diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index 0bd298f5..3617e29a 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -21,8 +21,14 @@ namespace Components } } - void Node::StoreNodes() + void Node::StoreNodes(bool force) { + static int lastStorage = 0; + + // Don't store nodes if the delta is too small and were not forcing it + if ((Game::Com_Milliseconds() - lastStorage) < NODE_STORE_INTERVAL && !force) return; + lastStorage = Game::Com_Milliseconds(); + std::vector entries; for (auto entry : Node::Nodes) @@ -291,7 +297,7 @@ namespace Components if (Dedicated::IsDedicated() && node.state == Node::STATE_VALID) { - if (heartbeatCount < HEARTBEATS_FRAME_LIMIT && (!node.lastHeartbeat || (Game::Com_Milliseconds() - node.lastHeartbeat) >(HEARTBEAT_INTERVAL))) + if (heartbeatCount < HEARTBEATS_FRAME_LIMIT && (!node.lastHeartbeat || (Game::Com_Milliseconds() - node.lastHeartbeat) > (HEARTBEAT_INTERVAL))) { heartbeatCount++; @@ -337,8 +343,7 @@ namespace Components Node::DeleteInvalidNodes(); Node::DeleteInvalidDedis(); - - count = 0; + Node::StoreNodes(false); } void Node::DeleteInvalidDedis() @@ -565,7 +570,8 @@ namespace Components Node::~Node() { - Node::StoreNodes(); + Node::StoreNodes(true); Node::Nodes.clear(); + Node::Dedis.clear(); } } diff --git a/src/Components/Modules/Node.hpp b/src/Components/Modules/Node.hpp index aaa8e2f4..07ca433d 100644 --- a/src/Components/Modules/Node.hpp +++ b/src/Components/Modules/Node.hpp @@ -17,6 +17,8 @@ #define NODE_PACKET_LIMIT 111 // Send 111 nodes per synchronization packet #define DEDI_PACKET_LIMIT 111 // Send 111 dedis per synchronization packet +#define NODE_STORE_INTERVAL 1000 * 60* 1 // Store nodes every minute + namespace Components { class Node : public Component @@ -86,7 +88,7 @@ namespace Components static std::vector Dedis; static void LoadNodes(); - static void StoreNodes(); + static void StoreNodes(bool force); static void AddNode(Network::Address address, bool valid = false); static void AddDedi(Network::Address address, bool dirty = false);