mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
integrating the existing state of TON Storage / TON Payments / CPS Fift development branches
This commit is contained in:
parent
040df63c98
commit
4e2624459b
153 changed files with 10760 additions and 1695 deletions
58
rldp2/InboundTransfer.cpp
Normal file
58
rldp2/InboundTransfer.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
#include "InboundTransfer.h"
|
||||
|
||||
#include "common/errorcode.h"
|
||||
|
||||
namespace ton {
|
||||
namespace rldp2 {
|
||||
size_t InboundTransfer::total_size() const {
|
||||
return data_.size();
|
||||
}
|
||||
|
||||
std::map<td::uint32, InboundTransfer::Part> &InboundTransfer::parts() {
|
||||
return parts_;
|
||||
}
|
||||
|
||||
bool InboundTransfer::is_part_completed(td::uint32 part_i) {
|
||||
return parts_.count(part_i) == 0 && part_i < next_part_;
|
||||
}
|
||||
|
||||
td::Result<InboundTransfer::Part *> InboundTransfer::get_part(td::uint32 part_i, const ton::fec::FecType &fec_type) {
|
||||
auto it = parts_.find(part_i);
|
||||
if (it != parts_.end()) {
|
||||
return &it->second;
|
||||
}
|
||||
//TODO: pass offset off and process even newer parts.
|
||||
//LOG_CHECK(next_part_ >= part_i) << next_part_ << " >= " << part_i;
|
||||
if (next_part_ == part_i && parts_.size() < 20) {
|
||||
auto offset = offset_;
|
||||
offset_ += fec_type.size();
|
||||
if (offset_ > total_size()) {
|
||||
return td::Status::Error(ErrorCode::protoviolation,
|
||||
PSTRING() << "too big part: offset=" << offset_ << " total_size=" << total_size()
|
||||
<< " total_size=" << fec_type.size() << " part=" << part_i);
|
||||
}
|
||||
|
||||
auto decoder = fec_type.create_decoder().move_as_ok();
|
||||
auto it = parts_.emplace(part_i, Part{std::move(decoder), RldpReceiver(RldpSender::Config()), offset});
|
||||
next_part_++;
|
||||
return &it.first->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void InboundTransfer::finish_part(td::uint32 part_i, td::Slice data) {
|
||||
auto it = parts_.find(part_i);
|
||||
CHECK(it != parts_.end());
|
||||
data_.as_slice().substr(it->second.offset).copy_from(data);
|
||||
parts_.erase(it);
|
||||
}
|
||||
|
||||
td::optional<td::Result<td::BufferSlice>> InboundTransfer::try_finish() {
|
||||
if (parts_.empty() && offset_ == data_.size()) {
|
||||
return std::move(data_);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace rldp2
|
||||
} // namespace ton
|
Loading…
Add table
Add a link
Reference in a new issue