Skip to content

Commit

Permalink
Allow init ton::liteserver::config with tl
Browse files Browse the repository at this point in the history
  • Loading branch information
tvorogme committed Feb 3, 2024
1 parent e38d053 commit 5f7db6a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
35 changes: 27 additions & 8 deletions lite-server-daemon/lite-server-config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ class Config {
return addr < with.addr;
}
};

td::IPAddress addr_;
std::map<ton::PublicKeyHash, AdnlCategory> adnl_ids;
std::map<td::int32, ton::PublicKeyHash> liteservers;
std::map<ton::PublicKeyHash, td::uint32> keys_refcnt;

void decref(ton::PublicKeyHash key) {
Expand All @@ -36,6 +32,29 @@ class Config {
};

public:
td::IPAddress addr_;
std::map<ton::PublicKeyHash, AdnlCategory> adnl_ids;
std::map<td::int32, ton::PublicKeyHash> liteservers;

Config() {
}

Config(ton::ton_api::engine_liteserver_config &config) {
auto tmp = addr_.init_host_port(td::IPAddress::ipv4_to_str(config.ip_), static_cast<td::uint16>(config.out_port_));
if (tmp.is_error()) {
LOG(ERROR) << tmp.move_as_error();
std::_Exit(2);
}

for (auto &serv : config.liteservers_) {
config_add_lite_server(ton::PublicKeyHash{serv->id_}, serv->port_).ensure();
}

for (auto &adnl : config.adnl_) {
config_add_adnl_addr(ton::PublicKeyHash{adnl->id_}, td::narrow_cast<td::uint8>(adnl->category_)).ensure();
}
}

td::Result<bool> config_add_lite_server(ton::PublicKeyHash key, td::int32 port) {
auto it = liteservers.find(port);
if (it != liteservers.end()) {
Expand All @@ -51,8 +70,8 @@ class Config {
}
};

td::Result<bool> set_addr(std::string addr) {
auto s = addr_.init_host_port(std::move(addr), 0);
td::Result<bool> set_addr(const std::string &addr) {
auto s = addr_.init_host_port(addr);
if (s.is_error()) {
LOG(ERROR) << s.move_as_error();
return false;
Expand Down Expand Up @@ -92,8 +111,8 @@ class Config {
for (auto &x : liteservers) {
liteserver_vec.push_back(ton::create_tl_object<ton::ton_api::engine_liteServer>(x.second.tl(), x.first));
}
return ton::create_tl_object<ton::ton_api::engine_liteserver_config>(addr_.get_ipv4(), std::move(adnl_vec),
std::move(liteserver_vec));
return ton::create_tl_object<ton::ton_api::engine_liteserver_config>(
addr_.get_ipv4(), addr_.get_port(), std::move(adnl_vec), std::move(liteserver_vec));
};
};
} // namespace liteserver
Expand Down
15 changes: 14 additions & 1 deletion lite-server-daemon/lite-server-daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class LiteServerDaemon : public td::actor::Actor {
std::string server_config_;
std::string tmp_ipaddr_;
std::string global_config_;
ton::liteserver::Config config_;

td::Ref<ton::validator::ValidatorManagerOptions> opts_;
td::actor::ActorOwn<ton::validator::ValidatorManagerInterface> validator_manager_;
Expand All @@ -147,7 +148,7 @@ class LiteServerDaemon : public td::actor::Actor {
std::_Exit(2);
}

auto ls_port = addr.get_port();
auto ls_port = addr.get_port() + 1;
config.set_addr(addr);

auto pk = ton::PrivateKey{ton::privkeys::Ed25519::random()};
Expand Down Expand Up @@ -187,6 +188,18 @@ class LiteServerDaemon : public td::actor::Actor {
LOG(ERROR) << "Json does not fit TL scheme";
std::_Exit(2);
}

config_ = ton::liteserver::Config{conf};

LOG(WARNING) << "ADNL available on: " << config_.addr_;

for (auto &[t, e] : config_.adnl_ids) {
LOG(WARNING) << "ADNL Key: " << t.tl().to_hex();
}

for (auto &[t, e] : config_.liteservers) {
LOG(WARNING) << "LiteServer port: " << t << " key: " << e.tl().to_hex();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tl/generate/scheme/ton_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ engine.validator.config out_port:int addrs:(vector engine.Addr) adnl:(vector eng
liteservers:(vector engine.liteServer) control:(vector engine.controlInterface)
gc:engine.gc = engine.validator.Config;

engine.liteserver.config ip:int adnl:(vector engine.adnl)
engine.liteserver.config ip:int out_port:int adnl:(vector engine.adnl)
liteservers:(vector engine.liteServer) = engine.liteserver.Config;

---functions---
Expand Down
Binary file modified tl/generate/scheme/ton_api.tlo
Binary file not shown.

0 comments on commit 5f7db6a

Please sign in to comment.