In the inner loop of ThreadOpenConnections() in net.cpp sometimes there is a break to the outer loop and sometimes a continue. This is my understanding of the decision between break and continue in this part of the code:
- A break fully 'restarts' the search for an outward connection, the type of which will be determined again. Also new incoming potential peers will be included in the addrman tables.
- A continue effectivily just asks addrman for a next candidate peer from the existing tables. The type of outward connection that we wish for remains the same.
My question is about the choice of break versus continue in two cases. Here the code does a break:
// if we selected an invalid or local address, restart
if (!addr.IsValid() || IsLocal(addr)) {
break;
}
While a few lines below there is a continue:
if (!IsReachable(addr))
continue;
My question is: why 'restart' in the first code snippet and not continue? In other words: why not ask addrman a few times more, as it might supply a valid address soon? Or, for the second snippet, if we got an unreachable address: why not restart, so addrman might get refreshed with more reachable addresses?
I tried to find the answer by tracking back the history of this part of the code. The break in the first code snippet above appears to stem from the introduction of the address manager (pr/787). It did not seem to answer my question.