diff options
author | Martin Zumsande <mzumsande@gmail.com> | 2023-12-11 14:37:56 -0500 |
---|---|---|
committer | Martin Zumsande <mzumsande@gmail.com> | 2023-12-27 16:39:32 -0500 |
commit | 770c0311ef5e35444efe4fd26f7bb5782624cf2c (patch) | |
tree | 41d90ddca13004630d8a3c0724412ba1aa6d13b4 /src/net.cpp | |
parent | d5e5810bd36f6e899d64a57e9264729b27a9c3f8 (diff) | |
download | bitcoin-770c0311ef5e35444efe4fd26f7bb5782624cf2c.tar.xz |
net: attempt v2 transport for manual connections if we support it
This affects manual connections made either with -connect, or with
-addnode provided as a bitcoind config arg (the addnode RPC has an
extra option for v2).
We don't necessarily know if our peer supports v2, but will reconnect
with v1 if they don't. In order to do that, improve the reconnection
behavior such that we will reconnect after a sleep of 500ms
(which usually should be enough for our peer to send us their
version message).
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp index 102d81579f..5d432cca14 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2423,12 +2423,15 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect) // Connect to specific addresses if (!connect.empty()) { + // Attempt v2 connection if we support v2 - we'll reconnect with v1 if our + // peer doesn't support it or immediately disconnects us for another reason. + const bool use_v2transport(GetLocalServices() & NODE_P2P_V2); for (int64_t nLoop = 0;; nLoop++) { for (const std::string& strAddr : connect) { CAddress addr(CService(), NODE_NONE); - OpenNetworkConnection(addr, false, {}, strAddr.c_str(), ConnectionType::MANUAL, /*use_v2transport=*/false); + OpenNetworkConnection(addr, false, {}, strAddr.c_str(), ConnectionType::MANUAL, /*use_v2transport=*/use_v2transport); for (int i = 0; i < 10 && i < nLoop; i++) { if (!interruptNet.sleep_for(std::chrono::milliseconds(500))) @@ -2437,6 +2440,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect) } if (!interruptNet.sleep_for(std::chrono::milliseconds(500))) return; + PerformReconnections(); } } @@ -2846,11 +2850,11 @@ void CConnman::ThreadOpenAddedConnections() if (!interruptNet.sleep_for(std::chrono::milliseconds(500))) return; grant = CSemaphoreGrant(*semAddnode, /*fTry=*/true); } + // See if any reconnections are desired. + PerformReconnections(); // Retry every 60 seconds if a connection was attempted, otherwise two seconds if (!interruptNet.sleep_for(std::chrono::seconds(tried ? 60 : 2))) return; - // See if any reconnections are desired. - PerformReconnections(); } } |