diff options
Diffstat (limited to 'include/sibs/BootstrapConnection.hpp')
-rw-r--r-- | include/sibs/BootstrapConnection.hpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/include/sibs/BootstrapConnection.hpp b/include/sibs/BootstrapConnection.hpp new file mode 100644 index 0000000..964d777 --- /dev/null +++ b/include/sibs/BootstrapConnection.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include "../utils.hpp" +#include "DirectConnection.hpp" +#include "PubsubKey.hpp" + +namespace sibs +{ + class PubsubKeyAlreadyListeningException : public std::runtime_error + { + public: + PubsubKeyAlreadyListeningException(const std::string &errMsg) : std::runtime_error(errMsg) {} + }; + + using BoostrapConnectionListenCallbackFunc = std::function<void(const void *data, const usize size)>; + + class BootstrapConnection + { + DISABLE_COPY(BootstrapConnection) + public: + BootstrapConnection(const Ipv4 &bootstrapAddress); + + // Throws PubsubKeyAlreadyListeningException if we are already listening on the key @pubsubKey + void listen(const PubsubKey &pubsubKey, BoostrapConnectionListenCallbackFunc callbackFunc); + private: + void receiveDataFromServer(std::shared_ptr<DirectConnectionPeer> peer, const void *data, const usize size); + void receiveDataFromPeer(BoostrapConnectionListenCallbackFunc listenCallbackFunc, std::shared_ptr<DirectConnectionPeer> peer, const void *data, const usize size); + private: + DirectConnections connections; + std::shared_ptr<DirectConnectionPeer> serverPeer; + PubsubKeyMap<BoostrapConnectionListenCallbackFunc> listenCallbackFuncs; + }; +} |