Skip to content

Commit 5cce607

Browse files
author
MarcoFalke
committed
Merge #20373: refactor, net: Increase CNode data member encapsulation
3642b2e refactor, net: Increase CNode data member encapsulation (Hennadii Stepanov) acebb79 refactor, move-only: Relocate CNode private members (Hennadii Stepanov) Pull request description: All protected `CNode` data members could be private. ACKs for top commit: jnewbery: utACK 3642b2e MarcoFalke: review ACK 3642b2e 🏛 Tree-SHA512: 8435e3c43c3b7a3107d58cb809b8b5e1a1c0068677e249bdf0fc6ed24140ac4fc4efe2a280a1ee86df180d738c0c9e10772308690607954db6713000cf6e728d
2 parents 675af2a + 3642b2e commit 5cce607

File tree

1 file changed

+38
-45
lines changed

1 file changed

+38
-45
lines changed

src/net.h

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,6 @@ class CNode
528528
*/
529529
Network ConnectedThroughNetwork() const;
530530

531-
protected:
532-
mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend);
533-
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
534-
535-
public:
536531
// We selected peer as (compact blocks) high-bandwidth peer (BIP152)
537532
std::atomic<bool> m_bip152_highbandwidth_to{false};
538533
// Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
@@ -604,43 +599,6 @@ class CNode
604599
CNode(const CNode&) = delete;
605600
CNode& operator=(const CNode&) = delete;
606601

607-
private:
608-
const NodeId id;
609-
const uint64_t nLocalHostNonce;
610-
const ConnectionType m_conn_type;
611-
std::atomic<int> m_greatest_common_version{INIT_PROTO_VERSION};
612-
613-
//! Services offered to this peer.
614-
//!
615-
//! This is supplied by the parent CConnman during peer connection
616-
//! (CConnman::ConnectNode()) from its attribute of the same name.
617-
//!
618-
//! This is const because there is no protocol defined for renegotiating
619-
//! services initially offered to a peer. The set of local services we
620-
//! offer should not change after initialization.
621-
//!
622-
//! An interesting example of this is NODE_NETWORK and initial block
623-
//! download: a node which starts up from scratch doesn't have any blocks
624-
//! to serve, but still advertises NODE_NETWORK because it will eventually
625-
//! fulfill this role after IBD completes. P2P code is written in such a
626-
//! way that it can gracefully handle peers who don't make good on their
627-
//! service advertisements.
628-
const ServiceFlags nLocalServices;
629-
630-
std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
631-
632-
mutable RecursiveMutex cs_addrName;
633-
std::string addrName GUARDED_BY(cs_addrName);
634-
635-
// Our address, as reported by the peer
636-
CService addrLocal GUARDED_BY(cs_addrLocal);
637-
mutable RecursiveMutex cs_addrLocal;
638-
639-
//! Whether this peer is an inbound onion, e.g. connected via our Tor onion service.
640-
const bool m_inbound_onion{false};
641-
642-
public:
643-
644602
NodeId GetId() const {
645603
return id;
646604
}
@@ -691,8 +649,6 @@ class CNode
691649
nRefCount--;
692650
}
693651

694-
695-
696652
void AddAddressKnown(const CAddress& _addr)
697653
{
698654
assert(m_addr_known);
@@ -724,7 +680,6 @@ class CNode
724680
}
725681
}
726682

727-
728683
void AddKnownTx(const uint256& hash)
729684
{
730685
if (m_tx_relay != nullptr) {
@@ -759,6 +714,44 @@ class CNode
759714

760715
/** Whether this peer is an inbound onion, e.g. connected via our Tor onion service. */
761716
bool IsInboundOnion() const { return m_inbound_onion; }
717+
718+
private:
719+
const NodeId id;
720+
const uint64_t nLocalHostNonce;
721+
const ConnectionType m_conn_type;
722+
std::atomic<int> m_greatest_common_version{INIT_PROTO_VERSION};
723+
724+
//! Services offered to this peer.
725+
//!
726+
//! This is supplied by the parent CConnman during peer connection
727+
//! (CConnman::ConnectNode()) from its attribute of the same name.
728+
//!
729+
//! This is const because there is no protocol defined for renegotiating
730+
//! services initially offered to a peer. The set of local services we
731+
//! offer should not change after initialization.
732+
//!
733+
//! An interesting example of this is NODE_NETWORK and initial block
734+
//! download: a node which starts up from scratch doesn't have any blocks
735+
//! to serve, but still advertises NODE_NETWORK because it will eventually
736+
//! fulfill this role after IBD completes. P2P code is written in such a
737+
//! way that it can gracefully handle peers who don't make good on their
738+
//! service advertisements.
739+
const ServiceFlags nLocalServices;
740+
741+
std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
742+
743+
mutable RecursiveMutex cs_addrName;
744+
std::string addrName GUARDED_BY(cs_addrName);
745+
746+
// Our address, as reported by the peer
747+
CService addrLocal GUARDED_BY(cs_addrLocal);
748+
mutable RecursiveMutex cs_addrLocal;
749+
750+
//! Whether this peer is an inbound onion, e.g. connected via our Tor onion service.
751+
const bool m_inbound_onion{false};
752+
753+
mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend);
754+
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
762755
};
763756

764757
/**

0 commit comments

Comments
 (0)