1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Tonlib: change liteservers on query timeout or connection close

This commit is contained in:
SpyCheese 2022-10-04 15:12:13 +03:00
parent 69cee95abb
commit 33a079962f
16 changed files with 117 additions and 37 deletions

View file

@ -25,6 +25,7 @@
*/
#include "DNSResolver.h"
#include "td/utils/overloaded.h"
#include "common/delay.h"
static const double CACHE_TIMEOUT_HARD = 300.0;
static const double CACHE_TIMEOUT_SOFT = 270.0;
@ -33,8 +34,18 @@ DNSResolver::DNSResolver(td::actor::ActorId<TonlibClient> tonlib_client) : tonli
}
void DNSResolver::start_up() {
sync();
}
void DNSResolver::sync() {
auto obj = tonlib_api::make_object<tonlib_api::sync>();
auto P = td::PromiseCreator::lambda([](td::Result<tonlib_api::object_ptr<tonlib_api::Object>>) {});
auto P = td::PromiseCreator::lambda([SelfId =
actor_id(this)](td::Result<tonlib_api::object_ptr<tonlib_api::Object>> R) {
if (R.is_error()) {
LOG(WARNING) << "Sync error: " << R.move_as_error();
ton::delay_action([SelfId]() { td::actor::send_closure(SelfId, &DNSResolver::sync); }, td::Timestamp::in(5.0));
}
});
td::actor::send_closure(tonlib_client_, &TonlibClient::send_request, std::move(obj), std::move(P));
}

View file

@ -37,6 +37,7 @@ class DNSResolver : public td::actor::Actor {
void resolve(std::string host, td::Promise<ton::adnl::AdnlNodeIdShort> promise);
private:
void sync();
void save_to_cache(std::string host, ton::adnl::AdnlNodeIdShort id);
td::actor::ActorId<TonlibClient> tonlib_client_;