diff options
author | Ava Chow <github@achow101.com> | 2024-01-09 12:11:47 -0500 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-01-09 12:46:52 -0500 |
commit | 063a8b83875997068b3eb506b5f30f2691d18052 (patch) | |
tree | 9757d0ca1d2d0cd2142183ee0c06da3667f9980e /src/net.cpp | |
parent | 5a121bcdeed2904d94c9489d352d39d22d52fc7c (diff) | |
parent | fb5bfed26a564014b83ccfc96ff00b630930fc61 (diff) |
Merge bitcoin/bitcoin#29058: net, cli: use v2transport for manual/addrfetch connections, add to -netinfo
fb5bfed26a564014b83ccfc96ff00b630930fc61 cli: add transport protcol column to -netinfo (Martin Zumsande)
9eed22e870e650cadf5f65650917da21836d2bb0 net: attempt v2 transport for addrfetch connections if we support it (Martin Zumsande)
770c0311ef5e35444efe4fd26f7bb5782624cf2c net: attempt v2 transport for manual connections if we support it (Martin Zumsande)
Pull request description:
Some preparations before enabling `-v2transport` as the default:
* Use v2 for `-connect`, `-addnode` config arg and `-seednode` if `-v2transport` is enabled.
Our peer may or may not support v2, but I don't think an extra option is necessary for any of these (we have that for the `addnode` rpc), because we have the reconnection mechanism that will try again with `v1` if our peer doesn't support `v2`.
* Add a column for the transport protocol to `-netinfo`. I added it next to the `net` column because I thought it looked nice there, but if people prefer it somewhere else I'm happy to move it.
![Screenshot from 2023-12-11 17-51-22](https://github.com/bitcoin/bitcoin/assets/48763452/b4f5dfcb-16be-4d8f-9303-9d342123deec)
ACKs for top commit:
sipa:
utACK fb5bfed26a564014b83ccfc96ff00b630930fc61
achow101:
ACK fb5bfed26a564014b83ccfc96ff00b630930fc61
stratospher:
tested ACK fb5bfed. addrfetch + manual connections aren't frequent and it would be useful to have this for transition to v2 one day.
theStack:
ACK fb5bfed26a564014b83ccfc96ff00b630930fc61
kristapsk:
ACK fb5bfed26a564014b83ccfc96ff00b630930fc61
Tree-SHA512: c4575ad11b99613870b342acae369fa08f877ac79e6e04eb62e94ad7a92d528e289183c0963c78aa779ba11cb91e2a6fad7c8b0d813126c46c3e5b54bd962c26
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/net.cpp b/src/net.cpp index 41f5323d91..0cc794c2c3 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2316,10 +2316,13 @@ void CConnman::ProcessAddrFetch() strDest = m_addr_fetches.front(); m_addr_fetches.pop_front(); } + // 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); CAddress addr; CSemaphoreGrant grant(*semOutbound, /*fTry=*/true); if (grant) { - OpenNetworkConnection(addr, false, std::move(grant), strDest.c_str(), ConnectionType::ADDR_FETCH, /*use_v2transport=*/false); + OpenNetworkConnection(addr, false, std::move(grant), strDest.c_str(), ConnectionType::ADDR_FETCH, use_v2transport); } } @@ -2417,12 +2420,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))) @@ -2431,6 +2437,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect) } if (!interruptNet.sleep_for(std::chrono::milliseconds(500))) return; + PerformReconnections(); } } @@ -2840,11 +2847,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(); } } |