diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-06-07 22:00:42 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 22:56:48 +0200 |
commit | c2187ca6b61c701c281cc528db43f6b97c50f3d8 (patch) | |
tree | f0baf317846902ae628c2e12cf8c25b6eb235c77 /include/sibs/BootstrapConnection.hpp | |
parent | ed71e8adf36e3d0c3f6f2b54794fe069091d3376 (diff) |
Add bootstrap node, listen method
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; + }; +} |