mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
actually connect to random routers
This commit is contained in:
parent
a3e7324e9a
commit
9f153f12e0
1 changed files with 20 additions and 13 deletions
|
@ -121,21 +121,28 @@ namespace llarp
|
|||
OutboundSessionMaker::ConnectToRandomRouters(int numDesired)
|
||||
{
|
||||
int remainingDesired = numDesired;
|
||||
|
||||
_nodedb->visit([&](const RouterContact &other) -> bool {
|
||||
if(!_rcLookup->RemoteIsAllowed(other.pubkey))
|
||||
std::set< RouterID > exclude;
|
||||
int itersLeft = 100;
|
||||
do
|
||||
{
|
||||
RouterContact other;
|
||||
--itersLeft;
|
||||
if(_nodedb->select_random_hop_excluding(other, exclude))
|
||||
{
|
||||
return remainingDesired > 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
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…
Reference in a new issue