1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-02-15 04:32:21 +00:00
ton/rldp2/RttStats.cpp
EmelyanenkoK 360ef54e6b
TON Storage utilities (#564)
* Rename chunk to piece in MerkleTree for consistency

* Refactor PeerManager

* Make PeerState thread-safe

* Download torrent by hash

* First version of storage daemon

* Download torrents partially

* Improve storing and loading torrent state in DB

* Rewrite MerkleTree

* "Remove torrent" in storage daemon

* Process errors, fix bugs in storage

* Move TonlibClientWrapper from rldp-http-proxy to tonlib

* Initial version of storage provider

* Move interaction with contracts to smc-util

* Improve TonlibClientWrapper interface

* Various improvements in storage provider

* Fix TorrentCreator.cpp

* Improve interface for partial download

* Client mode in storage-daemon

* Improve interface of storage-daemon-cli

* Fix calculating speed, show peers in storage-daemon

* Use permanent adnl id in storage daemon

* Fix sending large "storage.addUpdate" messages

* Improve printing torrents in cli

* Update tlo

* Fix RldpSender::on_ack

* Update storage provider

* Add "address" parameter to get-provider-params

* Allow client to close storage contract

* Limit torrent description

* Add more logs to storage provider

* smc.forget tonlib method

* Use smc.forget in storage daemon

* Optimize sending messages in smc-util.cpp

* Fix verbosity, remove excessive logs

* Json output in storage-daemon-cli

* Update storage provider contracts

* Fix rldp2 acks

* Change verbosity of logs in rldp2

* Update help and output of commands and in storage-daemon-cli

Co-authored-by: SpyCheese <mikle98@yandex.ru>
2022-12-22 12:24:13 +03:00

71 lines
2.1 KiB
C++

/*
This file is part of TON Blockchain Library.
TON Blockchain Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
TON Blockchain Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2017-2020 Telegram Systems LLP
*/
#include "RttStats.h"
#include "rldp.hpp"
#include <cmath>
namespace ton {
namespace rldp2 {
void RttStats::on_rtt_sample(double rtt_sample, double ack_delay, td::Timestamp now) {
if (rtt_sample < 0.001 || rtt_sample > 10) {
VLOG(RLDP_WARNING) << "Suspicious rtt sample " << rtt_sample;
return;
}
if (ack_delay < -1e-9 || ack_delay > 10) {
VLOG(RLDP_WARNING) << "Suspicious ack_delay " << ack_delay;
return;
}
rtt_sample = td::max(0.01, rtt_sample);
last_rtt = rtt_sample;
windowed_min_rtt_stat.add_event(rtt_sample, now.at());
auto windowed_min_rtt_sample = windowed_min_rtt_stat.get_stat(now.at()).get_stat();
if (windowed_min_rtt_sample) {
windowed_min_rtt = windowed_min_rtt_sample.value();
}
if (smoothed_rtt < 0) {
// ignore ack_delay just because
min_rtt = last_rtt;
smoothed_rtt = last_rtt;
rtt_var = last_rtt / 2;
} else {
if (rtt_sample < min_rtt) {
min_rtt = rtt_sample;
}
double adjusted_rtt = rtt_sample;
if (adjusted_rtt - ack_delay > min_rtt) {
adjusted_rtt -= ack_delay;
}
smoothed_rtt += (adjusted_rtt - smoothed_rtt) / 8;
double var = fabs(smoothed_rtt - adjusted_rtt);
rtt_var += (var - rtt_var) / 4;
}
if (td::Timestamp::in(smoothed_rtt, rtt_round_at).is_in_past(now)) {
rtt_round_at = now;
rtt_round++;
}
}
} // namespace rldp2
} // namespace ton