Skip to content

Conversation

sipa
Copy link
Member

@sipa sipa commented Jun 5, 2011

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.

@TheBlueMatt
Copy link
Contributor

As devrandom pointed out, tor latency could be much greater than 5s. Maybe add if (fProxy) timeout = 20s?

@sipa
Copy link
Member Author

sipa commented Jun 6, 2011

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.

@jrmithdobbs
Copy link
Contributor

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.

@sipa
Copy link
Member Author

sipa commented Jun 6, 2011

@jrmithdobbs: good suggestion - implemented.

@gavinandresen
Copy link
Contributor

I'd prefer removing the nConnectTimeout global variable and just calling GetArg("-timeout", 5000) in ConnectSocket.

@phantomcircuit
Copy link

My name is phantomcircuit and I approve this patch.

@sipa
Copy link
Member Author

sipa commented Jun 8, 2011

@gavinandresen: I disagree - I don't like global variables, but doing parsing of command-line options all over the place is even worse.

@jgarzik
Copy link
Contributor

jgarzik commented Jun 10, 2011

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.

@jgarzik
Copy link
Contributor

jgarzik commented Jun 11, 2011

ACK final result. Needs to be rebased though...

@gavinandresen
Copy link
Contributor

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.
@sipa
Copy link
Member Author

sipa commented Jun 11, 2011

Now using select() instead of looping. Tested on Linux and Windows.

jgarzik pushed a commit that referenced this pull request Jun 11, 2011
non-blocking connect (by phantomcircuit)
@jgarzik jgarzik merged commit ce14894 into bitcoin:master Jun 11, 2011
ptschip pushed a commit to ptschip/bitcoin that referenced this pull request Feb 17, 2017
Trivial: Update copyright year to 2017
ptschip pushed a commit to ptschip/bitcoin that referenced this pull request Apr 9, 2017
Trivial: Update copyright year to 2017
(cherry picked from commit 52c6f73)
destenson pushed a commit to destenson/bitcoin--bitcoin that referenced this pull request Nov 18, 2017
c01500c protobump (rejectedpromise)

Tree-SHA512: ad0a5f4e6d1ff0a4df54d310e675c044b7a400efab0398beb88868b1aab3c9b3d299a7ec4247b471d63c01106120d03ae517971541d699a07d3b8cd16f346a51
classesjack pushed a commit to classesjack/bitcoin that referenced this pull request Jan 2, 2018
classesjack pushed a commit to classesjack/bitcoin that referenced this pull request Jan 2, 2018
…ue-300

Fixing issue bitcoin#300 (by soft-disabling the -prune and -txindex flags)
classesjack pushed a commit to classesjack/bitcoin that referenced this pull request Jan 2, 2018
Losangelosgenetics pushed a commit to Losangelosgenetics/bitcoin that referenced this pull request Mar 12, 2020
rajarshimaitra pushed a commit to rajarshimaitra/bitcoin that referenced this pull request Aug 5, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants