Use non-blocking connects, and a select() call to wait a predefined time (5s by default, but configurable with -timeout) for either success or failure. This allows much more connections to be tried per time unit.
Based on a patch by phantomcircuit.
Use non-blocking connects, and a select() call to wait a predefined time (5s by default, but configurable with -timeout) for either success or failure. This allows much more connections to be tried per time unit.
Based on a patch by phantomcircuit.
As devrandom pointed out, tor latency could be much greater than 5s. Maybe add if (fProxy) timeout = 20s?
Maybe this can be done adaptively: start with a timeout=100ms, and each time N connection attempts have failed through time-out (and not enough connections are established), double the timeout.
I think making it a command line override option would be a better way of handling it. In general you want to avoid connecting to other nodes where your network path is that latent. That way people who have known-latent paths can manually bump the timeout but it works as expected for most users.
@jrmithdobbs: good suggestion - implemented.
I'd prefer removing the nConnectTimeout global variable and just calling GetArg("-timeout", 5000) in ConnectSocket.
My name is phantomcircuit and I approve this patch.
@gavinandresen: I disagree - I don't like global variables, but doing parsing of command-line options all over the place is even worse.
bleh, this is overkill.
Use select with timeout -- as net.cpp already does -- and eliminate that polling loop.
In all of linux/osx/winsock, you issue a non-blocking connect(2), and then select(2) the socket for writing.
ACK final result. Needs to be rebased though...
ACK -- looks OK, but I haven't had time to compile and test.
Use non-blocking connects, and a select() call to wait a predefined
time (5s by default, but configurable with -timeout) for either
success or failure. This allows much more connections to be tried
per time unit.
Based on a patch by phantomcircuit.
Now using select() instead of looping. Tested on Linux and Windows.