From f98658f10f5b492056397fc612c4bb4ce1bd7e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Mon, 16 Apr 2018 16:06:43 -0400 Subject: [PATCH 1/2] proxy client: independently resubscribe push listeners --- src/dht_proxy_client.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index 5d4de69d..41d086b1 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -697,6 +697,21 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi scheduler.edit(l->second.cacheExpirationJob, next); return true; }; + + if (not deviceKey_.empty()) + l->second.refreshJob = scheduler.add(scheduler.time() + proxy::OP_TIMEOUT - proxy::OP_MARGIN, [this, key, token, state] { + if (state->cancel) + return; + std::lock_guard lock(searchLock_); + auto s = searches_.find(key); + if (s != searches_.end()) { + auto l = s->second.listeners.find(token); + if (l != s->second.listeners.end()) { + resubscribe(key, l->second); + } + } + }); + auto pushNotifToken = std::make_shared(0); auto vcb = l->second.cb; l->second.pushNotifToken = pushNotifToken; @@ -983,6 +998,7 @@ DhtProxyClient::resubscribe(const InfoHash& key, Listener& listener) { #if OPENDHT_PUSH_NOTIFICATIONS if (deviceKey_.empty()) return; + scheduler.syncTime(); DHT_LOG.d(key, "[search %s] resubscribe push listener", key.to_c_str()); // Subscribe restbed::Uri uri(proxy::HTTP_PROTO + serverHost_ + "/" + key.toString()); @@ -997,6 +1013,7 @@ DhtProxyClient::resubscribe(const InfoHash& key, Listener& listener) state->ok = true; listener.req = req; listener.pushNotifToken = pushNotifToken; + scheduler.edit(listener.refreshJob, scheduler.time() + proxy::OP_TIMEOUT - proxy::OP_MARGIN); listener.thread = std::thread([this, req, pushNotifToken, state]() { fillBodyToGetToken(req); auto settings = std::make_shared(); From 95f1d59a7f38cf9f9d1a5bc5e7896b64832c65c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= Date: Mon, 30 Apr 2018 10:42:39 -0400 Subject: [PATCH 2/2] proxy: add comment for refresh job --- src/dht_proxy_client.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index 41d086b1..338c07bd 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -699,6 +699,7 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi }; if (not deviceKey_.empty()) + // Relaunch push listeners even if a timeout is not received (if the proxy crash for any reason) l->second.refreshJob = scheduler.add(scheduler.time() + proxy::OP_TIMEOUT - proxy::OP_MARGIN, [this, key, token, state] { if (state->cancel) return;