#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; 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 peer, const void *data, const usize size); void receiveDataFromPeer(BoostrapConnectionListenCallbackFunc listenCallbackFunc, std::shared_ptr peer, const void *data, const usize size); private: DirectConnections connections; std::shared_ptr serverPeer; PubsubKeyMap listenCallbackFuncs; }; }