diff --git a/src/net.cpp b/src/net.cpp index 102d81579f9e8..5d432cca14c1a 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2423,12 +2423,15 @@ void CConnman::ThreadOpenConnections(const std::vector 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 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(); } } diff --git a/src/net.h b/src/net.h index 547e032ba6101..6b9386e511ed3 100644 --- a/src/net.h +++ b/src/net.h @@ -1084,10 +1084,11 @@ class CConnman vWhitelistedRange = connOptions.vWhitelistedRange; { LOCK(m_added_nodes_mutex); - + // 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 (const std::string& added_node : connOptions.m_added_nodes) { - // -addnode cli arg does not currently have a way to signal BIP324 support - m_added_node_params.push_back({added_node, false}); + m_added_node_params.push_back({added_node, use_v2transport}); } } m_onion_binds = connOptions.onion_binds;