From 5e25552b62e044149f95c8f27b7bc4f24335ec40 Mon Sep 17 00:00:00 2001 From: Andrey Tvorozhkov Date: Thu, 15 Feb 2024 06:19:51 +0300 Subject: [PATCH] Add dht --- lite-server-daemon/adnl-lite-proxy.cpp | 31 +++++++++++++++++++++-- lite-server-daemon/lite-server-daemon.cpp | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lite-server-daemon/adnl-lite-proxy.cpp b/lite-server-daemon/adnl-lite-proxy.cpp index f8c30dda2..bcf1b92ed 100644 --- a/lite-server-daemon/adnl-lite-proxy.cpp +++ b/lite-server-daemon/adnl-lite-proxy.cpp @@ -59,6 +59,33 @@ class LiteProxy : public td::actor::Actor { ratelimitdb = std::make_shared( td::RocksDb::open(db_root_ + "/" + config_.overlay_prefix + "rate-limits/", true).move_as_ok()); + + std::vector> vec; + auto nodes = ton::create_tl_object(std::move(vec)); + auto conf = ton::create_tl_object(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(); } @@ -81,7 +108,6 @@ 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); @@ -89,7 +115,6 @@ class LiteProxy : public td::actor::Actor { auto t = std::time(nullptr); auto users = fetch_tl_object(td::Slice{utmp}, true).move_as_ok(); - LOG(INFO) << "Known users: " << users->values_.size(); for (td::Bits256 pubkey : users->values_) { std::string tmp; @@ -194,6 +219,8 @@ class LiteProxy : public td::actor::Actor { td::IPAddress address_; std::shared_ptr ratelimitdb; td::actor::ActorOwn lite_proxy_; + std::map> dht_nodes_; + ton::PublicKeyHash default_dht_node_ = ton::PublicKeyHash::zero(); }; } // namespace ton::liteserver diff --git a/lite-server-daemon/lite-server-daemon.cpp b/lite-server-daemon/lite-server-daemon.cpp index b84f45390..c2fb995d1 100644 --- a/lite-server-daemon/lite-server-daemon.cpp +++ b/lite-server-daemon/lite-server-daemon.cpp @@ -88,6 +88,7 @@ class LiteServerDaemon : public td::actor::Actor { ton::adnl::AdnlNodesList adnl_static_nodes_; std::map> dht_nodes_; + ton::PublicKeyHash default_dht_node_ = ton::PublicKeyHash::zero(); td::actor::ActorOwn full_node_client_; std::shared_ptr dht_config_; std::map keys_; @@ -101,7 +102,6 @@ class LiteServerDaemon : public td::actor::Actor { td::actor::ActorOwn rldp_; td::actor::ActorOwn rldp2_; td::actor::ActorOwn lslimiter_; - ton::PublicKeyHash default_dht_node_ = ton::PublicKeyHash::zero(); int to_load_keys = 0;