Ton

Форк
0
/
OutboundTransfer.cpp 
59 строк · 2.0 Кб
1
/*
2
    This file is part of TON Blockchain Library.
3

4
    TON Blockchain Library is free software: you can redistribute it and/or modify
5
    it under the terms of the GNU Lesser General Public License as published by
6
    the Free Software Foundation, either version 2 of the License, or
7
    (at your option) any later version.
8

9
    TON Blockchain Library is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU Lesser General Public License for more details.
13

14
    You should have received a copy of the GNU Lesser General Public License
15
    along with TON Blockchain Library.  If not, see <http://www.gnu.org/licenses/>.
16

17
    Copyright 2017-2020 Telegram Systems LLP
18
*/
19

20
#include "OutboundTransfer.h"
21

22
namespace ton {
23
namespace rldp2 {
24
size_t OutboundTransfer::total_size() const {
25
  return data_.size();
26
}
27
std::map<td::uint32, OutboundTransfer::Part> &OutboundTransfer::parts(const RldpSender::Config &config) {
28
  while (parts_.size() < 20) {
29
    auto offset = next_part_ * part_size();
30
    if (offset >= data_.size()) {
31
      break;
32
    }
33
    td::BufferSlice D = data_.from_slice(data_.as_slice().substr(offset).truncate(part_size()));
34
    ton::fec::FecType fec_type = td::fec::RaptorQEncoder::Parameters{D.size(), symbol_size(), 0};
35
    auto encoder = fec_type.create_encoder(std::move(D)).move_as_ok();
36
    auto symbols_count = fec_type.symbols_count();
37
    parts_.emplace(next_part_, Part{std::move(encoder), RldpSender(config, symbols_count), std::move(fec_type)});
38
    next_part_++;
39
  }
40
  return parts_;
41
}
42

43
void OutboundTransfer::drop_part(td::uint32 part_i) {
44
  parts_.erase(part_i);
45
}
46

47
OutboundTransfer::Part *OutboundTransfer::get_part(td::uint32 part_i) {
48
  auto it = parts_.find(part_i);
49
  if (it == parts_.end()) {
50
    return nullptr;
51
  }
52
  return &it->second;
53
}
54

55
bool OutboundTransfer::is_done() const {
56
  return next_part_ * part_size() >= data_.size() && parts_.empty();
57
}
58
}  // namespace rldp2
59
}  // namespace ton
60

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.