Skip to content

Commit ad44aa5

Browse files
committed
[net] Add connection type getter to CNode
1 parent 40e1c4d commit ad44aa5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ bool CConnman::AttemptToEvictConnection()
917917
.m_is_local = node->addr.IsLocal(),
918918
.m_network = node->ConnectedThroughNetwork(),
919919
.m_noban = node->HasPermission(NetPermissionFlags::NoBan),
920-
.m_conn_type = node->m_conn_type,
920+
.m_conn_type = node->GetConnectionType(),
921921
};
922922
vEvictionCandidates.push_back(candidate);
923923
}
@@ -1092,7 +1092,7 @@ bool CConnman::AddConnection(const std::string& address, ConnectionType conn_typ
10921092

10931093
// Count existing connections
10941094
int existing_connections = WITH_LOCK(m_nodes_mutex,
1095-
return std::count_if(m_nodes.begin(), m_nodes.end(), [conn_type](CNode* node) { return node->m_conn_type == conn_type; }););
1095+
return std::count_if(m_nodes.begin(), m_nodes.end(), [conn_type](CNode* node) { return node->GetConnectionType() == conn_type; }););
10961096

10971097
// Max connections of specified type already exist
10981098
if (max_connections != std::nullopt && existing_connections >= max_connections) return false;
@@ -1722,7 +1722,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
17221722
if (pnode->IsBlockOnlyConn()) nOutboundBlockRelay++;
17231723

17241724
// Make sure our persistent outbound slots belong to different netgroups.
1725-
switch (pnode->m_conn_type) {
1725+
switch (pnode->GetConnectionType()) {
17261726
// We currently don't take inbound connections into account. Since they are
17271727
// free to make, an attacker could make them to prevent us from connecting to
17281728
// certain peers.

src/net.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ class CNode
417417
std::atomic_bool fPauseRecv{false};
418418
std::atomic_bool fPauseSend{false};
419419

420+
const ConnectionType& GetConnectionType() const
421+
{
422+
return m_conn_type;
423+
}
424+
420425
bool IsOutboundOrBlockRelayConn() const {
421426
switch (m_conn_type) {
422427
case ConnectionType::OUTBOUND_FULL_RELAY:

0 commit comments

Comments
 (0)