net: Block v2->v1 transport downgrade if !CConnman::fNetworkActive

We might have just set CNode::fDisconnect in the first loop because of being offline.

Also caches CConnman::fNetworkActive in case it's changed concurrently with our own thread.
This commit is contained in:
Hodlinator 2025-02-12 12:02:53 +01:00
parent 698f86964c
commit 6869fb4170
No known key found for this signature in database

View file

@ -1910,7 +1910,8 @@ void CConnman::DisconnectNodes()
{
LOCK(m_nodes_mutex);
if (!fNetworkActive) {
const bool network_active{fNetworkActive};
if (!network_active) {
// Disconnect any connected nodes
for (CNode* pnode : m_nodes) {
if (!pnode->fDisconnect) {
@ -1932,7 +1933,7 @@ void CConnman::DisconnectNodes()
// Add to reconnection list if appropriate. We don't reconnect right here, because
// the creation of a connection is a blocking operation (up to several seconds),
// and we don't want to hold up the socket handler thread for that long.
if (pnode->m_transport->ShouldReconnectV1()) {
if (network_active && pnode->m_transport->ShouldReconnectV1()) {
reconnections_to_add.push_back({
.addr_connect = pnode->addr,
.grant = std::move(pnode->grantOutbound),