Ton
1/*
2This file is part of TON Blockchain Library.
3
4TON Blockchain Library is free software: you can redistribute it and/or modify
5it under the terms of the GNU Lesser General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9TON Blockchain Library is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU Lesser General Public License for more details.
13
14You should have received a copy of the GNU Lesser General Public License
15along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
16
17Copyright 2017-2020 Telegram Systems LLP
18*/
19
20#include "OutboundTransfer.h"21
22namespace ton {23namespace rldp2 {24size_t OutboundTransfer::total_size() const {25return data_.size();26}
27std::map<td::uint32, OutboundTransfer::Part> &OutboundTransfer::parts(const RldpSender::Config &config) {28while (parts_.size() < 20) {29auto offset = next_part_ * part_size();30if (offset >= data_.size()) {31break;32}33td::BufferSlice D = data_.from_slice(data_.as_slice().substr(offset).truncate(part_size()));34ton::fec::FecType fec_type = td::fec::RaptorQEncoder::Parameters{D.size(), symbol_size(), 0};35auto encoder = fec_type.create_encoder(std::move(D)).move_as_ok();36auto symbols_count = fec_type.symbols_count();37parts_.emplace(next_part_, Part{std::move(encoder), RldpSender(config, symbols_count), std::move(fec_type)});38next_part_++;39}40return parts_;41}
42
43void OutboundTransfer::drop_part(td::uint32 part_i) {44parts_.erase(part_i);45}
46
47OutboundTransfer::Part *OutboundTransfer::get_part(td::uint32 part_i) {48auto it = parts_.find(part_i);49if (it == parts_.end()) {50return nullptr;51}52return &it->second;53}
54
55bool OutboundTransfer::is_done() const {56return next_part_ * part_size() >= data_.size() && parts_.empty();57}
58} // namespace rldp259} // namespace ton60