summaryrefslogtreecommitdiffstats
path: root/src/rgw/rgw_torrent.h
blob: 0e314cce956efa950e91d7f99ee570ba6d119cd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab ft=cpp

#pragma once

#include "common/ceph_crypto.h"
#include "common/dout.h"
#include "common/async/yield_context.h"

#include "rgw_putobj.h"
#include "rgw_sal_fwd.h"

//control characters
void bencode_dict(bufferlist& bl);
void bencode_list(bufferlist& bl);
void bencode_end(bufferlist& bl);

//key len
void bencode_key(std::string_view key, bufferlist& bl);

//single values
void bencode(int value, bufferlist& bl);

//single values
void bencode(std::string_view str, bufferlist& bl);

//dictionary elements
void bencode(std::string_view key, int value, bufferlist& bl);

//dictionary elements
void bencode(std::string_view key, std::string_view value, bufferlist& bl);


// read the bencoded torrent file from the given object
int rgw_read_torrent_file(const DoutPrefixProvider* dpp,
                          rgw::sal::Object* object,
                          ceph::bufferlist &bl,
                          optional_yield y);

// PutObj filter that builds a torrent file during upload
class RGWPutObj_Torrent : public rgw::putobj::Pipe {
  size_t max_len = 0;
  size_t piece_len = 0;
  bufferlist piece_hashes;
  size_t len = 0;
  size_t piece_offset = 0;
  uint32_t piece_count = 0;
  ceph::crypto::SHA1 digest;

 public:
  RGWPutObj_Torrent(rgw::sal::DataProcessor* next,
                    size_t max_len, size_t piece_len);

  int process(bufferlist&& data, uint64_t logical_offset) override;

  // after processing is complete, return the bencoded torrent file
  bufferlist bencode_torrent(std::string_view filename) const;
};