diff --git a/include/opendht/dht_proxy_client.h b/include/opendht/dht_proxy_client.h index b4b45090bf74abd2cfb05b222bb7380920b09fb8..12fb4c8a14ddeedcd367aa578bdfac2557fb9c1d 100644 --- a/include/opendht/dht_proxy_client.h +++ b/include/opendht/dht_proxy_client.h @@ -337,6 +337,7 @@ private: NodeStats stats6_ {}; SockAddr publicAddressV4_; SockAddr publicAddressV6_; + std::atomic_bool launchConnectedCbs_ {false}; InfoHash myid {}; diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index f713d4b39138a49f8a6e8aa2b3c693d478a88de0..626fdcdde64331b070e561a183841eb786fbe83b 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -720,7 +720,8 @@ DhtProxyClient::onProxyInfos(const Json::Value& proxyInfos, const sa_family_t fa } auto newStatus = std::max(statusIpv4_, statusIpv6_); if (newStatus == NodeStatus::Connected) { - if (oldStatus == NodeStatus::Disconnected || oldStatus == NodeStatus::Connecting) { + if (oldStatus == NodeStatus::Disconnected || oldStatus == NodeStatus::Connecting || launchConnectedCbs_) { + launchConnectedCbs_ = false; listenerRestartTimer_->expires_at(std::chrono::steady_clock::now()); listenerRestartTimer_->async_wait(std::bind(&DhtProxyClient::restartListeners, this, std::placeholders::_1)); if (not onConnectCallbacks_.empty()) { @@ -1160,6 +1161,9 @@ DhtProxyClient::pushNotificationReceived(const std::map<std::string, std::string { // If a push notification is received, the proxy is up and running std::lock_guard<std::mutex> l(lockCurrentProxyInfos_); + auto oldStatus = std::max(statusIpv4_, statusIpv6_); + if (oldStatus != NodeStatus::Connected) + launchConnectedCbs_ = true; statusIpv4_ = NodeStatus::Connected; statusIpv6_ = NodeStatus::Connected; }