Skip to content

Commit 49efac5

Browse files
committed
[net/refactor] Remove m_manual_connection flag from CNode
1 parent d3698b5 commit 49efac5

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/net.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
539539
X(cleanSubVer);
540540
}
541541
X(fInbound);
542-
X(m_manual_connection);
542+
stats.m_manual_connection = IsManualConn();
543543
X(nStartingHeight);
544544
{
545545
LOCK(cs_vSend);
@@ -1648,7 +1648,7 @@ void CConnman::ThreadDNSAddressSeed()
16481648
{
16491649
LOCK(cs_vNodes);
16501650
for (const CNode* pnode : vNodes) {
1651-
nRelevant += pnode->fSuccessfullyConnected && !pnode->fFeeler && !pnode->m_addr_fetch && !pnode->m_manual_connection && !pnode->fInbound;
1651+
nRelevant += pnode->fSuccessfullyConnected && !pnode->fFeeler && !pnode->m_addr_fetch && !pnode->IsManualConn() && !pnode->fInbound;
16521652
}
16531653
}
16541654
if (nRelevant >= 2) {
@@ -1758,7 +1758,7 @@ int CConnman::GetExtraOutboundCount()
17581758
{
17591759
LOCK(cs_vNodes);
17601760
for (const CNode* pnode : vNodes) {
1761-
if (!pnode->fInbound && !pnode->m_manual_connection && !pnode->fFeeler && !pnode->fDisconnect && !pnode->m_addr_fetch && pnode->fSuccessfullyConnected) {
1761+
if (!pnode->fInbound && !pnode->IsManualConn() && !pnode->fFeeler && !pnode->fDisconnect && !pnode->m_addr_fetch && pnode->fSuccessfullyConnected) {
17621762
++nOutbound;
17631763
}
17641764
}
@@ -1832,7 +1832,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
18321832
{
18331833
LOCK(cs_vNodes);
18341834
for (const CNode* pnode : vNodes) {
1835-
if (!pnode->fInbound && !pnode->m_manual_connection) {
1835+
if (!pnode->fInbound && (pnode->m_conn_type != ConnectionType::MANUAL)) {
18361836
// Netgroups for inbound and addnode peers are not excluded because our goal here
18371837
// is to not use multiple of our limited outbound slots on a single netgroup
18381838
// but inbound and addnode peers do not use our outbound slots. Inbound peers
@@ -2741,7 +2741,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
27412741
addrBind(addrBindIn),
27422742
fFeeler(conn_type_in == ConnectionType::FEELER),
27432743
m_addr_fetch(conn_type_in == ConnectionType::ADDR_FETCH),
2744-
m_manual_connection(conn_type_in == ConnectionType::MANUAL),
27452744
fInbound(conn_type_in == ConnectionType::INBOUND),
27462745
nKeyedNetGroup(nKeyedNetGroupIn),
27472746
// Don't relay addr messages to peers that we connect to as block-relay-only

src/net.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,6 @@ class CNode
777777
bool m_legacyWhitelisted{false};
778778
bool fFeeler{false}; // If true this node is being used as a short lived feeler.
779779
bool m_addr_fetch{false};
780-
bool m_manual_connection{false};
781780
bool fClient{false}; // set by version message
782781
bool m_limited_node{false}; //after BIP159, set by version message
783782
const bool fInbound;
@@ -793,6 +792,10 @@ class CNode
793792
std::atomic_bool fPauseRecv{false};
794793
std::atomic_bool fPauseSend{false};
795794

795+
bool IsManualConn() const {
796+
return m_conn_type == ConnectionType::MANUAL;
797+
}
798+
796799
protected:
797800
mapMsgCmdSize mapSendBytesPerMsgCmd;
798801
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);

src/net_processing.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -827,11 +827,9 @@ void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
827827
if (state) state->m_last_block_announcement = time_in_seconds;
828828
}
829829

830-
// Returns true for outbound peers, excluding manual connections, feelers, and
831-
// one-shots.
832830
static bool IsOutboundDisconnectionCandidate(const CNode& node)
833831
{
834-
return !(node.fInbound || node.m_manual_connection || node.fFeeler || node.m_addr_fetch);
832+
return !(node.fInbound || node.IsManualConn() || node.fFeeler || node.m_addr_fetch);
835833
}
836834

837835
void PeerLogicValidation::InitializeNode(CNode *pnode) {
@@ -840,7 +838,7 @@ void PeerLogicValidation::InitializeNode(CNode *pnode) {
840838
NodeId nodeid = pnode->GetId();
841839
{
842840
LOCK(cs_main);
843-
mapNodeState.emplace_hint(mapNodeState.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(addr, std::move(addrName), pnode->fInbound, pnode->m_manual_connection));
841+
mapNodeState.emplace_hint(mapNodeState.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(addr, std::move(addrName), pnode->fInbound, pnode->IsManualConn()));
844842
}
845843
if(!pnode->fInbound)
846844
PushNodeVersion(*pnode, *connman, GetTime());
@@ -2326,7 +2324,7 @@ void ProcessMessage(
23262324
{
23272325
connman.SetServices(pfrom.addr, nServices);
23282326
}
2329-
if (!pfrom.fInbound && !pfrom.fFeeler && !pfrom.m_manual_connection && !HasAllDesirableServiceFlags(nServices))
2327+
if (!pfrom.fInbound && !pfrom.fFeeler && !pfrom.IsManualConn() && !HasAllDesirableServiceFlags(nServices))
23302328
{
23312329
LogPrint(BCLog::NET, "peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n", pfrom.GetId(), nServices, GetDesirableServiceFlags(nServices));
23322330
pfrom.fDisconnect = true;
@@ -3736,7 +3734,7 @@ bool PeerLogicValidation::MaybeDiscourageAndDisconnect(CNode& pnode)
37363734
return false;
37373735
}
37383736

3739-
if (pnode.m_manual_connection) {
3737+
if (pnode.IsManualConn()) {
37403738
// We never disconnect or discourage manual peers for bad behavior
37413739
LogPrintf("Warning: not punishing manually connected peer %d!\n", peer_id);
37423740
return false;

0 commit comments

Comments
 (0)