Skip to content

Commit 6869fb4

Browse files
committed
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.
1 parent 698f869 commit 6869fb4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/net.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,7 +1910,8 @@ void CConnman::DisconnectNodes()
19101910
{
19111911
LOCK(m_nodes_mutex);
19121912

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

0 commit comments

Comments
 (0)