Skip to content
Snippets Groups Projects
Commit f98658f1 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

proxy client: independently resubscribe push listeners

parent 8b6dcb1c
No related branches found
No related tags found
No related merge requests found
...@@ -697,6 +697,21 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi ...@@ -697,6 +697,21 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi
scheduler.edit(l->second.cacheExpirationJob, next); scheduler.edit(l->second.cacheExpirationJob, next);
return true; 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<std::mutex> 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<proxy::ListenToken>(0); auto pushNotifToken = std::make_shared<proxy::ListenToken>(0);
auto vcb = l->second.cb; auto vcb = l->second.cb;
l->second.pushNotifToken = pushNotifToken; l->second.pushNotifToken = pushNotifToken;
...@@ -983,6 +998,7 @@ DhtProxyClient::resubscribe(const InfoHash& key, Listener& listener) ...@@ -983,6 +998,7 @@ DhtProxyClient::resubscribe(const InfoHash& key, Listener& listener)
{ {
#if OPENDHT_PUSH_NOTIFICATIONS #if OPENDHT_PUSH_NOTIFICATIONS
if (deviceKey_.empty()) return; if (deviceKey_.empty()) return;
scheduler.syncTime();
DHT_LOG.d(key, "[search %s] resubscribe push listener", key.to_c_str()); DHT_LOG.d(key, "[search %s] resubscribe push listener", key.to_c_str());
// Subscribe // Subscribe
restbed::Uri uri(proxy::HTTP_PROTO + serverHost_ + "/" + key.toString()); restbed::Uri uri(proxy::HTTP_PROTO + serverHost_ + "/" + key.toString());
...@@ -997,6 +1013,7 @@ DhtProxyClient::resubscribe(const InfoHash& key, Listener& listener) ...@@ -997,6 +1013,7 @@ DhtProxyClient::resubscribe(const InfoHash& key, Listener& listener)
state->ok = true; state->ok = true;
listener.req = req; listener.req = req;
listener.pushNotifToken = pushNotifToken; listener.pushNotifToken = pushNotifToken;
scheduler.edit(listener.refreshJob, scheduler.time() + proxy::OP_TIMEOUT - proxy::OP_MARGIN);
listener.thread = std::thread([this, req, pushNotifToken, state]() { listener.thread = std::thread([this, req, pushNotifToken, state]() {
fillBodyToGetToken(req); fillBodyToGetToken(req);
auto settings = std::make_shared<restbed::Settings>(); auto settings = std::make_shared<restbed::Settings>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment