mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-21 05:43:59 -07:00
Fix a sporadic warning in cluster-geo, and fix test to not overload the test-watcher.
This commit is contained in:
parent
2854f14966
commit
0e4a2c378f
3 changed files with 25 additions and 16 deletions
|
@ -97,7 +97,7 @@ function agentIdToIp(agentId)
|
|||
};
|
||||
|
||||
var lastTestResult = null;
|
||||
var allOtherAgents = [];
|
||||
var allOtherAgents = {};
|
||||
|
||||
function doTest()
|
||||
{
|
||||
|
@ -114,16 +114,19 @@ function doTest()
|
|||
if (body) {
|
||||
try {
|
||||
var peers = JSON.parse(body);
|
||||
if (Array.isArray(peers))
|
||||
allOtherAgents = allOtherAgents.concat(peers);
|
||||
if (Array.isArray(peers)) {
|
||||
for(var xx=0;xx<peers.length;++xx)
|
||||
allOtherAgents[peers[xx]] = true;
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
if (allOtherAgents.length > 1) {
|
||||
var agents = Object.keys(allOtherAgents);
|
||||
if (agents.length > 1) {
|
||||
|
||||
var target = allOtherAgents[Math.floor(Math.random() * allOtherAgents.length)];
|
||||
var target = agents[Math.floor(Math.random() * agents.length)];
|
||||
while (target === thisAgentId)
|
||||
target = allOtherAgents[Math.floor(Math.random() * allOtherAgents.length)];
|
||||
target = agents[Math.floor(Math.random() * agents.length)];
|
||||
|
||||
var testRequest = null;
|
||||
var timeoutId = null;
|
||||
|
|
|
@ -34,16 +34,16 @@ app.post('/:agentId',function(req,res) {
|
|||
} catch (e) {}
|
||||
}
|
||||
|
||||
var thisUpdate = null;
|
||||
if (!(agentId in knownAgents)) {
|
||||
thisUpdate = Object.keys(knownAgents);
|
||||
for(var id in knownAgents)
|
||||
knownAgents[id].push(agentId);
|
||||
knownAgents[agentId] = [];
|
||||
} else {
|
||||
thisUpdate = knownAgents[agentId];
|
||||
knownAgents[agentId] = [];
|
||||
knownAgents[agentId] = true;
|
||||
var thisUpdate = [];
|
||||
var agents = Object.keys(knownAgents);
|
||||
if (agents.length < 100)
|
||||
thisUpdate = agents;
|
||||
else {
|
||||
for(var xx=0;xx<100;++xx)
|
||||
thisUpdate.push(agents[Math.floor(Math.random() * agents.length)]);
|
||||
}
|
||||
|
||||
return res.status(200).send(JSON.stringify(thisUpdate));
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue