20
#include "InboundTransfer.h"
22
#include "common/errorcode.h"
26
size_t InboundTransfer::total_size() const {
30
std::map<td::uint32, InboundTransfer::Part> &InboundTransfer::parts() {
34
bool InboundTransfer::is_part_completed(td::uint32 part_i) {
35
return parts_.count(part_i) == 0 && part_i < next_part_;
38
td::Result<InboundTransfer::Part *> InboundTransfer::get_part(td::uint32 part_i, const ton::fec::FecType &fec_type) {
39
auto it = parts_.find(part_i);
40
if (it != parts_.end()) {
45
if (next_part_ == part_i && parts_.size() < 20) {
46
auto offset = offset_;
47
offset_ += fec_type.size();
48
if (offset_ > total_size()) {
49
return td::Status::Error(ErrorCode::protoviolation,
50
PSTRING() << "too big part: offset=" << offset_ << " total_size=" << total_size()
51
<< " total_size=" << fec_type.size() << " part=" << part_i);
54
auto decoder = fec_type.create_decoder().move_as_ok();
55
auto it = parts_.emplace(part_i, Part{std::move(decoder), RldpReceiver(RldpSender::Config()), offset});
57
return &it.first->second;
62
void InboundTransfer::finish_part(td::uint32 part_i, td::Slice data) {
63
auto it = parts_.find(part_i);
64
CHECK(it != parts_.end());
65
data_.as_slice().substr(it->second.offset).copy_from(data);
69
td::optional<td::Result<td::BufferSlice>> InboundTransfer::try_finish() {
70
if (parts_.empty() && offset_ == data_.size()) {
71
return std::move(data_);