4 #include "protodefinitions/Hermes.pb.h"
19 Hive(hiveNodeCallback& _onNodeFound, hiveNodeCallback& _onLocalNodeFound, hiveNodeCallback& _onNodeRemoved);
24 Hive& operator=(
const Hive&) =
delete;
26 void Configure(std::string _name,
bool _useLoopback =
true,
int _beaconPort = (
int)Hermes::Protocol::DefaultPorts::HivePort,
int _broadcastIntervalInSeconds = 1,
int _deadNodeTimeoutInSeconds = 10);
29 static std::unique_ptr<Hive>
FindCoordinator(std::string _name,
int _beaconPort, hiveNodeCallback& _onNodeFound, hiveNodeCallback& _onLocalNodeFound, hiveNodeCallback& _onNodeRemoved,
bool _useLoopback);
30 static std::unique_ptr<Hive>
FindLocalCoordinator(std::string _name,
int _beaconPort, hiveNodeCallback& _onNodeFound, hiveNodeCallback& _onLocalNodeFound, hiveNodeCallback& _onNodeRemoved);
31 static std::unique_ptr<Hive>
FindNetworkCoordinator(std::string _name,
int _beaconPort, hiveNodeCallback& _onNodeFound, hiveNodeCallback& _onLocalNodeFound, hiveNodeCallback& _onNodeRemoved);
34 static std::unique_ptr<Hermes::Protocol::HiveNode> tryParseHiveNodeFromBytes(
unsigned char*_data,
int _size);
38 struct HiveNodeTimeStamped {
40 std::chrono::system_clock::time_point lastseen;
42 std::vector<HiveNodeTimeStamped> m_nodes;
43 std::mutex m_nodes_mutex;
46 void subscriberThreadFunction();
47 void nodeCleanupThreadFunction();
48 std::unique_ptr<std::thread> m_subscriberThread;
49 std::unique_ptr<std::thread> m_nodeCleanupThread;
52 hiveNodeCallback& m_anyNodeFoundCallback;
53 hiveNodeCallback& m_localNodeFoundCallback;
54 hiveNodeCallback& m_nodeRemovedCallback;
56 bool m_running =
false;
58 bool m_isConfigured =
false;
59 std::string m_name =
"N/A";
61 std::chrono::seconds m_deadNodeTimeout = std::chrono::seconds(2);
62 int m_broadcastIntervalInSeconds = 1;
64 std::vector<std::string> m_localIpAddresses;