From 15da502354b339ff7d4a1b4791d25ba5167c0d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Sat, 13 Apr 2019 22:31:45 -0400 Subject: [PATCH] dhtrunner: make peer discovery port static constexpr --- include/opendht/dhtrunner.h | 2 -- src/dhtrunner.cpp | 25 +++++++++++-------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/include/opendht/dhtrunner.h b/include/opendht/dhtrunner.h index 5b942760..ecf01680 100644 --- a/include/opendht/dhtrunner.h +++ b/include/opendht/dhtrunner.h @@ -541,8 +541,6 @@ private: /** PeerDiscovery Parameters */ std::unique_ptr<PeerDiscovery> peerDiscovery4_; std::unique_ptr<PeerDiscovery> peerDiscovery6_; - const in_port_t port_multicast = 8888; - }; } diff --git a/src/dhtrunner.cpp b/src/dhtrunner.cpp index e0d106c0..e6a4af35 100644 --- a/src/dhtrunner.cpp +++ b/src/dhtrunner.cpp @@ -31,6 +31,7 @@ namespace dht { constexpr std::chrono::seconds DhtRunner::BOOTSTRAP_PERIOD; static constexpr size_t RX_QUEUE_MAX_SIZE = 1024 * 16; +static constexpr in_port_t PEER_DISCOVERY_PORT = 8888; struct DhtRunner::Listener { size_t tokenClassicDht {0}; @@ -45,6 +46,7 @@ DhtRunner::DhtRunner() : dht_() #ifdef OPENDHT_PROXY_CLIENT , dht_via_proxy_() #endif //OPENDHT_PROXY_CLIENT +, peerDiscovery4_(), peerDiscovery6_() { #ifdef _WIN32 WSADATA wsd; @@ -137,12 +139,12 @@ DhtRunner::run(const SockAddr& local4, const SockAddr& local6, const DhtRunner:: if (config.peer_discovery or config.peer_publish) { try { - peerDiscovery4_.reset(new PeerDiscovery(AF_INET, port_multicast)); + peerDiscovery4_.reset(new PeerDiscovery(AF_INET, PEER_DISCOVERY_PORT)); } catch(const std::exception& e){ std::cerr << "Can't start peer discovery (IPv4): " << e.what() << std::endl; } try { - peerDiscovery6_.reset(new PeerDiscovery(AF_INET6, port_multicast)); + peerDiscovery6_.reset(new PeerDiscovery(AF_INET6, PEER_DISCOVERY_PORT)); } catch(const std::exception& e) { std::cerr << "Can't start peer discovery (IPv6): " << e.what() << std::endl; } @@ -150,13 +152,11 @@ DhtRunner::run(const SockAddr& local4, const SockAddr& local6, const DhtRunner:: if (config.peer_discovery) { using sig = void (DhtRunner::*)(const InfoHash&, const SockAddr&); if (peerDiscovery4_) - peerDiscovery4_->startDiscovery(std::bind(static_cast<sig>(&DhtRunner::bootstrap), - this, + peerDiscovery4_->startDiscovery(std::bind(static_cast<sig>(&DhtRunner::bootstrap), this, std::placeholders::_1,std::placeholders::_2)); if (peerDiscovery6_) - peerDiscovery6_->startDiscovery(std::bind(static_cast<sig>(&DhtRunner::bootstrap), - this, + peerDiscovery6_->startDiscovery(std::bind(static_cast<sig>(&DhtRunner::bootstrap), this, std::placeholders::_1,std::placeholders::_2)); } if (config.peer_publish) { @@ -187,10 +187,8 @@ DhtRunner::join() running = false; cv.notify_all(); bootstrap_cv.notify_all(); - if (peerDiscovery4_) - peerDiscovery4_->stop(); - if (peerDiscovery6_) - peerDiscovery6_->stop(); + if (peerDiscovery4_) peerDiscovery4_->stop(); + if (peerDiscovery6_) peerDiscovery6_->stop(); if (dht_thread.joinable()) dht_thread.join(); @@ -198,10 +196,9 @@ DhtRunner::join() bootstrap_thread.join(); if (rcv_thread.joinable()) rcv_thread.join(); - if (peerDiscovery4_) - peerDiscovery4_->join(); - if (peerDiscovery6_) - peerDiscovery6_->join(); + + if (peerDiscovery4_) peerDiscovery4_->join(); + if (peerDiscovery6_) peerDiscovery6_->join(); { std::lock_guard<std::mutex> lck(storage_mtx); -- GitLab