From ad44aa5c64d4ee5f31c867fda26350ab560575b7 Mon Sep 17 00:00:00 2001 From: dergoegge Date: Tue, 14 Mar 2023 17:38:03 +0100 Subject: [PATCH] [net] Add connection type getter to CNode --- src/net.cpp | 6 +++--- src/net.h | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 9b803180f97..986c9b119b8 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -917,7 +917,7 @@ bool CConnman::AttemptToEvictConnection() .m_is_local = node->addr.IsLocal(), .m_network = node->ConnectedThroughNetwork(), .m_noban = node->HasPermission(NetPermissionFlags::NoBan), - .m_conn_type = node->m_conn_type, + .m_conn_type = node->GetConnectionType(), }; vEvictionCandidates.push_back(candidate); } @@ -1092,7 +1092,7 @@ bool CConnman::AddConnection(const std::string& address, ConnectionType conn_typ // Count existing connections int existing_connections = WITH_LOCK(m_nodes_mutex, - return std::count_if(m_nodes.begin(), m_nodes.end(), [conn_type](CNode* node) { return node->m_conn_type == conn_type; });); + return std::count_if(m_nodes.begin(), m_nodes.end(), [conn_type](CNode* node) { return node->GetConnectionType() == conn_type; });); // Max connections of specified type already exist if (max_connections != std::nullopt && existing_connections >= max_connections) return false; @@ -1722,7 +1722,7 @@ void CConnman::ThreadOpenConnections(const std::vector connect) if (pnode->IsBlockOnlyConn()) nOutboundBlockRelay++; // Make sure our persistent outbound slots belong to different netgroups. - switch (pnode->m_conn_type) { + switch (pnode->GetConnectionType()) { // We currently don't take inbound connections into account. Since they are // free to make, an attacker could make them to prevent us from connecting to // certain peers. diff --git a/src/net.h b/src/net.h index 2025dfdb054..7cc23392479 100644 --- a/src/net.h +++ b/src/net.h @@ -417,6 +417,11 @@ public: std::atomic_bool fPauseRecv{false}; std::atomic_bool fPauseSend{false}; + const ConnectionType& GetConnectionType() const + { + return m_conn_type; + } + bool IsOutboundOrBlockRelayConn() const { switch (m_conn_type) { case ConnectionType::OUTBOUND_FULL_RELAY: