From f13b28fed46ca583feb1156e6aacbac1d8d032ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Tue, 28 Jul 2015 16:26:35 -0400 Subject: [PATCH] dht: add connectivityChanged() --- include/opendht/dht.h | 7 +++++++ include/opendht/dhtrunner.h | 7 +++++++ src/dht.cpp | 11 +++++++++++ src/dhtrunner.cpp | 10 ++++++++++ 4 files changed, 35 insertions(+) diff --git a/include/opendht/dht.h b/include/opendht/dht.h index ecb85d87..bc68bc65 100644 --- a/include/opendht/dht.h +++ b/include/opendht/dht.h @@ -300,6 +300,13 @@ public: bool cancelListen(const InfoHash&, size_t token); + /** + * Inform the DHT of lower-layer connectivity changes. + * This will cause the DHT to assume an IP address change. + * The DHT will recontact neighbor nodes, re-register for listen ops etc. + */ + void connectivityChanged(); + /** * Get the list of good nodes for local storage saving purposes * The list is ordered to minimize the back-to-work delay. diff --git a/include/opendht/dhtrunner.h b/include/opendht/dhtrunner.h index 6d632f9c..97f146bd 100644 --- a/include/opendht/dhtrunner.h +++ b/include/opendht/dhtrunner.h @@ -191,6 +191,13 @@ public: void bootstrap(const std::vector>& nodes); void bootstrap(const std::vector& nodes); + /** + * Inform the DHT of lower-layer connectivity changes. + * This will cause the DHT to assume an IP address change. + * The DHT will recontact neighbor nodes, re-register for listen ops etc. + */ + void connectivityChanged(); + void dumpTables() const { std::lock_guard lck(dht_mtx); diff --git a/src/dht.cpp b/src/dht.cpp index f6ea0fef..01515d0c 100644 --- a/src/dht.cpp +++ b/src/dht.cpp @@ -1705,6 +1705,17 @@ Dht::expireStorage() } } +void +Dht::connectivityChanged() +{ + confirm_nodes_time = now; + mybucket_grow_time = now; + mybucket6_grow_time = now; + for (auto& s : searches) + for (auto& sn : s.nodes) + sn.listenStatus = {}; +} + void Dht::rotateSecrets() { diff --git a/src/dhtrunner.cpp b/src/dhtrunner.cpp index fdc7bf65..10368caf 100644 --- a/src/dhtrunner.cpp +++ b/src/dhtrunner.cpp @@ -445,6 +445,16 @@ DhtRunner::bootstrap(const std::vector& nodes) cv.notify_all(); } +void +DhtRunner::connectivityChanged() +{ + std::lock_guard lck(storage_mtx); + pending_ops.emplace([=](SecureDht& dht) { + dht.connectivityChanged(); + }); + cv.notify_all(); +} + void DhtRunner::findCertificate(InfoHash hash, std::function)> cb) { std::lock_guard lck(storage_mtx);