diff options
Diffstat (limited to 'include/sibs/DirectConnection.hpp')
-rw-r--r-- | include/sibs/DirectConnection.hpp | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/include/sibs/DirectConnection.hpp b/include/sibs/DirectConnection.hpp index 8e92137..c4431a5 100644 --- a/include/sibs/DirectConnection.hpp +++ b/include/sibs/DirectConnection.hpp @@ -7,19 +7,12 @@ #include <memory> #include <thread> #include <mutex> +#include "IpAddress.hpp" #include "../types.hpp" #include "../utils.hpp" -struct addrinfo; - namespace sibs { - class InvalidAddressException : public std::runtime_error - { - public: - InvalidAddressException(const std::string &errMsg) : std::runtime_error(errMsg) {} - }; - class ConnectionException : public std::runtime_error { public: @@ -32,16 +25,6 @@ namespace sibs SendException(const std::string &errMsg) : std::runtime_error(errMsg) {} }; - class Ipv4 - { - DISABLE_COPY(Ipv4) - public: - // Throws InvalidAddressException on error - Ipv4(const char *ip, u16 port); - ~Ipv4(); - - struct addrinfo *address; - }; enum class PubSubConnectResult { @@ -61,6 +44,7 @@ namespace sibs class DirectConnections { DISABLE_COPY(DirectConnections) + friend class BootstrapNode; public: DirectConnections(u16 port = 27137); ~DirectConnections(); @@ -69,6 +53,8 @@ namespace sibs std::shared_ptr<DirectConnectionPeer> connect(const Ipv4 &address, PubSubReceiveDataCallback receiveDataCallbackFunc); // Throws SendException on error void send(const std::shared_ptr<DirectConnectionPeer> &peer, const void *data, const usize size); + protected: + int createSocket(const Ipv4 &addressToBind, bool rendezvous, bool reuseAddr); private: void receiveData(); bool receiveDataFromPeer(const int socket, char *output); |