From 5e15c0bdc0a19f37f54a0f8d2b99145a4350d8c7 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 14 Oct 2018 06:05:09 +0200 Subject: Removed user from subscriptions on disconnect --- include/sibs/BootstrapNode.hpp | 2 ++ include/sibs/DirectConnection.hpp | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'include') diff --git a/include/sibs/BootstrapNode.hpp b/include/sibs/BootstrapNode.hpp index 48e527c..ab3d6b3 100644 --- a/include/sibs/BootstrapNode.hpp +++ b/include/sibs/BootstrapNode.hpp @@ -4,6 +4,7 @@ #include "IpAddress.hpp" #include "PubsubKey.hpp" #include +#include namespace sibs { @@ -28,5 +29,6 @@ namespace sibs int socket; std::thread acceptConnectionsThread; PubsubKeyMap>> subscribedPeers; + std::mutex subscribedPeersMutex; }; } diff --git a/include/sibs/DirectConnection.hpp b/include/sibs/DirectConnection.hpp index 4b5c67f..8e3865f 100644 --- a/include/sibs/DirectConnection.hpp +++ b/include/sibs/DirectConnection.hpp @@ -31,6 +31,7 @@ namespace sibs using PubSubConnectCallback = std::function peer, PubSubResult result, const std::string &resultStr)>; using PubSubReceiveDataCallback = std::function peer, const void *data, const usize size)>; using PubSubSendDataCallback = std::function; + using PubSubOnRemoveDisconnectedPeerCallback = std::function peer)>; struct DirectConnectionPeer { @@ -53,6 +54,8 @@ namespace sibs void connect(const Ipv4 &address, PubSubConnectCallback connectCallbackFunc, PubSubReceiveDataCallback receiveDataCallbackFunc); void send(const std::shared_ptr peer, std::shared_ptr> data, PubSubSendDataCallback sendDataCallbackFunc = nullptr); + + void onRemoveDisconnectedPeer(PubSubOnRemoveDisconnectedPeerCallback callbackFunc); protected: int createSocket(const Ipv4 &addressToBind, bool rendezvous, bool reuseAddr, bool bind = true); private: @@ -68,5 +71,6 @@ namespace sibs std::thread receiveDataThread; std::mutex peersMutex; bool alive; + PubSubOnRemoveDisconnectedPeerCallback removeDisconnectedPeerCallback; }; } -- cgit v1.2.3