diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index 31d238d4..7e0374d2 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -18,7 +18,7 @@ namespace Components { Utils::String::Replace(node, "\r", ""); node = Utils::String::Trim(node); - Node::AddNode(node); + Node::AddNode(node, true); } } @@ -39,7 +39,7 @@ namespace Components for (int i = 0; i < list.address_size(); ++i) { - Node::AddNode(list.address(i)); + Node::AddNode(list.address(i), true); } } @@ -125,7 +125,7 @@ namespace Components return count; } - void Node::AddNode(Network::Address address) + void Node::AddNode(Network::Address address, bool def) { #ifdef DEBUG if (!address.isValid() || address.isSelf()) return; @@ -137,6 +137,7 @@ namespace Components Node::NodeEntry* existingEntry = Node::FindNode(address); if (existingEntry) { + existingEntry->def = false; existingEntry->lastHeard = Game::Sys_Milliseconds(); } else @@ -155,6 +156,7 @@ namespace Components Node::NodeEntry entry; entry.lastHeard = Game::Sys_Milliseconds(); + entry.def = def; entry.lastTime = 0; entry.lastListQuery = 0; entry.registered = false; @@ -222,7 +224,7 @@ namespace Components for (auto i = Node::Nodes.begin(); i != Node::Nodes.end();) { - if (i->state == Node::STATE_INVALID && (Game::Sys_Milliseconds() - i->lastHeard) > NODE_INVALID_DELETE) + if (i->state == Node::STATE_INVALID && ((Game::Sys_Milliseconds() - i->lastHeard) > NODE_INVALID_DELETE || i->def)) { #if defined(DEBUG) && !defined(DISABLE_NODE_LOG) Logger::Print("Removing invalid node %s\n", i->address.getCString()); @@ -520,6 +522,7 @@ namespace Components // Mark as registered entry->lastTime = Game::Sys_Milliseconds(); entry->state = Node::STATE_VALID; + entry->def = false; entry->registered = true; #if defined(DEBUG) && !defined(DISABLE_NODE_LOG) @@ -566,6 +569,7 @@ namespace Components { entry->lastTime = Game::Sys_Milliseconds(); entry->state = Node::STATE_VALID; + entry->def = false; entry->registered = true; #if defined(DEBUG) && !defined(DISABLE_NODE_LOG) @@ -641,6 +645,7 @@ namespace Components if (Utils::Cryptography::ECC::VerifyMessage(entry->publicKey, challenge, signature)) { + entry->def = true; entry->lastHeard = Game::Sys_Milliseconds(); entry->lastTime = Game::Sys_Milliseconds(); entry->registered = false; @@ -736,6 +741,7 @@ namespace Components if (!entry) return; entry->state = Node::STATE_VALID; + entry->def = false; entry->registered = true; entry->lastTime = Game::Sys_Milliseconds(); @@ -773,6 +779,7 @@ namespace Components entry->protocol = list.protocol(); entry->version = list.version(); entry->state = Node::STATE_VALID; + entry->def = false; entry->lastTime = Game::Sys_Milliseconds(); #ifndef DEBUG @@ -860,6 +867,21 @@ namespace Components } }); + Command::Add("nodeinfo", [](Command::Params*) + { + std::lock_guard _(Node::NodeMutex); + unsigned int valid = 0, invalid = 0, negotiating = 0, total = Node::Nodes.size(); + + for (auto& node : Node::Nodes) + { + valid += static_cast(node.state == Node::STATE_VALID); + invalid += static_cast(node.state == Node::STATE_INVALID); + negotiating += static_cast(node.state == Node::STATE_NEGOTIATING); + } + + Logger::Print("Total: %d\nValid: %d\nNegotiating: %d\nInvalid: %d\n\n", total, valid, negotiating, invalid); + }); + Command::Add("addnode", [](Command::Params* params) { if (params->length() < 2) return; diff --git a/src/Components/Modules/Node.hpp b/src/Components/Modules/Node.hpp index 0b7e3357..e4a01f19 100644 --- a/src/Components/Modules/Node.hpp +++ b/src/Components/Modules/Node.hpp @@ -24,7 +24,7 @@ namespace Components bool unitTest() override; static void SyncNodeList(); - static void AddNode(Network::Address address); + static void AddNode(Network::Address address, bool def = false); static unsigned int GetValidNodeCount(); @@ -55,6 +55,8 @@ namespace Components int lastHeard; // Last time we heard something of the server at all (refs form other nodes) int lastListQuery; // Last time we got the list of the node + bool def; + // This is only relevant for clients bool isDedi; uint32_t protocol;