mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Move ExtClientLazy and QueryTraits to lite-client-common
This commit is contained in:
parent
21ce145af2
commit
d115807f6e
12 changed files with 57 additions and 60 deletions
|
@ -1,9 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
|
||||
|
||||
add_library(lite-client-common lite-client-common.cpp lite-client-common.h)
|
||||
add_library(lite-client-common lite-client-common.cpp lite-client-common.h ext-client.cpp ext-client.h QueryTraits.h)
|
||||
target_link_libraries(lite-client-common PUBLIC tdutils tdactor adnllite tl_api tl_lite_api tl-lite-utils ton_crypto ton_block)
|
||||
|
||||
add_executable(lite-client lite-client.cpp lite-client.h)
|
||||
add_executable(lite-client lite-client.cpp lite-client.h ext-client.h ext-client.cpp)
|
||||
target_link_libraries(lite-client tdutils tdactor adnllite tl_api tl_lite_api tl-lite-utils ton_crypto ton_block
|
||||
terminal lite-client-common git)
|
||||
|
||||
|
|
|
@ -17,12 +17,14 @@
|
|||
#pragma once
|
||||
#include "ton/ton-types.h"
|
||||
#include "auto/tl/lite_api.h"
|
||||
#include "auto/tl/lite_api.hpp"
|
||||
#include "vm/boc.h"
|
||||
#include "vm/cellslice.h"
|
||||
#include "block/block-auto.h"
|
||||
#include "block/block-parse.h"
|
||||
#include "auto/tl/lite_api.hpp"
|
||||
|
||||
namespace tonlib {
|
||||
namespace liteclient {
|
||||
|
||||
template <typename Query>
|
||||
struct QueryTraits {
|
||||
|
@ -212,5 +214,9 @@ struct QueryTraits<ton::lite_api::liteServer_getShardBlockProof> {
|
|||
}
|
||||
};
|
||||
|
||||
template<typename Query>
|
||||
inline ton::ShardIdFull get_query_shard(const Query& q) {
|
||||
return QueryTraits<Query>::get_shard(q);
|
||||
}
|
||||
|
||||
} // namespace tonlib
|
|
@ -13,20 +13,17 @@
|
|||
|
||||
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 "ExtClientLazy.h"
|
||||
#include "TonlibError.h"
|
||||
#include "ext-client.h"
|
||||
#include "td/utils/Random.h"
|
||||
#include "ton/ton-shard.h"
|
||||
#include <map>
|
||||
|
||||
namespace tonlib {
|
||||
namespace liteclient {
|
||||
|
||||
class ExtClientLazyImpl : public ExtClientLazy {
|
||||
class ExtClientImpl : public ExtClient {
|
||||
public:
|
||||
ExtClientLazyImpl(std::vector<Config::LiteServer> servers, td::unique_ptr<ExtClientLazy::Callback> callback)
|
||||
ExtClientImpl(std::vector<LiteServer> servers, td::unique_ptr<ExtClient::Callback> callback)
|
||||
: callback_(std::move(callback)) {
|
||||
CHECK(!servers.empty());
|
||||
servers_.resize(servers.size());
|
||||
|
@ -53,10 +50,10 @@ class ExtClientLazyImpl : public ExtClientLazy {
|
|||
CHECK(!server.client.empty());
|
||||
alarm_timestamp().relax(server.timeout = td::Timestamp::in(MAX_NO_QUERIES_TIMEOUT));
|
||||
td::Promise<td::BufferSlice> P = [SelfId = actor_id(this), server_idx,
|
||||
promise = std::move(promise)](td::Result<td::BufferSlice> R) mutable {
|
||||
promise = std::move(promise)](td::Result<td::BufferSlice> R) mutable {
|
||||
if (R.is_error() &&
|
||||
(R.error().code() == ton::ErrorCode::timeout || R.error().code() == ton::ErrorCode::cancelled)) {
|
||||
td::actor::send_closure(SelfId, &ExtClientLazyImpl::set_server_bad, server_idx);
|
||||
td::actor::send_closure(SelfId, &ExtClientImpl::set_server_bad, server_idx);
|
||||
}
|
||||
promise.set_result(std::move(R));
|
||||
};
|
||||
|
@ -128,17 +125,17 @@ class ExtClientLazyImpl : public ExtClientLazy {
|
|||
|
||||
class Callback : public ton::adnl::AdnlExtClient::Callback {
|
||||
public:
|
||||
explicit Callback(td::actor::ActorShared<ExtClientLazyImpl> parent, size_t idx)
|
||||
explicit Callback(td::actor::ActorShared<ExtClientImpl> parent, size_t idx)
|
||||
: parent_(std::move(parent)), idx_(idx) {
|
||||
}
|
||||
void on_ready() override {
|
||||
}
|
||||
void on_stop_ready() override {
|
||||
td::actor::send_closure(parent_, &ExtClientLazyImpl::set_server_bad, idx_);
|
||||
td::actor::send_closure(parent_, &ExtClientImpl::set_server_bad, idx_);
|
||||
}
|
||||
|
||||
private:
|
||||
td::actor::ActorShared<ExtClientLazyImpl> parent_;
|
||||
td::actor::ActorShared<ExtClientImpl> parent_;
|
||||
size_t idx_;
|
||||
};
|
||||
ref_cnt_++;
|
||||
|
@ -154,7 +151,7 @@ class ExtClientLazyImpl : public ExtClientLazy {
|
|||
}
|
||||
|
||||
struct Server {
|
||||
Config::LiteServer s;
|
||||
LiteServer s;
|
||||
td::actor::ActorOwn<ton::adnl::AdnlExtClient> client;
|
||||
td::Timestamp timeout = td::Timestamp::never();
|
||||
td::Timestamp ignore_until = td::Timestamp::never();
|
||||
|
@ -169,7 +166,7 @@ class ExtClientLazyImpl : public ExtClientLazy {
|
|||
std::map<ton::ShardIdFull, size_t> shard_to_server_;
|
||||
int max_server_shard_depth_ = 0;
|
||||
|
||||
td::unique_ptr<ExtClientLazy::Callback> callback_;
|
||||
td::unique_ptr<ExtClient::Callback> callback_;
|
||||
static constexpr double MAX_NO_QUERIES_TIMEOUT = 100;
|
||||
|
||||
bool is_closing_{false};
|
||||
|
@ -206,13 +203,13 @@ class ExtClientLazyImpl : public ExtClientLazy {
|
|||
}
|
||||
};
|
||||
|
||||
td::actor::ActorOwn<ExtClientLazy> ExtClientLazy::create(ton::adnl::AdnlNodeIdFull dst, td::IPAddress dst_addr,
|
||||
td::actor::ActorOwn<ExtClient> ExtClient::create(ton::adnl::AdnlNodeIdFull dst, td::IPAddress dst_addr,
|
||||
td::unique_ptr<Callback> callback) {
|
||||
return create({Config::LiteServer{dst, dst_addr, true, {}}}, std::move(callback));
|
||||
return create({LiteServer{dst, dst_addr, true, {}}}, std::move(callback));
|
||||
}
|
||||
|
||||
td::actor::ActorOwn<ExtClientLazy> ExtClientLazy::create(std::vector<Config::LiteServer> servers,
|
||||
td::actor::ActorOwn<ExtClient> ExtClient::create(std::vector<LiteServer> servers,
|
||||
td::unique_ptr<Callback> callback) {
|
||||
return td::actor::create_actor<ExtClientLazyImpl>("ExtClientLazy", std::move(servers), std::move(callback));
|
||||
return td::actor::create_actor<ExtClientImpl>("ExtClient", std::move(servers), std::move(callback));
|
||||
}
|
||||
} // namespace tonlib
|
||||
} // namespace liteclient
|
|
@ -13,18 +13,22 @@
|
|||
|
||||
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
|
||||
*/
|
||||
#pragma once
|
||||
#include "td/actor/actor.h"
|
||||
#include "ton/ton-types.h"
|
||||
#include "adnl/adnl-ext-client.h"
|
||||
#include "Config.h"
|
||||
|
||||
namespace tonlib {
|
||||
class ExtClientLazy : public td::actor::Actor {
|
||||
namespace liteclient {
|
||||
class ExtClient : public td::actor::Actor {
|
||||
public:
|
||||
struct LiteServer {
|
||||
ton::adnl::AdnlNodeIdFull adnl_id;
|
||||
td::IPAddress address;
|
||||
bool is_full = true;
|
||||
std::vector<ton::ShardIdFull> shards;
|
||||
};
|
||||
|
||||
class Callback {
|
||||
public:
|
||||
virtual ~Callback() {
|
||||
|
@ -35,10 +39,8 @@ class ExtClientLazy : public td::actor::Actor {
|
|||
td::Promise<td::BufferSlice> promise) = 0;
|
||||
virtual void force_change_liteserver() = 0;
|
||||
|
||||
static td::actor::ActorOwn<ExtClientLazy> create(ton::adnl::AdnlNodeIdFull dst, td::IPAddress dst_addr,
|
||||
td::unique_ptr<Callback> callback);
|
||||
static td::actor::ActorOwn<ExtClientLazy> create(std::vector<Config::LiteServer> servers,
|
||||
td::unique_ptr<Callback> callback);
|
||||
static td::actor::ActorOwn<ExtClient> create(ton::adnl::AdnlNodeIdFull dst, td::IPAddress dst_addr,
|
||||
td::unique_ptr<Callback> callback);
|
||||
static td::actor::ActorOwn<ExtClient> create(std::vector<LiteServer> servers, td::unique_ptr<Callback> callback);
|
||||
};
|
||||
|
||||
} // namespace tonlib
|
||||
} // namespace liteclient
|
|
@ -10,7 +10,6 @@ set(TONLIB_SOURCE
|
|||
tonlib/Client.cpp
|
||||
tonlib/Config.cpp
|
||||
tonlib/ExtClient.cpp
|
||||
tonlib/ExtClientLazy.cpp
|
||||
tonlib/ExtClientOutbound.cpp
|
||||
tonlib/KeyStorage.cpp
|
||||
tonlib/KeyValue.cpp
|
||||
|
@ -25,7 +24,6 @@ set(TONLIB_SOURCE
|
|||
tonlib/Client.h
|
||||
tonlib/Config.h
|
||||
tonlib/ExtClient.h
|
||||
tonlib/ExtClientLazy.h
|
||||
tonlib/ExtClientOutbound.h
|
||||
tonlib/KeyStorage.h
|
||||
tonlib/KeyValue.h
|
||||
|
|
|
@ -20,15 +20,11 @@
|
|||
#include "adnl/adnl-node-id.hpp"
|
||||
#include "td/utils/port/IPAddress.h"
|
||||
#include "ton/ton-types.h"
|
||||
#include "lite-client/ext-client.h"
|
||||
|
||||
namespace tonlib {
|
||||
struct Config {
|
||||
struct LiteServer {
|
||||
ton::adnl::AdnlNodeIdFull adnl_id;
|
||||
td::IPAddress address;
|
||||
bool is_full = true;
|
||||
std::vector<ton::ShardIdFull> shards;
|
||||
};
|
||||
using LiteServer = liteclient::ExtClient::LiteServer;
|
||||
ton::BlockIdExt zero_state_id;
|
||||
ton::BlockIdExt init_block_id;
|
||||
std::vector<ton::BlockIdExt> hardforks;
|
||||
|
|
|
@ -65,7 +65,7 @@ void ExtClient::send_raw_query(td::BufferSlice query, ton::ShardIdFull shard, td
|
|||
if (client_.adnl_ext_client_.empty()) {
|
||||
return P.set_error(TonlibError::NoLiteServers());
|
||||
}
|
||||
td::actor::send_closure(client_.adnl_ext_client_, &ExtClientLazy::send_query, "query", std::move(query),
|
||||
td::actor::send_closure(client_.adnl_ext_client_, &liteclient::ExtClient::send_query, "query", std::move(query),
|
||||
shard, td::Timestamp::in(10.0), std::move(P));
|
||||
}
|
||||
} // namespace tonlib
|
||||
|
|
|
@ -28,10 +28,10 @@
|
|||
#include "td/utils/Container.h"
|
||||
#include "td/utils/Random.h"
|
||||
|
||||
#include "ExtClientLazy.h"
|
||||
#include "lite-client/ext-client.h"
|
||||
#include "TonlibError.h"
|
||||
#include "utils.h"
|
||||
#include "QueryTraits.h"
|
||||
#include "lite-client/QueryTraits.h"
|
||||
|
||||
namespace tonlib {
|
||||
class LastBlock;
|
||||
|
@ -39,7 +39,7 @@ class LastConfig;
|
|||
struct LastBlockState;
|
||||
struct LastConfigState;
|
||||
struct ExtClientRef {
|
||||
td::actor::ActorId<ExtClientLazy> adnl_ext_client_;
|
||||
td::actor::ActorId<liteclient::ExtClient> adnl_ext_client_;
|
||||
td::actor::ActorId<LastBlock> last_block_actor_;
|
||||
td::actor::ActorId<LastConfig> last_config_actor_;
|
||||
};
|
||||
|
@ -65,7 +65,7 @@ class ExtClient {
|
|||
|
||||
template <class QueryT>
|
||||
void send_query(QueryT query, td::Promise<typename QueryT::ReturnType> promise, td::int32 seq_no = -1) {
|
||||
ton::ShardIdFull shard = QueryTraits<QueryT>::get_shard(query);
|
||||
ton::ShardIdFull shard = liteclient::QueryTraits<QueryT>::get_shard(query);
|
||||
auto raw_query = ton::serialize_tl_object(&query, true);
|
||||
td::uint32 tag = td::Random::fast_uint32();
|
||||
VLOG(lite_server) << "send query to liteserver: " << tag << " " << to_string(query);
|
||||
|
@ -99,7 +99,7 @@ class ExtClient {
|
|||
|
||||
void force_change_liteserver() {
|
||||
if (!client_.adnl_ext_client_.empty()) {
|
||||
td::actor::send_closure(client_.adnl_ext_client_, &ExtClientLazy::force_change_liteserver);
|
||||
td::actor::send_closure(client_.adnl_ext_client_, &liteclient::ExtClient::force_change_liteserver);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,11 +18,10 @@
|
|||
*/
|
||||
#pragma once
|
||||
#include "td/actor/actor.h"
|
||||
|
||||
#include "ExtClientLazy.h"
|
||||
#include "lite-client/ext-client.h"
|
||||
|
||||
namespace tonlib {
|
||||
class ExtClientOutbound : public ExtClientLazy {
|
||||
class ExtClientOutbound : public liteclient::ExtClient {
|
||||
public:
|
||||
class Callback {
|
||||
public:
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
#include "TonlibClient.h"
|
||||
|
||||
#include "tonlib/ExtClientLazy.h"
|
||||
#include "tonlib/ExtClientOutbound.h"
|
||||
#include "tonlib/LastBlock.h"
|
||||
#include "tonlib/LastConfig.h"
|
||||
|
@ -2022,7 +2021,7 @@ void TonlibClient::init_ext_client() {
|
|||
ext_client_outbound_ = client.get();
|
||||
raw_client_ = std::move(client);
|
||||
} else {
|
||||
class Callback : public ExtClientLazy::Callback {
|
||||
class Callback : public liteclient::ExtClient::Callback {
|
||||
public:
|
||||
explicit Callback(td::actor::ActorShared<> parent) : parent_(std::move(parent)) {
|
||||
}
|
||||
|
@ -2032,7 +2031,7 @@ void TonlibClient::init_ext_client() {
|
|||
};
|
||||
ext_client_outbound_ = {};
|
||||
ref_cnt_++;
|
||||
raw_client_ = ExtClientLazy::create(config_.lite_servers, td::make_unique<Callback>(td::actor::actor_shared()));
|
||||
raw_client_ = liteclient::ExtClient::create(config_.lite_servers, td::make_unique<Callback>(td::actor::actor_shared()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "td/utils/optional.h"
|
||||
|
||||
#include "smc-envelope/ManualDns.h"
|
||||
#include "lite-client/ext-client.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
|
@ -112,7 +113,7 @@ class TonlibClient : public td::actor::Actor {
|
|||
vm::Dictionary libraries{256};
|
||||
|
||||
// network
|
||||
td::actor::ActorOwn<ExtClientLazy> raw_client_;
|
||||
td::actor::ActorOwn<liteclient::ExtClient> raw_client_;
|
||||
td::actor::ActorId<ExtClientOutbound> ext_client_outbound_;
|
||||
td::actor::ActorOwn<LastBlock> raw_last_block_;
|
||||
td::actor::ActorOwn<LastConfig> raw_last_config_;
|
||||
|
|
|
@ -47,8 +47,6 @@
|
|||
#include "tonlib/TonlibClient.h"
|
||||
#include "tonlib/TonlibCallback.h"
|
||||
|
||||
#include "tonlib/ExtClientLazy.h"
|
||||
|
||||
#include "smc-envelope/ManualDns.h"
|
||||
#include "smc-envelope/PaymentChannel.h"
|
||||
|
||||
|
@ -57,6 +55,7 @@
|
|||
#include "crypto/util/Miner.h"
|
||||
#include "vm/boc.h"
|
||||
#include "vm/cells/CellBuilder.h"
|
||||
#include "lite-client/ext-client.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <iostream>
|
||||
|
@ -174,7 +173,7 @@ class TonlibCli : public td::actor::Actor {
|
|||
|
||||
std::map<std::uint64_t, td::Promise<tonlib_api::object_ptr<tonlib_api::Object>>> query_handlers_;
|
||||
|
||||
td::actor::ActorOwn<tonlib::ExtClientLazy> raw_client_;
|
||||
td::actor::ActorOwn<liteclient::ExtClient> raw_client_;
|
||||
|
||||
bool is_closing_{false};
|
||||
td::uint32 ref_cnt_{1};
|
||||
|
@ -223,7 +222,7 @@ class TonlibCli : public td::actor::Actor {
|
|||
|
||||
if (options_.use_callbacks_for_network) {
|
||||
auto config = tonlib::Config::parse(options_.config).move_as_ok();
|
||||
class Callback : public tonlib::ExtClientLazy::Callback {
|
||||
class Callback : public liteclient::ExtClient::Callback {
|
||||
public:
|
||||
explicit Callback(td::actor::ActorShared<> parent) : parent_(std::move(parent)) {
|
||||
}
|
||||
|
@ -232,7 +231,7 @@ class TonlibCli : public td::actor::Actor {
|
|||
td::actor::ActorShared<> parent_;
|
||||
};
|
||||
ref_cnt_++;
|
||||
raw_client_ = tonlib::ExtClientLazy::create(config.lite_servers,
|
||||
raw_client_ = liteclient::ExtClient::create(config.lite_servers,
|
||||
td::make_unique<Callback>(td::actor::actor_shared()));
|
||||
}
|
||||
|
||||
|
@ -1533,7 +1532,7 @@ class TonlibCli : public td::actor::Actor {
|
|||
auto update = tonlib_api::move_object_as<tonlib_api::updateSendLiteServerQuery>(std::move(result));
|
||||
CHECK(!raw_client_.empty());
|
||||
snd_bytes_ += update->data_.size();
|
||||
send_closure(raw_client_, &tonlib::ExtClientLazy::send_query, "query", td::BufferSlice(update->data_),
|
||||
send_closure(raw_client_, &liteclient::ExtClient::send_query, "query", td::BufferSlice(update->data_),
|
||||
ton::ShardIdFull(update->workchain_, update->shard_), td::Timestamp::in(5),
|
||||
[actor_id = actor_id(this), id = update->id_](td::Result<td::BufferSlice> res) {
|
||||
send_closure(actor_id, &TonlibCli::on_adnl_result, id, std::move(res));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue