5 #include "protodefinitions/Hermes.pb.h"
27 static const unsigned long s_BufferSize = 65535;
30 Hive(hiveNodeCallback& _onNodeFound, hiveNodeCallback& _onLocalNodeFound, hiveNodeCallback& _onNodeRemoved);
35 Hive& operator=(
const Hive&) =
delete;
37 void Configure(std::string _name,
bool _useLoopback =
true,
int _beaconPort = (
int)Hermes::Protocol::DefaultPorts::HivePort,
int _broadcastIntervalInSeconds = 1,
int _deadNodeTimeoutInSeconds = 10);
42 static bool DoesEnvironmentVariableExist(std::wstring p_EnvironmentVariable);
43 static std::unique_ptr<Hive>
FindCoordinator(std::string _name,
int _beaconPort, hiveNodeCallback& _onNodeFound, hiveNodeCallback& _onLocalNodeFound, hiveNodeCallback& _onNodeRemoved,
bool _useLoopback);
44 static std::unique_ptr<Hive>
FindLocalCoordinator(std::string _name,
int _beaconPort, hiveNodeCallback& _onNodeFound, hiveNodeCallback& _onLocalNodeFound, hiveNodeCallback& _onNodeRemoved);
45 static std::unique_ptr<Hive>
FindNetworkCoordinator(std::string _name,
int _beaconPort, hiveNodeCallback& _onNodeFound, hiveNodeCallback& _onLocalNodeFound, hiveNodeCallback& _onNodeRemoved);
48 static std::unique_ptr<Hermes::Protocol::HiveNode> tryParseHiveNodeFromBytes(
unsigned char*_data,
int _size);
52 struct HiveNodeTimeStamped {
54 std::chrono::system_clock::time_point lastseen;
56 std::vector<HiveNodeTimeStamped> m_nodes;
57 std::mutex m_nodes_mutex;
60 void subscriberThreadFunction();
61 void nodeCleanupThreadFunction();
62 std::unique_ptr<std::thread> m_subscriberThread;
63 std::unique_ptr<std::thread> m_nodeCleanupThread;
66 hiveNodeCallback& m_anyNodeFoundCallback;
67 hiveNodeCallback& m_localNodeFoundCallback;
68 hiveNodeCallback& m_nodeRemovedCallback;
70 bool m_running =
false;
72 bool m_isConfigured =
false;
73 std::string m_name =
"N/A";
75 std::chrono::seconds m_deadNodeTimeout = std::chrono::seconds(2);
76 int m_broadcastIntervalInSeconds = 1;
78 std::vector<std::string> m_localIpAddresses;