dhtrunner: move getNodeInfo implementation to securedht

This commit is contained in:
Adrien Béraud committed 2026-02-22 17:16:28 -05:00
1 parent 85cbee0f1a
commit 0fc7e451e6
2 files changed
+22 -25

No files matched your search

+17
View File
@@ -191,6 +191,23 @@ public:
std::vector<ValuesExport> exportValues() const override { return dht_->exportValues(); }
void importValues(const std::vector<ValuesExport>& v) override { dht_->importValues(v); }
NodeStats getNodesStats(sa_family_t af) const override { return dht_->getNodesStats(af); }
NodeInfo getNodeInfo()
{
NodeInfo info;
info.id = getId();
info.node_id = getNodeId();
info.ipv4 = getNodesStats(AF_INET);
info.ipv6 = getNodesStats(AF_INET6);
std::tie(info.storage_size, info.storage_values) = getStoreSize();
std::tie(info.local_storage_size, info.local_storage_values) = getLocalStoreSize();
if (auto sock = getSocket()) {
info.bound4 = sock->getBoundRef(AF_INET).getPort();
info.bound6 = sock->getBoundRef(AF_INET6).getPort();
}
return info;
}
std::vector<unsigned> getNodeMessageStats(bool in = false) override { return dht_->getNodeMessageStats(in); }
std::string getRoutingTablesLog(sa_family_t af) const override { return dht_->getRoutingTablesLog(af); }
std::string getSearchesLog(sa_family_t af) const override { return dht_->getSearchesLog(af); }
+5 -25
View File
@@ -571,20 +571,10 @@ DhtRunner::getNodesStats(sa_family_t af) const
NodeInfo
DhtRunner::getNodeInfo() const
{
std::lock_guard<std::mutex> lck(dht_mtx);
NodeInfo info {};
if (dht_) {
info.id = dht_->getId();
info.node_id = dht_->getNodeId();
info.ipv4 = dht_->getNodesStats(AF_INET);
info.ipv6 = dht_->getNodesStats(AF_INET6);
std::tie(info.storage_size, info.storage_values) = dht_->getStoreSize();
std::tie(info.local_storage_size, info.local_storage_values) = dht_->getLocalStoreSize();
if (auto sock = dht_->getSocket()) {
info.bound4 = sock->getBoundRef(AF_INET).getPort();
info.bound6 = sock->getBoundRef(AF_INET6).getPort();
}
}
std::lock_guard<std::mutex> lck(dht_mtx);
if (dht_)
info = dht_->getNodeInfo();
info.ongoing_ops = ongoing_ops;
return info;
}
@@ -596,18 +586,8 @@ DhtRunner::getNodeInfo(std::function<void(std::shared_ptr<NodeInfo>)> cb)
ongoing_ops++;
pending_ops_prio.emplace([cb = std::move(cb), this](SecureDht& dht) {
auto sinfo = std::make_shared<NodeInfo>();
auto& info = *sinfo;
info.id = dht.getId();
info.node_id = dht.getNodeId();
info.ipv4 = dht.getNodesStats(AF_INET);
info.ipv6 = dht.getNodesStats(AF_INET6);
std::tie(info.storage_size, info.storage_values) = dht.getStoreSize();
std::tie(info.local_storage_size, info.local_storage_values) = dht.getLocalStoreSize();
if (auto sock = dht.getSocket()) {
info.bound4 = sock->getBoundRef(AF_INET).getPort();
info.bound6 = sock->getBoundRef(AF_INET6).getPort();
}
info.ongoing_ops = ongoing_ops;
*sinfo = dht.getNodeInfo();
sinfo->ongoing_ops = ongoing_ops;
cb(std::move(sinfo));
opEnded();
});