From 1debe012c1cfbe5ddd14117ab7f51da2dccc9cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Sun, 8 Apr 2018 13:07:27 -0400 Subject: [PATCH] proxy client: restart listeners on connectivity change --- include/opendht/dht_proxy_client.h | 10 ++++++++-- src/dht_proxy_client.cpp | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/opendht/dht_proxy_client.h b/include/opendht/dht_proxy_client.h index 0b260331..3b350f39 100644 --- a/include/opendht/dht_proxy_client.h +++ b/include/opendht/dht_proxy_client.h @@ -249,8 +249,14 @@ public: void dumpTables() const {} std::vector getNodeMessageStats(bool) { return {}; } void setStorageLimit(size_t) {} - void connectivityChanged(sa_family_t) {} - void connectivityChanged() { } + void connectivityChanged(sa_family_t) { + restartListeners(); + } + void connectivityChanged() { + getProxyInfos(); + restartListeners(); + loopSignal_(); + } private: /** diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index 9682ac9d..05d1ac36 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -603,6 +603,7 @@ DhtProxyClient::cancelListen(const InfoHash& key, size_t gtoken) { size_t DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter filter/*, Where where*/) { + scheduler.syncTime(); restbed::Uri uri(HTTP_PROTO + serverHost_ + "/" + key.toString()); auto req = std::make_shared(uri); req->set_method(deviceKey_.empty() ? "LISTEN" : "SUBSCRIBE"); @@ -669,7 +670,7 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi auto pushNotifToken = std::make_shared(0); auto vcb = l->second.cb; l->second.pushNotifToken = pushNotifToken; - l->second.thread = std::thread([=]() + l->second.thread = std::thread([this,req,filter,vcb,pushNotifToken,state,isCanceledViaClose]() { auto settings = std::make_shared(); if (deviceKey_.empty()) { @@ -683,7 +684,7 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi restbed::Http::async(req, [this, filter, vcb, pushNotifToken, state](const std::shared_ptr& req, - const std::shared_ptr& reply) { + const std::shared_ptr& reply) { auto code = reply->get_status_code(); if (code == 200) { try {