mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Allow untrusted fecs after check (#356)
* Allow untrusted fecs after check * FEC: save and resend incoming parts Co-authored-by: OmicronTau <87443739+OmicronTau@users.noreply.github.com> Co-authored-by: OmicronTau <omicron@ton.org>
This commit is contained in:
parent
0fbfc91965
commit
1e0b587023
4 changed files with 83 additions and 41 deletions
|
@ -82,13 +82,17 @@ class BroadcastFec : public td::ListNode {
|
|||
}
|
||||
}
|
||||
|
||||
td::Status add_part(td::uint32 seqno, td::BufferSlice data) {
|
||||
td::Status add_part(td::uint32 seqno, td::BufferSlice data,
|
||||
td::BufferSlice serialized_fec_part_short,
|
||||
td::BufferSlice serialized_fec_part) {
|
||||
CHECK(decoder_);
|
||||
td::fec::Symbol s;
|
||||
s.id = seqno;
|
||||
s.data = std::move(data);
|
||||
|
||||
decoder_->add_symbol(std::move(s));
|
||||
parts_[seqno] = std::pair<td::BufferSlice, td::BufferSlice>(std::move(serialized_fec_part_short),
|
||||
std::move(serialized_fec_part));
|
||||
|
||||
return td::Status::OK();
|
||||
}
|
||||
|
@ -106,6 +110,7 @@ class BroadcastFec : public td::ListNode {
|
|||
CHECK(encoder_ != nullptr);
|
||||
ready_ = true;
|
||||
decoder_ = nullptr;
|
||||
data_ = D.data.clone();
|
||||
return std::move(D.data);
|
||||
}
|
||||
|
||||
|
@ -185,9 +190,13 @@ class BroadcastFec : public td::ListNode {
|
|||
}
|
||||
}
|
||||
|
||||
void broadcast_checked(td::Result<td::Unit> R) {
|
||||
void broadcast_checked(td::Result<td::Unit> R);
|
||||
void set_overlay(OverlayImpl *overlay) {
|
||||
overlay_ = overlay;
|
||||
}
|
||||
|
||||
td::Status distribute_part(td::uint32 seqno);
|
||||
|
||||
private:
|
||||
bool ready_ = false;
|
||||
|
||||
|
@ -208,6 +217,10 @@ class BroadcastFec : public td::ListNode {
|
|||
|
||||
td::uint32 next_seqno_ = 0;
|
||||
td::uint64 received_parts_ = 0;
|
||||
|
||||
std::map<td::uint32, std::pair<td::BufferSlice, td::BufferSlice>> parts_;
|
||||
OverlayImpl *overlay_;
|
||||
td::BufferSlice data_;
|
||||
};
|
||||
|
||||
class OverlayFecBroadcastPart : public td::ListNode {
|
||||
|
@ -228,6 +241,7 @@ class OverlayFecBroadcastPart : public td::ListNode {
|
|||
td::BufferSlice signature_;
|
||||
|
||||
bool is_short_;
|
||||
bool untrusted_{false};
|
||||
|
||||
BroadcastFec *bcast_;
|
||||
OverlayImpl *overlay_;
|
||||
|
@ -280,7 +294,7 @@ class OverlayFecBroadcastPart : public td::ListNode {
|
|||
signature_ = std::move(signature);
|
||||
}
|
||||
void update_overlay(OverlayImpl *overlay);
|
||||
|
||||
|
||||
tl_object_ptr<ton_api::overlay_broadcastFec> export_tl();
|
||||
tl_object_ptr<ton_api::overlay_broadcastFecShort> export_tl_short();
|
||||
td::BufferSlice export_serialized();
|
||||
|
@ -290,7 +304,9 @@ class OverlayFecBroadcastPart : public td::ListNode {
|
|||
td::Status run() {
|
||||
TRY_STATUS(run_checks());
|
||||
TRY_STATUS(apply());
|
||||
TRY_STATUS(distribute());
|
||||
if(!untrusted_) {
|
||||
TRY_STATUS(distribute());
|
||||
}
|
||||
return td::Status::OK();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue