Skip to content

Commit 3f27cd7

Browse files
committed
proxy client: resubscribe on token change
1 parent b222efe commit 3f27cd7

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

include/opendht/dht_proxy_client.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,7 @@ class OPENDHT_PUBLIC DhtProxyClient final : public DhtInterface {
6767

6868
void setHeaderFields(http::Request& request);
6969

70-
virtual void setPushNotificationToken(const std::string& token) override {
71-
#ifdef OPENDHT_PUSH_NOTIFICATIONS
72-
deviceKey_ = token;
73-
#else
74-
(void) token;
75-
#endif
76-
}
70+
virtual void setPushNotificationToken(const std::string& token) override;
7771

7872
virtual void setPushNotificationTopic(const std::string& topic) override {
7973
#ifdef OPENDHT_PUSH_NOTIFICATIONS

src/dht_proxy_client.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -1394,4 +1394,24 @@ DhtProxyClient::fillBody(bool resubscribe)
13941394
}
13951395
#endif // OPENDHT_PUSH_NOTIFICATIONS
13961396

1397+
void
1398+
DhtProxyClient::setPushNotificationToken([[maybe_unused]] const std::string& token) {
1399+
#ifdef OPENDHT_PUSH_NOTIFICATIONS
1400+
std::unique_lock<std::mutex> l(lockCurrentProxyInfos_);
1401+
if (deviceKey_ != token) {
1402+
deviceKey_ = token;
1403+
if (statusIpv4_ == NodeStatus::Connected || statusIpv6_ == NodeStatus::Connected) {
1404+
if (logger_)
1405+
logger_->d("[proxy:client] [push] token changed, resubscribing");
1406+
for (auto& search : searches_) {
1407+
for (auto& listener : search.second.listeners) {
1408+
resubscribe(search.first, listener.first, listener.second);
1409+
}
1410+
}
1411+
}
1412+
}
1413+
#endif
1414+
}
1415+
1416+
13971417
} // namespace dht

0 commit comments

Comments
 (0)