Ton

Форк
0
/
overlay-fec.cpp 
74 строки · 2.6 Кб
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
#include "overlay-fec.hpp"
20
#include "overlay.hpp"
21
#include "adnl/utils.hpp"
22

23
namespace ton {
24

25
namespace overlay {
26

27
void OverlayOutboundFecBroadcast::alarm() {
28
  for (td::uint32 i = 0; i < 4; i++) {
29
    auto X = encoder_->gen_symbol(seqno_++);
30
    CHECK(X.data.size() <= 1000);
31
    td::actor::send_closure(overlay_, &OverlayImpl::send_new_fec_broadcast_part, local_id_, data_hash_,
32
                            fec_type_.size(), flags_, std::move(X.data), X.id, fec_type_, date_);
33
  }
34

35
  alarm_timestamp() = td::Timestamp::in(0.010);
36

37
  if (seqno_ >= to_send_) {
38
    stop();
39
  }
40
}
41

42
void OverlayOutboundFecBroadcast::start_up() {
43
  encoder_->prepare_more_symbols();
44
  alarm();
45
}
46

47
OverlayOutboundFecBroadcast::OverlayOutboundFecBroadcast(td::BufferSlice data, td::uint32 flags,
48
                                                         td::actor::ActorId<OverlayImpl> overlay,
49
                                                         PublicKeyHash local_id)
50
    : flags_(flags) {
51
  CHECK(data.size() <= (1 << 27));
52
  local_id_ = local_id;
53
  overlay_ = std::move(overlay);
54
  date_ = static_cast<td::int32>(td::Clocks::system());
55
  to_send_ = (static_cast<td::uint32>(data.size()) / symbol_size_ + 1) * 2;
56

57
  data_hash_ = td::sha256_bits256(data);
58

59
  fec_type_ = td::fec::RaptorQEncoder::Parameters{data.size(), symbol_size_, 0};
60
  auto E = fec_type_.create_encoder(std::move(data));
61
  E.ensure();
62
  encoder_ = E.move_as_ok();
63
}
64

65
td::actor::ActorId<OverlayOutboundFecBroadcast> OverlayOutboundFecBroadcast::create(
66
    td::BufferSlice data, td::uint32 flags, td::actor::ActorId<OverlayImpl> overlay, PublicKeyHash local_id) {
67
  return td::actor::create_actor<OverlayOutboundFecBroadcast>(td::actor::ActorOptions().with_name("bcast"),
68
                                                              std::move(data), flags, overlay, local_id)
69
      .release();
70
}
71

72
}  // namespace overlay
73

74
}  // namespace ton
75

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

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

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

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