Skip to content

Commit

Permalink
proxy client: resubscribe on token change
Browse files Browse the repository at this point in the history
  • Loading branch information
aberaud committed Nov 6, 2024
1 parent acd0a23 commit baad0b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
8 changes: 1 addition & 7 deletions include/opendht/dht_proxy_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,7 @@ class OPENDHT_PUBLIC DhtProxyClient final : public DhtInterface {

void setHeaderFields(http::Request& request);

virtual void setPushNotificationToken(const std::string& token) override {
#ifdef OPENDHT_PUSH_NOTIFICATIONS
deviceKey_ = token;
#else
(void) token;
#endif
}
virtual void setPushNotificationToken(const std::string& token) override;

virtual void setPushNotificationTopic(const std::string& topic) override {
#ifdef OPENDHT_PUSH_NOTIFICATIONS
Expand Down
21 changes: 21 additions & 0 deletions src/dht_proxy_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,4 +1394,25 @@ DhtProxyClient::fillBody(bool resubscribe)
}
#endif // OPENDHT_PUSH_NOTIFICATIONS

void
DhtProxyClient::setPushNotificationToken([[maybe_unused]] const std::string& token) {
#ifdef OPENDHT_PUSH_NOTIFICATIONS
std::unique_lock<std::mutex> l(lockCurrentProxyInfos_);
if (deviceKey_ != token) {
deviceKey_ = token;
auto status = ;
if (statusIpv4_ == NodeStatus::Connected || statusIpv6_ == NodeStatus::Connected) {
if (logger_)
logger_->d("[proxy:client] [push] token changed, resubscribing");
for (auto& search : searches_) {
for (auto& listener : search.second.listeners) {
resubscribe(search.first, listener.first, listener.second);
}
}
}
}
#endif
}


} // namespace dht

0 comments on commit baad0b4

Please sign in to comment.