mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
tools: show connectivity change in log
This commit is contained in:
1 parent
2dd4cde035
commit
01f2ad9ea4
3 files changed
+13
-7
No files matched your search
@@ -44,6 +44,13 @@ enum class NodeStatus {
|
||||
Connected // 1+ good nodes
|
||||
};
|
||||
|
||||
inline constexpr const char*
|
||||
statusToStr(NodeStatus status) {
|
||||
return status == NodeStatus::Connected ? "connected" : (
|
||||
status == NodeStatus::Connecting ? "connecting" :
|
||||
"disconnected");
|
||||
}
|
||||
|
||||
struct OPENDHT_PUBLIC NodeStats {
|
||||
unsigned good_nodes {0},
|
||||
dubious_nodes {0},
|
||||
|
||||
+1
-7
@@ -57,19 +57,13 @@ main(int argc, char **argv)
|
||||
|
||||
DhtRunner dht;
|
||||
try {
|
||||
params.generate_identity = true;
|
||||
auto dhtConf = getDhtConfig(params);
|
||||
dht.run(params.port, dhtConf.first, std::move(dhtConf.second));
|
||||
|
||||
if (not params.bootstrap.first.empty())
|
||||
dht.bootstrap(params.bootstrap.first.c_str(), params.bootstrap.second.c_str());
|
||||
|
||||
#ifdef OPENDHT_PROXY_CLIENT
|
||||
if (!params.proxyclient.empty()) {
|
||||
dht.setProxyServer(params.proxyclient);
|
||||
dht.enableProxy(true);
|
||||
}
|
||||
#endif //OPENDHT_PROXY_CLIENT
|
||||
|
||||
print_node_info(dht, params);
|
||||
std::cout << " type 'c {hash}' to join a channel" << std::endl << std::endl;
|
||||
|
||||
|
||||
@@ -171,6 +171,11 @@ getDhtConfig(dht_params& params)
|
||||
else
|
||||
context.logger = dht::log::getStdLogger();
|
||||
}
|
||||
if (context.logger) {
|
||||
context.statusChangedCallback = [logger = *context.logger](dht::NodeStatus status4, dht::NodeStatus status6) {
|
||||
logger.WARN("Connectivity changed: IPv4: %s, IPv6: %s", dht::statusToStr(status4), dht::statusToStr(status6));
|
||||
};
|
||||
}
|
||||
return {std::move(config), std::move(context)};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user