blob: c824a84dd61cf4a002b8c91fabc42607379c307f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#pragma once
#include "Socket.hpp"
#include "DirectConnection.hpp"
#include "IpAddress.hpp"
#include "PubsubKey.hpp"
#include <vector>
#include <mutex>
namespace sibs
{
class BootstrapException : public std::runtime_error
{
public:
BootstrapException(const std::string &errMsg) : std::runtime_error(errMsg) {}
};
class BootstrapNode
{
DISABLE_COPY(BootstrapNode)
public:
// Throws SocketCreateException or BootstrapException on error
BootstrapNode(const Ipv4 &address);
~BootstrapNode();
private:
void acceptConnections();
void messageFromClient(std::shared_ptr<DirectConnectionPeer> peer, MessageType messageType, const void *data, const usize size);
private:
DirectConnections connections;
std::unique_ptr<Socket> socket;
std::thread acceptConnectionsThread;
PubsubKeyMap<std::vector<std::shared_ptr<DirectConnectionPeer>>> subscribedPeers;
std::mutex subscribedPeersMutex;
};
}
|