mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-25 15:05:55 +01:00
Merge bitcoin/bitcoin#29058: net, cli: use v2transport for manual/addrfetch connections, add to -netinfo
fb5bfed26acli: add transport protcol column to -netinfo (Martin Zumsande)9eed22e870net: attempt v2 transport for addrfetch connections if we support it (Martin Zumsande)770c0311efnet: 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.  ACKs for top commit: sipa: utACKfb5bfed26aachow101: ACKfb5bfed26astratospher: tested ACKfb5bfed. addrfetch + manual connections aren't frequent and it would be useful to have this for transition to v2 one day. theStack: ACKfb5bfed26akristapsk: ACKfb5bfed26aTree-SHA512: c4575ad11b99613870b342acae369fa08f877ac79e6e04eb62e94ad7a92d528e289183c0963c78aa779ba11cb91e2a6fad7c8b0d813126c46c3e5b54bd962c26
This commit is contained in:
15
src/net.cpp
15
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user