Bitcoin Core  0.20.99
P2P Digital Currency
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
CNode Class Reference

Information about a peer. More...

#include <net.h>

Collaboration diagram for CNode:
[legend]

Classes

struct  TxRelay
 

Public Member Functions

SOCKET hSocket GUARDED_BY (cs_hSocket)
 
uint64_t nSendBytes GUARDED_BY (cs_vSend)
 
std::deque< std::vector< unsigned char > > vSendMsg GUARDED_BY (cs_vSend)
 
std::list< CNetMessage > vProcessMsg GUARDED_BY (cs_vProcessMsg)
 
uint64_t nRecvBytes GUARDED_BY (cs_vRecv)
 
std::string cleanSubVer GUARDED_BY (cs_SubVer)
 cleanSubVer is a sanitized string of the user agent byte array we read from the wire. More...
 
bool HasPermission (NetPermissionFlags permission) const
 
bool IsOutboundOrBlockRelayConn () const
 
bool IsFullOutboundConn () const
 
bool IsManualConn () const
 
bool IsBlockOnlyConn () const
 
bool IsFeelerConn () const
 
bool IsAddrFetchConn () const
 
bool IsInboundConn () const
 
bool RelayAddrsWithConn () const
 
bool ExpectServicesFromConn () const
 
std::chrono::microseconds m_next_addr_send GUARDED_BY (cs_sendProcessing)
 
std::chrono::microseconds m_next_local_addr_send GUARDED_BY (cs_sendProcessing)
 
std::vector< uint256 > vInventoryBlockToSend GUARDED_BY (cs_inventory)
 
std::vector< uint256 > vBlockHashesToAnnounce GUARDED_BY (cs_inventory)
 
 CNode (NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn, ConnectionType conn_type_in)
 
 ~CNode ()
 
 CNode (const CNode &)=delete
 
CNodeoperator= (const CNode &)=delete
 
NodeId GetId () const
 
uint64_t GetLocalNonce () const
 
int GetMyStartingHeight () const
 
int GetRefCount () const
 
bool ReceiveMsgBytes (const char *pch, unsigned int nBytes, bool &complete)
 
void SetCommonVersion (int greatest_common_version)
 
int GetCommonVersion () const
 
CService GetAddrLocal () const
 
void SetAddrLocal (const CService &addrLocalIn)
 May not be called more than once. More...
 
CNodeAddRef ()
 
void Release ()
 
void AddAddressKnown (const CAddress &_addr)
 
void PushAddress (const CAddress &_addr, FastRandomContext &insecure_rand)
 
void AddKnownTx (const uint256 &hash)
 
void PushTxInventory (const uint256 &hash)
 
void CloseSocketDisconnect ()
 
void copyStats (CNodeStats &stats, const std::vector< bool > &m_asmap)
 
ServiceFlags GetLocalServices () const
 
std::string GetAddrName () const
 
void MaybeSetAddrName (const std::string &addrNameIn)
 Sets the addrName only if it was not previously set. More...
 

Public Attributes

std::unique_ptr< TransportDeserializerm_deserializer
 
std::unique_ptr< TransportSerializerm_serializer
 
std::atomic< ServiceFlagsnServices {NODE_NONE}
 
size_t nSendSize {0}
 
size_t nSendOffset {0}
 
RecursiveMutex cs_vSend
 
RecursiveMutex cs_hSocket
 
RecursiveMutex cs_vRecv
 
RecursiveMutex cs_vProcessMsg
 
size_t nProcessQueueSize {0}
 
RecursiveMutex cs_sendProcessing
 
std::deque< CInvvRecvGetData
 
std::atomic< int64_t > nLastSend {0}
 
std::atomic< int64_t > nLastRecv {0}
 
const int64_t nTimeConnected
 
std::atomic< int64_t > nTimeOffset {0}
 
const CAddress addr
 
const CAddress addrBind
 
std::atomic< int > nVersion {0}
 
RecursiveMutex cs_SubVer
 
bool m_prefer_evict {false}
 
bool m_legacyWhitelisted {false}
 
bool fClient {false}
 
bool m_limited_node {false}
 
std::atomic_bool fSuccessfullyConnected {false}
 
std::atomic_bool fDisconnect {false}
 
bool fSentAddr {false}
 
CSemaphoreGrant grantOutbound
 
std::atomic< int > nRefCount {0}
 
const uint64_t nKeyedNetGroup
 
std::atomic_bool fPauseRecv {false}
 
std::atomic_bool fPauseSend {false}
 
uint256 hashContinue
 
std::atomic< int > nStartingHeight {-1}
 
std::vector< CAddressvAddrToSend
 
std::unique_ptr< CRollingBloomFilterm_addr_known {nullptr}
 
bool fGetAddr {false}
 
Mutex cs_inventory
 
std::unique_ptr< TxRelaym_tx_relay
 
std::atomic< int64_t > nLastBlockTime {0}
 UNIX epoch time of the last block received from this peer that we had not yet seen (e.g. More...
 
std::atomic< int64_t > nLastTXTime {0}
 UNIX epoch time of the last transaction received from this peer that we had not yet seen (e.g. More...
 
std::atomic< uint64_t > nPingNonceSent {0}
 
std::atomic< std::chrono::microseconds > m_ping_start {std::chrono::microseconds{0}}
 When the last ping was sent, or 0 if no ping was ever sent. More...
 
std::atomic< int64_t > nPingUsecTime {0}
 
std::atomic< int64_t > nMinPingUsecTime {std::numeric_limits<int64_t>::max()}
 
std::atomic< bool > fPingQueued {false}
 
std::set< uint256orphan_work_set
 

Protected Member Functions

mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY (cs_vRecv)
 

Protected Attributes

mapMsgCmdSize mapSendBytesPerMsgCmd
 

Private Member Functions

std::string addrName GUARDED_BY (cs_addrName)
 
CService addrLocal GUARDED_BY (cs_addrLocal)
 

Private Attributes

const NodeId id
 
const uint64_t nLocalHostNonce
 
const ConnectionType m_conn_type
 
std::atomic< int > m_greatest_common_version {INIT_PROTO_VERSION}
 
const ServiceFlags nLocalServices
 Services offered to this peer. More...
 
const int nMyStartingHeight
 
NetPermissionFlags m_permissionFlags { PF_NONE }
 
std::list< CNetMessagevRecvMsg
 
RecursiveMutex cs_addrName
 
RecursiveMutex cs_addrLocal
 

Friends

class CConnman
 
struct ConnmanTestMsg
 

Detailed Description

Information about a peer.

Definition at line 805 of file net.h.

Constructor & Destructor Documentation

◆ CNode() [1/2]

CNode::CNode ( NodeId  id,
ServiceFlags  nLocalServicesIn,
int  nMyStartingHeightIn,
SOCKET  hSocketIn,
const CAddress addrIn,
uint64_t  nKeyedNetGroupIn,
uint64_t  nLocalHostNonceIn,
const CAddress addrBindIn,
const std::string &  addrNameIn,
ConnectionType  conn_type_in 
)

Definition at line 2796 of file net.cpp.

Here is the call graph for this function:

◆ ~CNode()

CNode::~CNode ( )

Definition at line 2835 of file net.cpp.

Here is the call graph for this function:

◆ CNode() [2/2]

CNode::CNode ( const CNode )
delete

Member Function Documentation

◆ AddAddressKnown()

void CNode::AddAddressKnown ( const CAddress _addr)
inline

Definition at line 1096 of file net.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddKnownTx()

void CNode::AddKnownTx ( const uint256 hash)
inline

Definition at line 1118 of file net.h.

Here is the caller graph for this function:

◆ AddRef()

CNode* CNode::AddRef ( )
inline

Definition at line 1083 of file net.h.

Here is the caller graph for this function:

◆ CloseSocketDisconnect()

void CNode::CloseSocketDisconnect ( )

Definition at line 474 of file net.cpp.

Here is the call graph for this function:

◆ copyStats()

void CNode::copyStats ( CNodeStats stats,
const std::vector< bool > &  m_asmap 
)

Definition at line 519 of file net.cpp.

Here is the call graph for this function:

◆ ExpectServicesFromConn()

bool CNode::ExpectServicesFromConn ( ) const
inline

Definition at line 914 of file net.h.

Here is the caller graph for this function:

◆ GetAddrLocal()

CService CNode::GetAddrLocal ( ) const

Definition at line 503 of file net.cpp.

Here is the caller graph for this function:

◆ GetAddrName()

std::string CNode::GetAddrName ( ) const

Definition at line 491 of file net.cpp.

Here is the caller graph for this function:

◆ GetCommonVersion()

int CNode::GetCommonVersion ( ) const
inline

Definition at line 1074 of file net.h.

Here is the caller graph for this function:

◆ GetId()

NodeId CNode::GetId ( ) const
inline

Definition at line 1050 of file net.h.

Here is the caller graph for this function:

◆ GetLocalNonce()

uint64_t CNode::GetLocalNonce ( ) const
inline

Definition at line 1054 of file net.h.

◆ GetLocalServices()

ServiceFlags CNode::GetLocalServices ( ) const
inline

Definition at line 1139 of file net.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMyStartingHeight()

int CNode::GetMyStartingHeight ( ) const
inline

Definition at line 1058 of file net.h.

◆ GetRefCount()

int CNode::GetRefCount ( ) const
inline

Definition at line 1062 of file net.h.

◆ GUARDED_BY() [1/13]

SOCKET hSocket CNode::GUARDED_BY ( cs_hSocket  )

◆ GUARDED_BY() [2/13]

uint64_t nSendBytes CNode::GUARDED_BY ( cs_vSend  )
inline

Definition at line 819 of file net.h.

Here is the call graph for this function:

◆ GUARDED_BY() [3/13]

std::deque<std::vector<unsigned char> > vSendMsg CNode::GUARDED_BY ( cs_vSend  )

◆ GUARDED_BY() [4/13]

std::list<CNetMessage> vProcessMsg CNode::GUARDED_BY ( cs_vProcessMsg  )

◆ GUARDED_BY() [5/13]

uint64_t nRecvBytes CNode::GUARDED_BY ( cs_vRecv  )
inline

Definition at line 832 of file net.h.

◆ GUARDED_BY() [6/13]

std::string cleanSubVer CNode::GUARDED_BY ( cs_SubVer  )
inline

cleanSubVer is a sanitized string of the user agent byte array we read from the wire.

This cleaned string can safely be logged or displayed.

Definition at line 848 of file net.h.

◆ GUARDED_BY() [7/13]

mapMsgCmdSize mapRecvBytesPerMsgCmd CNode::GUARDED_BY ( cs_vRecv  )
protected

◆ GUARDED_BY() [8/13]

std::chrono::microseconds m_next_addr_send CNode::GUARDED_BY ( cs_sendProcessing  )
inline

Definition at line 941 of file net.h.

◆ GUARDED_BY() [9/13]

std::chrono::microseconds m_next_local_addr_send CNode::GUARDED_BY ( cs_sendProcessing  )
inline

Definition at line 942 of file net.h.

Here is the call graph for this function:

◆ GUARDED_BY() [10/13]

std::vector<uint256> vInventoryBlockToSend CNode::GUARDED_BY ( cs_inventory  )

◆ GUARDED_BY() [11/13]

std::vector<uint256> vBlockHashesToAnnounce CNode::GUARDED_BY ( cs_inventory  )

◆ GUARDED_BY() [12/13]

std::string addrName CNode::GUARDED_BY ( cs_addrName  )
private

◆ GUARDED_BY() [13/13]

CService addrLocal CNode::GUARDED_BY ( cs_addrLocal  )
private

◆ HasPermission()

bool CNode::HasPermission ( NetPermissionFlags  permission) const
inline

Definition at line 850 of file net.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsAddrFetchConn()

bool CNode::IsAddrFetchConn ( ) const
inline

Definition at line 900 of file net.h.

Here is the caller graph for this function:

◆ IsBlockOnlyConn()

bool CNode::IsBlockOnlyConn ( ) const
inline

Definition at line 892 of file net.h.

Here is the caller graph for this function:

◆ IsFeelerConn()

bool CNode::IsFeelerConn ( ) const
inline

Definition at line 896 of file net.h.

Here is the caller graph for this function:

◆ IsFullOutboundConn()

bool CNode::IsFullOutboundConn ( ) const
inline

Definition at line 884 of file net.h.

Here is the caller graph for this function:

◆ IsInboundConn()

bool CNode::IsInboundConn ( ) const
inline

Definition at line 904 of file net.h.

Here is the caller graph for this function:

◆ IsManualConn()

bool CNode::IsManualConn ( ) const
inline

Definition at line 888 of file net.h.

Here is the caller graph for this function:

◆ IsOutboundOrBlockRelayConn()

bool CNode::IsOutboundOrBlockRelayConn ( ) const
inline

Definition at line 869 of file net.h.

Here is the caller graph for this function:

◆ MaybeSetAddrName()

void CNode::MaybeSetAddrName ( const std::string &  addrNameIn)

Sets the addrName only if it was not previously set.

Definition at line 496 of file net.cpp.

Here is the caller graph for this function:

◆ operator=()

CNode& CNode::operator= ( const CNode )
delete

◆ PushAddress()

void CNode::PushAddress ( const CAddress _addr,
FastRandomContext insecure_rand 
)
inline

Definition at line 1102 of file net.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PushTxInventory()

void CNode::PushTxInventory ( const uint256 hash)
inline

Definition at line 1126 of file net.h.

Here is the caller graph for this function:

◆ ReceiveMsgBytes()

bool CNode::ReceiveMsgBytes ( const char *  pch,
unsigned int  nBytes,
bool &  complete 
)

Definition at line 588 of file net.cpp.

Here is the call graph for this function:

◆ RelayAddrsWithConn()

bool CNode::RelayAddrsWithConn ( ) const
inline

Definition at line 909 of file net.h.

Here is the caller graph for this function:

◆ Release()

void CNode::Release ( )
inline

Definition at line 1089 of file net.h.

◆ SetAddrLocal()

void CNode::SetAddrLocal ( const CService addrLocalIn)

May not be called more than once.

Definition at line 508 of file net.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCommonVersion()

void CNode::SetCommonVersion ( int  greatest_common_version)
inline

Definition at line 1070 of file net.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ CConnman

friend class CConnman
friend

Definition at line 807 of file net.h.

◆ ConnmanTestMsg

friend struct ConnmanTestMsg
friend

Definition at line 808 of file net.h.

Member Data Documentation

◆ addr

const CAddress CNode::addr

Definition at line 839 of file net.h.

◆ addrBind

const CAddress CNode::addrBind

Definition at line 841 of file net.h.

◆ cs_addrLocal

RecursiveMutex CNode::cs_addrLocal
mutableprivate

Definition at line 1047 of file net.h.

◆ cs_addrName

RecursiveMutex CNode::cs_addrName
mutableprivate

Definition at line 1042 of file net.h.

◆ cs_hSocket

RecursiveMutex CNode::cs_hSocket

Definition at line 822 of file net.h.

◆ cs_inventory

Mutex CNode::cs_inventory

Definition at line 948 of file net.h.

◆ cs_sendProcessing

RecursiveMutex CNode::cs_sendProcessing

Definition at line 829 of file net.h.

◆ cs_SubVer

RecursiveMutex CNode::cs_SubVer

Definition at line 843 of file net.h.

◆ cs_vProcessMsg

RecursiveMutex CNode::cs_vProcessMsg

Definition at line 825 of file net.h.

◆ cs_vRecv

RecursiveMutex CNode::cs_vRecv

Definition at line 823 of file net.h.

◆ cs_vSend

RecursiveMutex CNode::cs_vSend

Definition at line 821 of file net.h.

◆ fClient

bool CNode::fClient {false}

Definition at line 855 of file net.h.

◆ fDisconnect

std::atomic_bool CNode::fDisconnect {false}

Definition at line 860 of file net.h.

◆ fGetAddr

bool CNode::fGetAddr {false}

Definition at line 940 of file net.h.

◆ fPauseRecv

std::atomic_bool CNode::fPauseRecv {false}

Definition at line 866 of file net.h.

◆ fPauseSend

std::atomic_bool CNode::fPauseSend {false}

Definition at line 867 of file net.h.

◆ fPingQueued

std::atomic<bool> CNode::fPingQueued {false}

Definition at line 1006 of file net.h.

◆ fSentAddr

bool CNode::fSentAddr {false}

Definition at line 861 of file net.h.

◆ fSuccessfullyConnected

std::atomic_bool CNode::fSuccessfullyConnected {false}

Definition at line 857 of file net.h.

◆ grantOutbound

CSemaphoreGrant CNode::grantOutbound

Definition at line 862 of file net.h.

◆ hashContinue

uint256 CNode::hashContinue

Definition at line 934 of file net.h.

◆ id

const NodeId CNode::id
private

Definition at line 1016 of file net.h.

◆ m_addr_known

std::unique_ptr<CRollingBloomFilter> CNode::m_addr_known {nullptr}

Definition at line 939 of file net.h.

◆ m_conn_type

const ConnectionType CNode::m_conn_type
private

Definition at line 1018 of file net.h.

◆ m_deserializer

std::unique_ptr<TransportDeserializer> CNode::m_deserializer

Definition at line 811 of file net.h.

◆ m_greatest_common_version

std::atomic<int> CNode::m_greatest_common_version {INIT_PROTO_VERSION}
private

Definition at line 1019 of file net.h.

◆ m_legacyWhitelisted

bool CNode::m_legacyWhitelisted {false}

Definition at line 854 of file net.h.

◆ m_limited_node

bool CNode::m_limited_node {false}

Definition at line 856 of file net.h.

◆ m_permissionFlags

NetPermissionFlags CNode::m_permissionFlags { PF_NONE }
private

Definition at line 1039 of file net.h.

◆ m_ping_start

std::atomic<std::chrono::microseconds> CNode::m_ping_start {std::chrono::microseconds{0}}

When the last ping was sent, or 0 if no ping was ever sent.

Definition at line 1000 of file net.h.

◆ m_prefer_evict

bool CNode::m_prefer_evict {false}

Definition at line 849 of file net.h.

◆ m_serializer

std::unique_ptr<TransportSerializer> CNode::m_serializer

Definition at line 812 of file net.h.

◆ m_tx_relay

std::unique_ptr<TxRelay> CNode::m_tx_relay

Definition at line 978 of file net.h.

◆ mapSendBytesPerMsgCmd

mapMsgCmdSize CNode::mapSendBytesPerMsgCmd
protected

Definition at line 930 of file net.h.

◆ nKeyedNetGroup

const uint64_t CNode::nKeyedNetGroup

Definition at line 865 of file net.h.

◆ nLastBlockTime

std::atomic<int64_t> CNode::nLastBlockTime {0}

UNIX epoch time of the last block received from this peer that we had not yet seen (e.g.

not already received from another peer), that passed preliminary validity checks and was saved to disk, even if we don't connect the block or it eventually fails connection. Used as an inbound peer eviction criterium in CConnman::AttemptToEvictConnection.

Definition at line 988 of file net.h.

◆ nLastRecv

std::atomic<int64_t> CNode::nLastRecv {0}

Definition at line 835 of file net.h.

◆ nLastSend

std::atomic<int64_t> CNode::nLastSend {0}

Definition at line 834 of file net.h.

◆ nLastTXTime

std::atomic<int64_t> CNode::nLastTXTime {0}

UNIX epoch time of the last transaction received from this peer that we had not yet seen (e.g.

not already received from another peer) and that was accepted into our mempool. Used as an inbound peer eviction criterium in CConnman::AttemptToEvictConnection.

Definition at line 994 of file net.h.

◆ nLocalHostNonce

const uint64_t CNode::nLocalHostNonce
private

Definition at line 1017 of file net.h.

◆ nLocalServices

const ServiceFlags CNode::nLocalServices
private

Services offered to this peer.

This is supplied by the parent CConnman during peer connection (CConnman::ConnectNode()) from its attribute of the same name.

This is const because there is no protocol defined for renegotiating services initially offered to a peer. The set of local services we offer should not change after initialization.

An interesting example of this is NODE_NETWORK and initial block download: a node which starts up from scratch doesn't have any blocks to serve, but still advertises NODE_NETWORK because it will eventually fulfill this role after IBD completes. P2P code is written in such a way that it can gracefully handle peers who don't make good on their service advertisements.

Definition at line 1036 of file net.h.

◆ nMinPingUsecTime

std::atomic<int64_t> CNode::nMinPingUsecTime {std::numeric_limits<int64_t>::max()}

Definition at line 1004 of file net.h.

◆ nMyStartingHeight

const int CNode::nMyStartingHeight
private

Definition at line 1038 of file net.h.

◆ nPingNonceSent

std::atomic<uint64_t> CNode::nPingNonceSent {0}

Definition at line 998 of file net.h.

◆ nPingUsecTime

std::atomic<int64_t> CNode::nPingUsecTime {0}

Definition at line 1002 of file net.h.

◆ nProcessQueueSize

size_t CNode::nProcessQueueSize {0}

Definition at line 827 of file net.h.

◆ nRefCount

std::atomic<int> CNode::nRefCount {0}

Definition at line 863 of file net.h.

◆ nSendOffset

size_t CNode::nSendOffset {0}

Definition at line 818 of file net.h.

◆ nSendSize

size_t CNode::nSendSize {0}

Definition at line 817 of file net.h.

◆ nServices

std::atomic<ServiceFlags> CNode::nServices {NODE_NONE}

Definition at line 815 of file net.h.

◆ nStartingHeight

std::atomic<int> CNode::nStartingHeight {-1}

Definition at line 935 of file net.h.

◆ nTimeConnected

const int64_t CNode::nTimeConnected

Definition at line 836 of file net.h.

◆ nTimeOffset

std::atomic<int64_t> CNode::nTimeOffset {0}

Definition at line 837 of file net.h.

◆ nVersion

std::atomic<int> CNode::nVersion {0}

Definition at line 842 of file net.h.

◆ orphan_work_set

std::set<uint256> CNode::orphan_work_set

Definition at line 1008 of file net.h.

◆ vAddrToSend

std::vector<CAddress> CNode::vAddrToSend

Definition at line 938 of file net.h.

◆ vRecvGetData

std::deque<CInv> CNode::vRecvGetData

Definition at line 831 of file net.h.

◆ vRecvMsg

std::list<CNetMessage> CNode::vRecvMsg
private

Definition at line 1040 of file net.h.


The documentation for this class was generated from the following files: