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 "RldpReceiver.h"21
22namespace ton {23namespace rldp2 {24td::Variant<RldpReceiver::ActionSendAck, RldpReceiver::ActionWait> RldpReceiver::next_action(td::Timestamp now) {25if (send_ack_at_ && (send_ack_at_.is_in_past(now))) {26return ActionSendAck{ack};27}28return ActionWait{send_ack_at_};29}
30
31void RldpReceiver::on_ack_sent(td::Timestamp now) {32if (cnt_ != 0) {33//LOG(ERROR) << "RESEND ACK " << cnt_;34}35cnt_++;36send_ack_at_ = {};37if (cnt_ <= 7) {38send_ack_at_.relax(td::Timestamp::at(now.at() + config_.ack_delay * (1 << cnt_)));39}40}
41
42bool RldpReceiver::on_received(td::uint32 seqno, td::Timestamp now) {43if (!ack.on_got_packet(seqno)) {44return false;45}46cnt_ = 0;47send_ack_at_.relax(td::Timestamp::at(now.at() + config_.ack_delay));48return true;49}
50
51} // namespace rldp252} // namespace ton53