Skip to content

Commit

Permalink
Add dht
Browse files Browse the repository at this point in the history
  • Loading branch information
tvorogme committed Feb 15, 2024
1 parent 3f8ec73 commit 5e25552
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 29 additions & 2 deletions lite-server-daemon/adnl-lite-proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,33 @@ class LiteProxy : public td::actor::Actor {

ratelimitdb = std::make_shared<td::RocksDb>(
td::RocksDb::open(db_root_ + "/" + config_.overlay_prefix + "rate-limits/", true).move_as_ok());

std::vector<ton::tl_object_ptr<ton::ton_api::dht_node>> vec;
auto nodes = ton::create_tl_object<ton::ton_api::dht_nodes>(std::move(vec));
auto conf = ton::create_tl_object<ton::ton_api::dht_config_global>(std::move(nodes), 6, 3);
auto dht_configR = ton::dht::Dht::create_global_config(std::move(conf));
dht_configR.ensure();
auto dht_config = dht_configR.move_as_ok();

// Start DHT
for (auto &dht : config_.dht_ids) {
auto D =
ton::dht::Dht::create(ton::adnl::AdnlNodeIdShort{dht}, db_root_, dht_config, keyring_.get(), adnl_.get());
D.ensure();

dht_nodes_[dht] = D.move_as_ok();
if (default_dht_node_.is_zero()) {
default_dht_node_ = dht;
}
}

if (default_dht_node_.is_zero()) {
LOG(ERROR) << "Config broken, no DHT";
std::_Exit(2);
}

td::actor::send_closure(adnl_, &ton::adnl::Adnl::register_dht_node, dht_nodes_[default_dht_node_].get());

start_server();
}

Expand All @@ -81,15 +108,13 @@ class LiteProxy : public td::actor::Actor {
}

void init_users() {
LOG(INFO) << "Init users";
if (ratelimitdb->count("users").move_as_ok() > 0) {
std::string utmp;
ratelimitdb->get("users", utmp);

auto t = std::time(nullptr);

auto users = fetch_tl_object<ton::ton_api::storage_liteserver_users>(td::Slice{utmp}, true).move_as_ok();
LOG(INFO) << "Known users: " << users->values_.size();

for (td::Bits256 pubkey : users->values_) {
std::string tmp;
Expand Down Expand Up @@ -194,6 +219,8 @@ class LiteProxy : public td::actor::Actor {
td::IPAddress address_;
std::shared_ptr<td::RocksDb> ratelimitdb;
td::actor::ActorOwn<adnl::AdnlExtServer> lite_proxy_;
std::map<ton::PublicKeyHash, td::actor::ActorOwn<ton::dht::Dht>> dht_nodes_;
ton::PublicKeyHash default_dht_node_ = ton::PublicKeyHash::zero();
};
} // namespace ton::liteserver

Expand Down
2 changes: 1 addition & 1 deletion lite-server-daemon/lite-server-daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class LiteServerDaemon : public td::actor::Actor {

ton::adnl::AdnlNodesList adnl_static_nodes_;
std::map<ton::PublicKeyHash, td::actor::ActorOwn<ton::dht::Dht>> dht_nodes_;
ton::PublicKeyHash default_dht_node_ = ton::PublicKeyHash::zero();
td::actor::ActorOwn<adnl::AdnlExtClient> full_node_client_;
std::shared_ptr<ton::dht::DhtGlobalConfig> dht_config_;
std::map<ton::PublicKeyHash, ton::PublicKey> keys_;
Expand All @@ -101,7 +102,6 @@ class LiteServerDaemon : public td::actor::Actor {
td::actor::ActorOwn<ton::rldp::Rldp> rldp_;
td::actor::ActorOwn<ton::rldp2::Rldp> rldp2_;
td::actor::ActorOwn<ton::liteserver::LiteServerLimiter> lslimiter_;
ton::PublicKeyHash default_dht_node_ = ton::PublicKeyHash::zero();

int to_load_keys = 0;

Expand Down

0 comments on commit 5e25552

Please sign in to comment.