Bitcoin Core  0.21.1
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules
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
 
Network ConnectedThroughNetwork () const
 Get network the peer connected through. More...
 
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, bool inbound_onion=false)
 
 ~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...
 
std::string ConnectionTypeAsString () const
 

Public Attributes

std::unique_ptr
< TransportDeserializer
m_deserializer
 
std::unique_ptr
< TransportSerializer
m_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::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 m_wants_addrv2 {false}
 Whether the peer has signaled support for receiving ADDRv2 (BIP155) messages, implying a preference to receive ADDRv2 instead of ADDR ones. More...
 
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
< CRollingBloomFilter
m_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}
 

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
 
const bool m_inbound_onion {false}
 Whether this peer connected via our Tor onion service. More...
 

Friends

class CConnman
 
struct ConnmanTestMsg
 

Detailed Description

Information about a peer.

Definition at line 840 of file net.h.

Constructor & Destructor Documentation

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,
bool  inbound_onion = false 
)
CNode::~CNode ( )
CNode::CNode ( const CNode )
delete

Member Function Documentation

void CNode::AddAddressKnown ( const CAddress _addr)
inline

Definition at line 1149 of file net.h.

Here is the call graph for this function:

void CNode::AddKnownTx ( const uint256 hash)
inline

Definition at line 1176 of file net.h.

CNode* CNode::AddRef ( )
inline

Definition at line 1136 of file net.h.

void CNode::CloseSocketDisconnect ( )
Network CNode::ConnectedThroughNetwork ( ) const

Get network the peer connected through.

Returns Network::NET_ONION for inbound onion connections, and CNetAddr::GetNetClass() otherwise. The latter cannot be used directly because it doesn't detect the former, and it's not the responsibility of the CNetAddr class to know the actual network a peer is connected through.

Returns
network the peer connected through.
std::string CNode::ConnectionTypeAsString ( ) const
void CNode::copyStats ( CNodeStats stats,
const std::vector< bool > &  m_asmap 
)
bool CNode::ExpectServicesFromConn ( ) const
inline

Definition at line 953 of file net.h.

CService CNode::GetAddrLocal ( ) const
std::string CNode::GetAddrName ( ) const
int CNode::GetCommonVersion ( ) const
inline

Definition at line 1127 of file net.h.

NodeId CNode::GetId ( ) const
inline

Definition at line 1103 of file net.h.

uint64_t CNode::GetLocalNonce ( ) const
inline

Definition at line 1107 of file net.h.

ServiceFlags CNode::GetLocalServices ( ) const
inline

Definition at line 1197 of file net.h.

int CNode::GetMyStartingHeight ( ) const
inline

Definition at line 1111 of file net.h.

int CNode::GetRefCount ( ) const
inline

Definition at line 1115 of file net.h.

SOCKET hSocket CNode::GUARDED_BY ( cs_hSocket  )
uint64_t nSendBytes CNode::GUARDED_BY ( cs_vSend  )
inline

Definition at line 854 of file net.h.

std::deque<std::vector<unsigned char> > vSendMsg CNode::GUARDED_BY ( cs_vSend  )
std::list<CNetMessage> vProcessMsg CNode::GUARDED_BY ( cs_vProcessMsg  )
uint64_t nRecvBytes CNode::GUARDED_BY ( cs_vRecv  )
inline

Definition at line 866 of file net.h.

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 882 of file net.h.

mapMsgCmdSize mapRecvBytesPerMsgCmd CNode::GUARDED_BY ( cs_vRecv  )
protected
std::chrono::microseconds m_next_addr_send CNode::GUARDED_BY ( cs_sendProcessing  )
inline

Definition at line 992 of file net.h.

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

Definition at line 993 of file net.h.

std::vector<uint256> vInventoryBlockToSend CNode::GUARDED_BY ( cs_inventory  )
std::vector<uint256> vBlockHashesToAnnounce CNode::GUARDED_BY ( cs_inventory  )
std::string addrName CNode::GUARDED_BY ( cs_addrName  )
private
CService addrLocal CNode::GUARDED_BY ( cs_addrLocal  )
private
bool CNode::HasPermission ( NetPermissionFlags  permission) const
inline

Definition at line 884 of file net.h.

Here is the call graph for this function:

bool CNode::IsAddrFetchConn ( ) const
inline

Definition at line 939 of file net.h.

bool CNode::IsBlockOnlyConn ( ) const
inline

Definition at line 931 of file net.h.

bool CNode::IsFeelerConn ( ) const
inline

Definition at line 935 of file net.h.

bool CNode::IsFullOutboundConn ( ) const
inline

Definition at line 923 of file net.h.

bool CNode::IsInboundConn ( ) const
inline

Definition at line 943 of file net.h.

bool CNode::IsManualConn ( ) const
inline

Definition at line 927 of file net.h.

bool CNode::IsOutboundOrBlockRelayConn ( ) const
inline

Definition at line 908 of file net.h.

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

Sets the addrName only if it was not previously set.

CNode& CNode::operator= ( const CNode )
delete
void CNode::PushAddress ( const CAddress _addr,
FastRandomContext insecure_rand 
)
inline

Definition at line 1155 of file net.h.

Here is the call graph for this function:

void CNode::PushTxInventory ( const uint256 hash)
inline

Definition at line 1184 of file net.h.

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

Definition at line 948 of file net.h.

void CNode::Release ( )
inline

Definition at line 1142 of file net.h.

void CNode::SetAddrLocal ( const CService addrLocalIn)

May not be called more than once.

void CNode::SetCommonVersion ( int  greatest_common_version)
inline

Definition at line 1123 of file net.h.

Friends And Related Function Documentation

friend class CConnman
friend

Definition at line 842 of file net.h.

friend struct ConnmanTestMsg
friend

Definition at line 843 of file net.h.

Member Data Documentation

const CAddress CNode::addr

Definition at line 873 of file net.h.

const CAddress CNode::addrBind

Definition at line 875 of file net.h.

RecursiveMutex CNode::cs_addrLocal
mutableprivate

Definition at line 1096 of file net.h.

RecursiveMutex CNode::cs_addrName
mutableprivate

Definition at line 1091 of file net.h.

RecursiveMutex CNode::cs_hSocket

Definition at line 857 of file net.h.

Mutex CNode::cs_inventory

Definition at line 999 of file net.h.

RecursiveMutex CNode::cs_sendProcessing

Definition at line 864 of file net.h.

RecursiveMutex CNode::cs_SubVer

Definition at line 877 of file net.h.

RecursiveMutex CNode::cs_vProcessMsg

Definition at line 860 of file net.h.

RecursiveMutex CNode::cs_vRecv

Definition at line 858 of file net.h.

RecursiveMutex CNode::cs_vSend

Definition at line 856 of file net.h.

bool CNode::fClient {false}

Definition at line 889 of file net.h.

std::atomic_bool CNode::fDisconnect {false}

Definition at line 899 of file net.h.

bool CNode::fGetAddr {false}

Definition at line 991 of file net.h.

std::atomic_bool CNode::fPauseRecv {false}

Definition at line 905 of file net.h.

std::atomic_bool CNode::fPauseSend {false}

Definition at line 906 of file net.h.

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

Definition at line 1057 of file net.h.

bool CNode::fSentAddr {false}

Definition at line 900 of file net.h.

std::atomic_bool CNode::fSuccessfullyConnected {false}

Definition at line 896 of file net.h.

CSemaphoreGrant CNode::grantOutbound

Definition at line 901 of file net.h.

uint256 CNode::hashContinue

Definition at line 985 of file net.h.

const NodeId CNode::id
private

Definition at line 1065 of file net.h.

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

Definition at line 990 of file net.h.

const ConnectionType CNode::m_conn_type
private

Definition at line 1067 of file net.h.

std::unique_ptr<TransportDeserializer> CNode::m_deserializer

Definition at line 846 of file net.h.

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

Definition at line 1068 of file net.h.

const bool CNode::m_inbound_onion {false}
private

Whether this peer connected via our Tor onion service.

Definition at line 1099 of file net.h.

bool CNode::m_legacyWhitelisted {false}

Definition at line 888 of file net.h.

bool CNode::m_limited_node {false}

Definition at line 890 of file net.h.

NetPermissionFlags CNode::m_permissionFlags { PF_NONE }
private

Definition at line 1088 of file net.h.

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 1051 of file net.h.

bool CNode::m_prefer_evict {false}

Definition at line 883 of file net.h.

std::unique_ptr<TransportSerializer> CNode::m_serializer

Definition at line 847 of file net.h.

std::unique_ptr<TxRelay> CNode::m_tx_relay

Definition at line 1029 of file net.h.

std::atomic_bool CNode::m_wants_addrv2 {false}

Whether the peer has signaled support for receiving ADDRv2 (BIP155) messages, implying a preference to receive ADDRv2 instead of ADDR ones.

Definition at line 895 of file net.h.

mapMsgCmdSize CNode::mapSendBytesPerMsgCmd
protected

Definition at line 981 of file net.h.

const uint64_t CNode::nKeyedNetGroup

Definition at line 904 of file net.h.

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 1039 of file net.h.

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

Definition at line 869 of file net.h.

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

Definition at line 868 of file net.h.

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 1045 of file net.h.

const uint64_t CNode::nLocalHostNonce
private

Definition at line 1066 of file net.h.

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 1085 of file net.h.

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

Definition at line 1055 of file net.h.

const int CNode::nMyStartingHeight
private

Definition at line 1087 of file net.h.

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

Definition at line 1049 of file net.h.

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

Definition at line 1053 of file net.h.

size_t CNode::nProcessQueueSize {0}

Definition at line 862 of file net.h.

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

Definition at line 902 of file net.h.

size_t CNode::nSendOffset {0}

Definition at line 853 of file net.h.

size_t CNode::nSendSize {0}

Definition at line 852 of file net.h.

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

Definition at line 850 of file net.h.

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

Definition at line 986 of file net.h.

const int64_t CNode::nTimeConnected

Definition at line 870 of file net.h.

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

Definition at line 871 of file net.h.

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

Definition at line 876 of file net.h.

std::vector<CAddress> CNode::vAddrToSend

Definition at line 989 of file net.h.

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

Definition at line 1089 of file net.h.


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