Node optimization
This commit is contained in:
parent
91826963cd
commit
fb7879e2c6
@ -44,17 +44,16 @@ namespace Components
|
|||||||
|
|
||||||
void Node::AddNode(Network::Address address, bool valid)
|
void Node::AddNode(Network::Address address, bool valid)
|
||||||
{
|
{
|
||||||
//#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (address.IsSelf()) return;
|
if (address.IsSelf()) return;
|
||||||
// #else
|
#else
|
||||||
// if (address.IsLocal() || address.IsSelf()) return;
|
if (address.IsLocal() || address.IsSelf()) return;
|
||||||
// #endif
|
#endif
|
||||||
|
|
||||||
Node::NodeEntry entry;
|
Node::NodeEntry entry;
|
||||||
|
|
||||||
entry.startTime = 0;
|
|
||||||
entry.lastHeartbeat = 0;
|
entry.lastHeartbeat = 0;
|
||||||
entry.endTime = (valid ? Game::Com_Milliseconds() : 0);
|
entry.lastTime = (valid ? Game::Com_Milliseconds() : 0);
|
||||||
entry.state = (valid ? Node::STATE_VALID : Node::STATE_UNKNOWN);
|
entry.state = (valid ? Node::STATE_VALID : Node::STATE_UNKNOWN);
|
||||||
entry.address = address;
|
entry.address = address;
|
||||||
|
|
||||||
@ -68,7 +67,7 @@ namespace Components
|
|||||||
if (valid)
|
if (valid)
|
||||||
{
|
{
|
||||||
ourEntry.state = Node::STATE_VALID;
|
ourEntry.state = Node::STATE_VALID;
|
||||||
ourEntry.endTime = Game::Com_Milliseconds();
|
ourEntry.lastTime = Game::Com_Milliseconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
duplicate = true;
|
duplicate = true;
|
||||||
@ -87,8 +86,7 @@ namespace Components
|
|||||||
{
|
{
|
||||||
Node::DediEntry entry;
|
Node::DediEntry entry;
|
||||||
|
|
||||||
entry.startTime = 0;
|
entry.lastTime = 0;
|
||||||
entry.endTime = 0;
|
|
||||||
entry.state = Node::STATE_UNKNOWN;
|
entry.state = Node::STATE_UNKNOWN;
|
||||||
entry.address = address;
|
entry.address = address;
|
||||||
|
|
||||||
@ -100,7 +98,7 @@ namespace Components
|
|||||||
{
|
{
|
||||||
if (dirty)
|
if (dirty)
|
||||||
{
|
{
|
||||||
ourEntry.endTime = Game::Com_Milliseconds();
|
ourEntry.lastTime = Game::Com_Milliseconds();
|
||||||
ourEntry.state = Node::STATE_UNKNOWN;
|
ourEntry.state = Node::STATE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +177,7 @@ namespace Components
|
|||||||
if (dedi.address == address)
|
if (dedi.address == address)
|
||||||
{
|
{
|
||||||
dedi.state = (info.Get("challenge") == dedi.challenge ? Node::STATE_VALID : Node::STATE_INVALID);
|
dedi.state = (info.Get("challenge") == dedi.challenge ? Node::STATE_VALID : Node::STATE_INVALID);
|
||||||
dedi.endTime = Game::Com_Milliseconds();
|
dedi.lastTime = Game::Com_Milliseconds();
|
||||||
|
|
||||||
if (dedi.state == Node::STATE_VALID)
|
if (dedi.state == Node::STATE_VALID)
|
||||||
{
|
{
|
||||||
@ -329,7 +327,7 @@ namespace Components
|
|||||||
if (dedi.address == address)
|
if (dedi.address == address)
|
||||||
{
|
{
|
||||||
dedi.state = Node::STATE_INVALID;
|
dedi.state = Node::STATE_INVALID;
|
||||||
dedi.endTime = Game::Com_Milliseconds();
|
dedi.lastTime = Game::Com_Milliseconds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +336,7 @@ namespace Components
|
|||||||
if (node.address == address)
|
if (node.address == address)
|
||||||
{
|
{
|
||||||
node.state = Node::STATE_INVALID;
|
node.state = Node::STATE_INVALID;
|
||||||
node.endTime = Game::Com_Milliseconds();
|
node.lastTime = Game::Com_Milliseconds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -351,12 +349,11 @@ namespace Components
|
|||||||
// Send requests
|
// Send requests
|
||||||
for (auto &node : Node::Nodes)
|
for (auto &node : Node::Nodes)
|
||||||
{
|
{
|
||||||
if (count < NODE_FRAME_QUERY_LIMIT && (node.state == Node::STATE_UNKNOWN || (/*node.state != Node::STATE_INVALID && */node.state != Node::STATE_QUERYING && (Game::Com_Milliseconds() - node.endTime) > (NODE_VALIDITY_EXPIRE))))
|
if (count < NODE_FRAME_QUERY_LIMIT && (node.state == Node::STATE_UNKNOWN || (/*node.state != Node::STATE_INVALID && */node.state != Node::STATE_QUERYING && (Game::Com_Milliseconds() - node.lastTime) > (NODE_VALIDITY_EXPIRE))))
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
node.startTime = Game::Com_Milliseconds();
|
node.lastTime = Game::Com_Milliseconds();
|
||||||
node.endTime = 0;
|
|
||||||
node.state = Node::STATE_QUERYING;
|
node.state = Node::STATE_QUERYING;
|
||||||
|
|
||||||
Logger::Print("Syncing with node %s...\n", node.address.GetString());
|
Logger::Print("Syncing with node %s...\n", node.address.GetString());
|
||||||
@ -369,10 +366,10 @@ namespace Components
|
|||||||
Node::SendDediList(node.address);
|
Node::SendDediList(node.address);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.state == Node::STATE_QUERYING && (Game::Com_Milliseconds() - node.startTime) > (NODE_QUERY_TIMEOUT))
|
if (node.state == Node::STATE_QUERYING && (Game::Com_Milliseconds() - node.lastTime) > (NODE_QUERY_TIMEOUT))
|
||||||
{
|
{
|
||||||
node.state = Node::STATE_INVALID;
|
node.state = Node::STATE_INVALID;
|
||||||
node.endTime = Game::Com_Milliseconds();
|
node.lastTime = Game::Com_Milliseconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.state == Node::STATE_VALID)
|
if (node.state == Node::STATE_VALID)
|
||||||
@ -392,13 +389,12 @@ namespace Components
|
|||||||
|
|
||||||
for (auto &dedi : Node::Dedis)
|
for (auto &dedi : Node::Dedis)
|
||||||
{
|
{
|
||||||
if (count < DEDI_FRAME_QUERY_LIMIT && (dedi.state == Node::STATE_UNKNOWN || (/*node.state != Node::STATE_INVALID && */dedi.state != Node::STATE_QUERYING && (Game::Com_Milliseconds() - dedi.endTime) > (DEDI_VALIDITY_EXPIRE))))
|
if (count < DEDI_FRAME_QUERY_LIMIT && (dedi.state == Node::STATE_UNKNOWN || (/*node.state != Node::STATE_INVALID && */dedi.state != Node::STATE_QUERYING && (Game::Com_Milliseconds() - dedi.lastTime) > (DEDI_VALIDITY_EXPIRE))))
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
dedi.startTime = Game::Com_Milliseconds();
|
dedi.lastTime = Game::Com_Milliseconds();
|
||||||
dedi.endTime = 0;
|
dedi.challenge = Utils::VA("%d", dedi.lastTime);
|
||||||
dedi.challenge = Utils::VA("%d", dedi.startTime);
|
|
||||||
dedi.state = Node::STATE_QUERYING;
|
dedi.state = Node::STATE_QUERYING;
|
||||||
|
|
||||||
Logger::Print("Verifying dedi %s...\n", dedi.address.GetString());
|
Logger::Print("Verifying dedi %s...\n", dedi.address.GetString());
|
||||||
@ -408,14 +404,14 @@ namespace Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No query response
|
// No query response
|
||||||
if (dedi.state == Node::STATE_QUERYING && (Game::Com_Milliseconds() - dedi.startTime) > (DEDI_QUERY_TIMEOUT))
|
if (dedi.state == Node::STATE_QUERYING && (Game::Com_Milliseconds() - dedi.lastTime) > (DEDI_QUERY_TIMEOUT))
|
||||||
{
|
{
|
||||||
dedi.state = Node::STATE_INVALID;
|
dedi.state = Node::STATE_INVALID;
|
||||||
dedi.endTime = Game::Com_Milliseconds();
|
dedi.lastTime = Game::Com_Milliseconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lack of heartbeats
|
// Lack of heartbeats
|
||||||
if (dedi.state == Node::STATE_VALID && (Game::Com_Milliseconds() - dedi.startTime) > (HEARTBEAT_DEADLINE))
|
if (dedi.state == Node::STATE_VALID && (Game::Com_Milliseconds() - dedi.lastTime) > (HEARTBEAT_DEADLINE))
|
||||||
{
|
{
|
||||||
Logger::Print("Invalidating dedi %s\n", dedi.address.GetString());
|
Logger::Print("Invalidating dedi %s\n", dedi.address.GetString());
|
||||||
dedi.state = Node::STATE_INVALID;
|
dedi.state = Node::STATE_INVALID;
|
||||||
@ -452,7 +448,18 @@ namespace Components
|
|||||||
{
|
{
|
||||||
if (params.Length() < 2) return;
|
if (params.Length() < 2) return;
|
||||||
|
|
||||||
Node::AddNode(Network::Address(params[1]));
|
Network::Address address(params[1]);
|
||||||
|
Node::AddNode(address);
|
||||||
|
|
||||||
|
// Invalidate it
|
||||||
|
for (auto &node : Node::Nodes)
|
||||||
|
{
|
||||||
|
if (node.address == address)
|
||||||
|
{
|
||||||
|
node.state = Node::STATE_UNKNOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,7 @@ namespace Components
|
|||||||
{
|
{
|
||||||
Network::Address address;
|
Network::Address address;
|
||||||
EntryState state;
|
EntryState state;
|
||||||
int startTime;
|
int lastTime;
|
||||||
int endTime;
|
|
||||||
int lastHeartbeat;
|
int lastHeartbeat;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -45,8 +44,7 @@ namespace Components
|
|||||||
Network::Address address;
|
Network::Address address;
|
||||||
std::string challenge;
|
std::string challenge;
|
||||||
EntryState state;
|
EntryState state;
|
||||||
int startTime;
|
int lastTime;
|
||||||
int endTime;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user