Skip to content

Commit

Permalink
p2p: Fix off-by-one error in fetching address loop
Browse files Browse the repository at this point in the history
This is a move-only commit.
  • Loading branch information
hebasto committed Oct 9, 2020
1 parent 4170b46 commit 5543c7a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1962,6 +1962,13 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
int nTries = 0;
while (!interruptNet)
{
// If we didn't find an appropriate destination after trying 100 addresses fetched from addrman,
// stop this loop, and let the outer loop run again (which sleeps, adds seed nodes, recalculates
// already-connected network ranges, ...) before trying new addrman addresses.
nTries++;
if (nTries > 100)
break;

CAddrInfo addr = addrman.SelectTriedCollision();

// SelectTriedCollision returns an invalid address if it is empty.
Expand All @@ -1979,13 +1986,6 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
break;
}

// If we didn't find an appropriate destination after trying 100 addresses fetched from addrman,
// stop this loop, and let the outer loop run again (which sleeps, adds seed nodes, recalculates
// already-connected network ranges, ...) before trying new addrman addresses.
nTries++;
if (nTries > 100)
break;

if (!IsReachable(addr))
continue;

Expand Down

0 comments on commit 5543c7a

Please sign in to comment.