actually connect to random routers

pull/1020/head
Jeff Becker 4 years ago
parent a3e7324e9a
commit 9f153f12e0
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -121,21 +121,28 @@ namespace llarp
OutboundSessionMaker::ConnectToRandomRouters(int numDesired)
{
int remainingDesired = numDesired;
_nodedb->visit([&](const RouterContact &other) -> bool {
if(!_rcLookup->RemoteIsAllowed(other.pubkey))
{
return remainingDesired > 0;
}
if(randint() % 2 == 0
&& !(_linkManager->HasSessionTo(other.pubkey)
|| HavePendingSessionTo(other.pubkey)))
std::set< RouterID > exclude;
int itersLeft = 100;
do
{
RouterContact other;
--itersLeft;
if(_nodedb->select_random_hop_excluding(other, exclude))
{
CreateSessionTo(other, nullptr);
--remainingDesired;
exclude.insert(other.pubkey);
if(not _rcLookup->RemoteIsAllowed(other.pubkey))
{
continue;
}
if(randint() % 2 == 0
&& !(_linkManager->HasSessionTo(other.pubkey)
|| HavePendingSessionTo(other.pubkey)))
{
CreateSessionTo(other, nullptr);
--remainingDesired;
}
}
return remainingDesired > 0;
});
} while(remainingDesired > 0 && itersLeft > 0);
LogDebug("connecting to ", numDesired - remainingDesired, " out of ",
numDesired, " random routers");
}

Loading…
Cancel
Save