return Compressor::create(s->cct, alg);
}
+auto RGWPutObj::get_torrent_filter(rgw::sal::DataProcessor* cb)
+ -> std::optional<RGWPutObj_Torrent>
+{
+ auto& conf = get_cct()->_conf;
+ if (!conf->rgw_torrent_flag) {
+ return std::nullopt; // torrent generation disabled
+ }
+ const auto max_len = conf->rgw_torrent_max_size;
+ const auto piece_len = conf->rgw_torrent_sha_unit;
+ if (!max_len || !piece_len) {
+ return std::nullopt; // invalid configuration
+ }
+ if (crypt_http_responses.count("x-amz-server-side-encryption-customer-algorithm")) {
+ return std::nullopt; // downloading the torrent would require customer keys
+ }
+ return RGWPutObj_Torrent{cb, max_len, piece_len};
+}
+
int RGWPutObj::get_lua_filter(std::unique_ptr<rgw::sal::DataProcessor>* filter, rgw::sal::DataProcessor* cb) {
std::string script;
const auto rc = rgw::lua::read_script(s, s->penv.lua.manager.get(), s->bucket_tenant, s->yield, rgw::lua::context::putData, script);
const auto& compression_type = driver->get_compression_type(*pdest_placement);
CompressorRef plugin;
- boost::optional<RGWPutObj_Compress> compressor;
+ std::optional<RGWPutObj_Compress> compressor;
+ std::optional<RGWPutObj_Torrent> torrent;
std::unique_ptr<rgw::sal::DataProcessor> encrypt;
std::unique_ptr<rgw::sal::DataProcessor> run_lua;
s->object->set_compressed();
}
}
+ if (torrent = get_torrent_filter(filter); torrent) {
+ filter = &*torrent;
+ }
// run lua script before data is compressed and encrypted - last filter runs first
op_ret = get_lua_filter(&run_lua, filter);
if (op_ret < 0) {
hash.Update((const unsigned char *)data.c_str(), data.length());
}
- /* update torrrent */
- torrent.update(data);
-
op_ret = filter->process(std::move(data), ofs);
if (op_ret < 0) {
ldpp_dout(this, 20) << "processor->process() returned ret="
<< ", orig_size=" << cs_info.orig_size
<< ", blocks=" << cs_info.blocks.size() << dendl;
}
+ if (torrent) {
+ auto bl = torrent->bencode_torrent(s->object->get_name());
+ if (bl.length()) {
+ ldpp_dout(this, 20) << "storing " << bl.length()
+ << " bytes of torrent info in " << RGW_ATTR_TORRENT << dendl;
+ attrs[RGW_ATTR_TORRENT] = std::move(bl);
+ }
+ }
buf_to_hex(m, CEPH_CRYPTO_MD5_DIGESTSIZE, calc_md5);
s->yield);
tracepoint(rgw_op, processor_complete_exit, s->req_id.c_str());
- /* produce torrent */
- if (s->cct->_conf->rgw_torrent_flag && (ofs == torrent.get_data_len()))
- {
- torrent.init(s, driver);
- torrent.set_create_date(mtime);
- op_ret = torrent.complete(y);
- if (0 != op_ret)
- {
- ldpp_dout(this, 0) << "ERROR: torrent.handle_data() returned " << op_ret << dendl;
- return;
- }
- }
-
// send request to notification manager
int ret = res->publish_commit(this, s->obj_size, mtime, etag, s->object->get_instance());
if (ret < 0) {