From 980312b2a6e96c6d301d30d38922f8a2cc315c92 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 19 Oct 2018 23:01:52 +0200 Subject: Retry put for 30 sec to wait for peer connections --- include/sibs/BootstrapConnection.hpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'include/sibs') diff --git a/include/sibs/BootstrapConnection.hpp b/include/sibs/BootstrapConnection.hpp index 9e2dfff..8156bd7 100644 --- a/include/sibs/BootstrapConnection.hpp +++ b/include/sibs/BootstrapConnection.hpp @@ -4,6 +4,7 @@ #include "DirectConnection.hpp" #include "PubsubKey.hpp" #include +#include namespace sibs { @@ -23,6 +24,13 @@ namespace sibs // Return false if you want to stop listening on the key using BoostrapConnectionListenCallbackFunc = std::function; + struct SubscribeData + { + BoostrapConnectionListenCallbackFunc listenCallbackFunc = nullptr; + std::vector> peers; + i64 listenStartTimeMs = 0; + }; + struct ListenHandle { PubsubKey key; @@ -34,6 +42,7 @@ namespace sibs public: // Throws BootstrapConnectionException on error BootstrapConnection(const Ipv4 &bootstrapAddress); + ~BootstrapConnection(); // If we are already listening on the key @pubsubKey then the callback function is overwritten ListenHandle listen(const PubsubKey &pubsubKey, BoostrapConnectionListenCallbackFunc callbackFunc); @@ -46,14 +55,15 @@ namespace sibs std::vector> getPeers(); private: + ListenHandle listen(const PubsubKey &pubsubKey, BoostrapConnectionListenCallbackFunc callbackFunc, bool registerCallbackFunc); void receiveDataFromServer(std::shared_ptr peer, MessageType messageType, const void *data, const usize size); void receiveDataFromPeer(std::shared_ptr peer, MessageType messageType, const void *data, const usize size); private: DirectConnections connections; std::shared_ptr serverPeer; - PubsubKeyMap listenCallbackFuncs; - PubsubKeyMap>> subscribedPeers; - std::recursive_mutex listenerCallbackFuncMutex; - std::recursive_mutex subscribedPeersMutex; + PubsubKeyMap subscribeData; + std::recursive_mutex subscribeDataMutex; + bool alive; + std::atomic_int putThreadCount; }; } -- cgit v1.2.3