aboutsummaryrefslogtreecommitdiff
path: root/include/sibs
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-14 06:05:09 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 22:56:48 +0200
commit5e15c0bdc0a19f37f54a0f8d2b99145a4350d8c7 (patch)
treecf2d3dafdaabfa392de4162845ab9ea4d6eb3842 /include/sibs
parent3e2c7e59672b282f8e089679ae7f05cfc03e405b (diff)
Removed user from subscriptions on disconnect
Diffstat (limited to 'include/sibs')
-rw-r--r--include/sibs/BootstrapNode.hpp2
-rw-r--r--include/sibs/DirectConnection.hpp4
2 files changed, 6 insertions, 0 deletions
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 <vector>
+#include <mutex>
namespace sibs
{
@@ -28,5 +29,6 @@ namespace sibs
int socket;
std::thread acceptConnectionsThread;
PubsubKeyMap<std::vector<std::shared_ptr<DirectConnectionPeer>>> 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<void(std::shared_ptr<DirectConnectionPeer> peer, PubSubResult result, const std::string &resultStr)>;
using PubSubReceiveDataCallback = std::function<void(std::shared_ptr<DirectConnectionPeer> peer, const void *data, const usize size)>;
using PubSubSendDataCallback = std::function<void(PubSubResult result, const std::string &resultStr)>;
+ using PubSubOnRemoveDisconnectedPeerCallback = std::function<void(std::shared_ptr<DirectConnectionPeer> peer)>;
struct DirectConnectionPeer
{
@@ -53,6 +54,8 @@ namespace sibs
void connect(const Ipv4 &address, PubSubConnectCallback connectCallbackFunc, PubSubReceiveDataCallback receiveDataCallbackFunc);
void send(const std::shared_ptr<DirectConnectionPeer> peer, std::shared_ptr<std::vector<u8>> 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;
};
}