mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Improve DHT store/load, pinging overlay peers (#840)
* Improve DHT store/load, pinging overlay peers * Fix speed limits in storage * Use keyStoreTypeDirectory in rldp-http-proxy and storage-daemon Mainly for caching synced block in tonlib. --------- Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
parent
c8918f0c02
commit
550c28d7db
16 changed files with 162 additions and 89 deletions
|
@ -25,6 +25,7 @@
|
|||
#include "td/utils/overloaded.h"
|
||||
#include "td/utils/Random.h"
|
||||
#include "vm/boc.h"
|
||||
#include "common/delay.h"
|
||||
|
||||
namespace ton {
|
||||
|
||||
|
@ -119,9 +120,9 @@ void PeerActor::on_get_piece_result(PartId piece_id, td::Result<td::BufferSlice>
|
|||
return std::move(res);
|
||||
}();
|
||||
if (res.is_error()) {
|
||||
LOG(DEBUG) << "getPiece " << piece_id << "query: " << res.error();
|
||||
LOG(DEBUG) << "getPiece " << piece_id << " query: " << res.error();
|
||||
} else {
|
||||
LOG(DEBUG) << "getPiece " << piece_id << "query: OK";
|
||||
LOG(DEBUG) << "getPiece " << piece_id << " query: OK";
|
||||
}
|
||||
state_->node_queries_results_.add_element(std::make_pair(piece_id, std::move(res)));
|
||||
notify_node();
|
||||
|
@ -343,11 +344,20 @@ void PeerActor::loop_node_get_piece() {
|
|||
}
|
||||
auto piece_size =
|
||||
std::min<td::uint64>(torrent_info_->piece_size, torrent_info_->file_size - part * torrent_info_->piece_size);
|
||||
td::actor::send_closure(state_->speed_limiters_.download, &SpeedLimiter::enqueue, (double)piece_size,
|
||||
td::Timestamp::in(3.0), [part, SelfId = actor_id(this)](td::Result<td::Unit> R) {
|
||||
td::actor::send_closure(SelfId, &PeerActor::node_get_piece_query_ready, part,
|
||||
std::move(R));
|
||||
});
|
||||
td::Timestamp timeout = td::Timestamp::in(3.0);
|
||||
td::actor::send_closure(
|
||||
state_->speed_limiters_.download, &SpeedLimiter::enqueue, (double)piece_size, timeout,
|
||||
[=, SelfId = actor_id(this)](td::Result<td::Unit> R) {
|
||||
if (R.is_ok()) {
|
||||
td::actor::send_closure(SelfId, &PeerActor::node_get_piece_query_ready, part, std::move(R));
|
||||
} else {
|
||||
delay_action(
|
||||
[=, R = std::move(R)]() mutable {
|
||||
td::actor::send_closure(SelfId, &PeerActor::node_get_piece_query_ready, part, std::move(R));
|
||||
},
|
||||
timeout);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -143,9 +143,11 @@ class PeerManager : public td::actor::Actor {
|
|||
td::actor::ActorId<PeerManager> peer_manager_;
|
||||
ton::adnl::AdnlNodeIdShort dst_;
|
||||
};
|
||||
ton::overlay::OverlayOptions opts;
|
||||
opts.announce_self_ = !client_mode_;
|
||||
opts.frequent_dht_lookup_ = true;
|
||||
send_closure(overlays_, &ton::overlay::Overlays::create_public_overlay_ex, src_id, overlay_id_.clone(),
|
||||
std::make_unique<Callback>(actor_id(this), src_id), rules, R"({ "type": "storage" })",
|
||||
!client_mode_);
|
||||
std::make_unique<Callback>(actor_id(this), src_id), rules, R"({ "type": "storage" })", opts);
|
||||
}
|
||||
promise.set_value({});
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
|
||||
#include "SpeedLimiter.h"
|
||||
#include "common/errorcode.h"
|
||||
|
||||
namespace ton {
|
||||
|
||||
|
@ -41,11 +42,11 @@ void SpeedLimiter::enqueue(double size, td::Timestamp timeout, td::Promise<td::U
|
|||
return;
|
||||
}
|
||||
if (max_speed_ == 0.0) {
|
||||
promise.set_error(td::Status::Error("Speed limit is 0"));
|
||||
promise.set_error(td::Status::Error(ErrorCode::timeout, "Speed limit is 0"));
|
||||
return;
|
||||
}
|
||||
if (timeout < unlock_at_) {
|
||||
promise.set_error(td::Status::Error("Timeout caused by speed limit"));
|
||||
promise.set_error(td::Status::Error(ErrorCode::timeout, "Timeout caused by speed limit"));
|
||||
return;
|
||||
}
|
||||
if (queue_.empty() && unlock_at_.is_in_past()) {
|
||||
|
|
|
@ -927,9 +927,11 @@ class StorageDaemon : public td::actor::Actor {
|
|||
}
|
||||
auto r_conf_data = td::read_file(global_config_);
|
||||
r_conf_data.ensure();
|
||||
std::string key_store = db_root_ + "/tonlib/";
|
||||
td::mkpath(key_store).ensure();
|
||||
auto tonlib_options = tonlib_api::make_object<tonlib_api::options>(
|
||||
tonlib_api::make_object<tonlib_api::config>(r_conf_data.move_as_ok().as_slice().str(), "", false, false),
|
||||
tonlib_api::make_object<tonlib_api::keyStoreTypeInMemory>());
|
||||
tonlib_api::make_object<tonlib_api::keyStoreTypeDirectory>(key_store));
|
||||
tonlib_client_ = td::actor::create_actor<tonlib::TonlibClientWrapper>("tonlibclient", std::move(tonlib_options));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue