From 0c1b3db7c4d9a4bcde4160c437613b32cd4081d6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 14 Oct 2018 06:10:47 +0200 Subject: Remove subscribed peer from client on disconnect --- src/BootstrapConnection.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/BootstrapConnection.cpp b/src/BootstrapConnection.cpp index 421dfe1..e5f5178 100644 --- a/src/BootstrapConnection.cpp +++ b/src/BootstrapConnection.cpp @@ -6,6 +6,21 @@ namespace sibs { BootstrapConnection::BootstrapConnection(const Ipv4 &bootstrapAddress) { + connections.onRemoveDisconnectedPeer([this](std::shared_ptr peer) + { + std::lock_guard lock(subscribedPeersMutex); + for(auto &topicUsers : subscribedPeers) + { + for(auto it = topicUsers.second.begin(); it != topicUsers.second.end(); ) + { + if(peer->address == (*it)->address) + it = topicUsers.second.erase(it); + else + ++it; + } + } + }); + PubSubResult connectResult = PubSubResult::OK; std::string connectResultStr; bool connected = false; -- cgit v1.2.3