feat: config class
This commit is contained in:
@@ -10,7 +10,7 @@ ClusterManager::ClusterManager(NodeContext& ctx) : ctx(ctx) {
|
||||
|
||||
void ClusterManager::sendDiscovery() {
|
||||
//Serial.println("[Cluster] Sending discovery packet...");
|
||||
ctx.udp->beginPacket("255.255.255.255", ClusterProtocol::UDP_PORT);
|
||||
ctx.udp->beginPacket("255.255.255.255", ctx.config.udp_port);
|
||||
ctx.udp->write(ClusterProtocol::DISCOVERY_MSG);
|
||||
ctx.udp->endPacket();
|
||||
}
|
||||
@@ -26,7 +26,7 @@ void ClusterManager::listenForDiscovery() {
|
||||
//Serial.printf("[UDP] Packet received: %s\n", incoming);
|
||||
if (strcmp(incoming, ClusterProtocol::DISCOVERY_MSG) == 0) {
|
||||
//Serial.printf("[UDP] Discovery request from: %s\n", ctx.udp->remoteIP().toString().c_str());
|
||||
ctx.udp->beginPacket(ctx.udp->remoteIP(), ClusterProtocol::UDP_PORT);
|
||||
ctx.udp->beginPacket(ctx.udp->remoteIP(), ctx.config.udp_port);
|
||||
String response = String(ClusterProtocol::RESPONSE_MSG) + ":" + ctx.hostname;
|
||||
ctx.udp->write(response.c_str());
|
||||
ctx.udp->endPacket();
|
||||
@@ -57,7 +57,7 @@ void ClusterManager::addOrUpdateNode(const String& nodeHost, IPAddress nodeIP) {
|
||||
newNode.hostname = nodeHost;
|
||||
newNode.ip = nodeIP;
|
||||
newNode.lastSeen = millis();
|
||||
updateNodeStatus(newNode, newNode.lastSeen);
|
||||
updateNodeStatus(newNode, newNode.lastSeen, ctx.config.node_inactive_threshold_ms, ctx.config.node_dead_threshold_ms);
|
||||
memberList[nodeHost] = newNode;
|
||||
Serial.printf("[Cluster] Added node: %s @ %s | Status: %s | last update: 0\n",
|
||||
nodeHost.c_str(),
|
||||
@@ -140,7 +140,7 @@ void ClusterManager::updateAllNodeStatuses() {
|
||||
unsigned long now = millis();
|
||||
for (auto& pair : memberList) {
|
||||
NodeInfo& node = pair.second;
|
||||
updateNodeStatus(node, now);
|
||||
updateNodeStatus(node, now, ctx.config.node_inactive_threshold_ms, ctx.config.node_dead_threshold_ms);
|
||||
node.latency = now - node.lastSeen;
|
||||
}
|
||||
}
|
||||
@@ -152,7 +152,7 @@ void ClusterManager::removeDeadNodes() {
|
||||
// Use iterator to safely remove elements from map
|
||||
for (auto it = memberList.begin(); it != memberList.end(); ) {
|
||||
unsigned long diff = now - it->second.lastSeen;
|
||||
if (it->second.status == NodeInfo::DEAD && diff > NODE_DEAD_THRESHOLD) {
|
||||
if (it->second.status == NodeInfo::DEAD && diff > ctx.config.node_dead_threshold_ms) {
|
||||
Serial.printf("[Cluster] Removing node: %s\n", it->second.hostname.c_str());
|
||||
it = memberList.erase(it);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user