Bitcoin Core  0.18.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
 
int64_t nNextAddrSend GUARDED_BY (cs_sendProcessing)
 
int64_t nNextLocalAddrSend GUARDED_BY (cs_sendProcessing)
 
bool IsAddrRelayPeer () const
 
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="", bool fInboundIn=false, bool block_relay_only=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 SetRecvVersion (int nVersionIn)
 
int GetRecvVersion () const
 
void SetSendVersion (int nVersionIn)
 
int GetSendVersion () 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 AddInventoryKnown (const CInv &inv)
 
void PushInventory (const CInv &inv)
 
void PushBlockHash (const uint256 &hash)
 
void CloseSocketDisconnect ()
 
void copyStats (CNodeStats &stats)
 
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::atomic< ServiceFlagsnServices {NODE_NONE}
 
size_t nSendSize {0}
 
size_t nSendOffset {0}
 
CCriticalSection cs_vSend
 
CCriticalSection cs_hSocket
 
CCriticalSection cs_vRecv
 
CCriticalSection cs_vProcessMsg
 
size_t nProcessQueueSize {0}
 
CCriticalSection cs_sendProcessing
 
std::deque< CInvvRecvGetData
 
std::atomic< int > nRecvVersion {INIT_PROTO_VERSION}
 
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 fFeeler {false}
 
bool fOneShot {false}
 
bool m_manual_connection {false}
 
bool fClient {false}
 
bool m_limited_node {false}
 
const bool fInbound
 
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
 
CRollingBloomFilter addrKnown
 
bool fGetAddr {false}
 
const bool m_addr_relay_peer
 
CCriticalSection cs_inventory
 
std::unique_ptr< TxRelaym_tx_relay
 
std::atomic< int64_t > nLastBlockTime {0}
 
std::atomic< int64_t > nLastTXTime {0}
 
std::atomic< uint64_t > nPingNonceSent {0}
 
std::atomic< int64_t > nPingUsecStart {0}
 
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 ServiceFlags nLocalServices
 Services offered to this peer. More...
 
const int nMyStartingHeight
 
int nSendVersion {0}
 
NetPermissionFlags m_permissionFlags { PF_NONE }
 
std::list< CNetMessagevRecvMsg
 
CCriticalSection cs_addrName
 
CCriticalSection cs_addrLocal
 

Friends

class CConnman
 

Detailed Description

Information about a peer.

Definition at line 658 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 = "",
bool  fInboundIn = false,
bool  block_relay_only = false 
)

Definition at line 2642 of file net.cpp.

Here is the call graph for this function:

◆ ~CNode()

CNode::~CNode ( )

Definition at line 2676 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 885 of file net.h.

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

◆ AddInventoryKnown()

void CNode::AddInventoryKnown ( const CInv inv)
inline

Definition at line 905 of file net.h.

Here is the caller graph for this function:

◆ AddRef()

CNode* CNode::AddRef ( )
inline

Definition at line 872 of file net.h.

Here is the caller graph for this function:

◆ CloseSocketDisconnect()

void CNode::CloseSocketDisconnect ( )

Definition at line 451 of file net.cpp.

Here is the call graph for this function:

◆ copyStats()

void CNode::copyStats ( CNodeStats stats)

Definition at line 496 of file net.cpp.

Here is the call graph for this function:

◆ GetAddrLocal()

CService CNode::GetAddrLocal ( ) const

Definition at line 480 of file net.cpp.

Here is the caller graph for this function:

◆ GetAddrName()

std::string CNode::GetAddrName ( ) const

Definition at line 468 of file net.cpp.

Here is the caller graph for this function:

◆ GetId()

NodeId CNode::GetId ( ) const
inline

Definition at line 837 of file net.h.

Here is the caller graph for this function:

◆ GetLocalNonce()

uint64_t CNode::GetLocalNonce ( ) const
inline

Definition at line 841 of file net.h.

◆ GetLocalServices()

ServiceFlags CNode::GetLocalServices ( ) const
inline

Definition at line 936 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 845 of file net.h.

◆ GetRecvVersion()

int CNode::GetRecvVersion ( ) const
inline

Definition at line 861 of file net.h.

Here is the caller graph for this function:

◆ GetRefCount()

int CNode::GetRefCount ( ) const
inline

Definition at line 849 of file net.h.

◆ GetSendVersion()

int CNode::GetSendVersion ( ) const

Definition at line 627 of file net.cpp.

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

◆ 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 667 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 680 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 697 of file net.h.

◆ GUARDED_BY() [7/13]

mapMsgCmdSize mapRecvBytesPerMsgCmd CNode::GUARDED_BY ( cs_vRecv  )
protected

◆ GUARDED_BY() [8/13]

int64_t nNextAddrSend CNode::GUARDED_BY ( cs_sendProcessing  )
inline

Definition at line 734 of file net.h.

◆ GUARDED_BY() [9/13]

int64_t nNextLocalAddrSend CNode::GUARDED_BY ( cs_sendProcessing  )
inline

Definition at line 735 of file net.h.

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

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

◆ IsAddrRelayPeer()

bool CNode::IsAddrRelayPeer ( ) const
inline

Definition at line 738 of file net.h.

Here is the call graph for this function:
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 473 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 890 of file net.h.

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

◆ PushBlockHash()

void CNode::PushBlockHash ( const uint256 hash)
inline

Definition at line 926 of file net.h.

◆ PushInventory()

void CNode::PushInventory ( const CInv inv)
inline

Definition at line 913 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 562 of file net.cpp.

Here is the call graph for this function:

◆ Release()

void CNode::Release ( )
inline

Definition at line 878 of file net.h.

◆ SetAddrLocal()

void CNode::SetAddrLocal ( const CService addrLocalIn)

May not be called more than once.

Definition at line 485 of file net.cpp.

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

◆ SetRecvVersion()

void CNode::SetRecvVersion ( int  nVersionIn)
inline

Definition at line 857 of file net.h.

Here is the caller graph for this function:

◆ SetSendVersion()

void CNode::SetSendVersion ( int  nVersionIn)

Definition at line 613 of file net.cpp.

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

Friends And Related Function Documentation

◆ CConnman

friend class CConnman
friend

Definition at line 660 of file net.h.

Member Data Documentation

◆ addr

const CAddress CNode::addr

Definition at line 688 of file net.h.

◆ addrBind

const CAddress CNode::addrBind

Definition at line 690 of file net.h.

◆ addrKnown

CRollingBloomFilter CNode::addrKnown

Definition at line 732 of file net.h.

◆ cs_addrLocal

CCriticalSection CNode::cs_addrLocal
mutableprivate

Definition at line 834 of file net.h.

◆ cs_addrName

CCriticalSection CNode::cs_addrName
mutableprivate

Definition at line 829 of file net.h.

◆ cs_hSocket

CCriticalSection CNode::cs_hSocket

Definition at line 670 of file net.h.

◆ cs_inventory

CCriticalSection CNode::cs_inventory

Definition at line 744 of file net.h.

◆ cs_sendProcessing

CCriticalSection CNode::cs_sendProcessing

Definition at line 677 of file net.h.

◆ cs_SubVer

RecursiveMutex CNode::cs_SubVer

Definition at line 692 of file net.h.

◆ cs_vProcessMsg

CCriticalSection CNode::cs_vProcessMsg

Definition at line 673 of file net.h.

◆ cs_vRecv

CCriticalSection CNode::cs_vRecv

Definition at line 671 of file net.h.

◆ cs_vSend

CCriticalSection CNode::cs_vSend

Definition at line 669 of file net.h.

◆ fClient

bool CNode::fClient {false}

Definition at line 707 of file net.h.

◆ fDisconnect

std::atomic_bool CNode::fDisconnect {false}

Definition at line 713 of file net.h.

◆ fFeeler

bool CNode::fFeeler {false}

Definition at line 704 of file net.h.

◆ fGetAddr

bool CNode::fGetAddr {false}

Definition at line 733 of file net.h.

◆ fInbound

const bool CNode::fInbound

Definition at line 709 of file net.h.

◆ fOneShot

bool CNode::fOneShot {false}

Definition at line 705 of file net.h.

◆ fPauseRecv

std::atomic_bool CNode::fPauseRecv {false}

Definition at line 719 of file net.h.

◆ fPauseSend

std::atomic_bool CNode::fPauseSend {false}

Definition at line 720 of file net.h.

◆ fPingQueued

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

Definition at line 794 of file net.h.

◆ fSentAddr

bool CNode::fSentAddr {false}

Definition at line 714 of file net.h.

◆ fSuccessfullyConnected

std::atomic_bool CNode::fSuccessfullyConnected {false}

Definition at line 710 of file net.h.

◆ grantOutbound

CSemaphoreGrant CNode::grantOutbound

Definition at line 715 of file net.h.

◆ hashContinue

uint256 CNode::hashContinue

Definition at line 727 of file net.h.

◆ id

const NodeId CNode::id
private

Definition at line 804 of file net.h.

◆ m_addr_relay_peer

const bool CNode::m_addr_relay_peer

Definition at line 735 of file net.h.

◆ m_legacyWhitelisted

bool CNode::m_legacyWhitelisted {false}

Definition at line 703 of file net.h.

◆ m_limited_node

bool CNode::m_limited_node {false}

Definition at line 708 of file net.h.

◆ m_manual_connection

bool CNode::m_manual_connection {false}

Definition at line 706 of file net.h.

◆ m_permissionFlags

NetPermissionFlags CNode::m_permissionFlags { PF_NONE }
private

Definition at line 826 of file net.h.

◆ m_prefer_evict

bool CNode::m_prefer_evict {false}

Definition at line 698 of file net.h.

◆ m_tx_relay

std::unique_ptr<TxRelay> CNode::m_tx_relay

Definition at line 775 of file net.h.

◆ mapSendBytesPerMsgCmd

mapMsgCmdSize CNode::mapSendBytesPerMsgCmd
protected

Definition at line 723 of file net.h.

◆ nKeyedNetGroup

const uint64_t CNode::nKeyedNetGroup

Definition at line 718 of file net.h.

◆ nLastBlockTime

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

Definition at line 781 of file net.h.

◆ nLastRecv

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

Definition at line 684 of file net.h.

◆ nLastSend

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

Definition at line 683 of file net.h.

◆ nLastTXTime

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

Definition at line 782 of file net.h.

◆ nLocalHostNonce

const uint64_t CNode::nLocalHostNonce
private

Definition at line 805 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 822 of file net.h.

◆ nMinPingUsecTime

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

Definition at line 792 of file net.h.

◆ nMyStartingHeight

const int CNode::nMyStartingHeight
private

Definition at line 824 of file net.h.

◆ nPingNonceSent

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

Definition at line 786 of file net.h.

◆ nPingUsecStart

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

Definition at line 788 of file net.h.

◆ nPingUsecTime

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

Definition at line 790 of file net.h.

◆ nProcessQueueSize

size_t CNode::nProcessQueueSize {0}

Definition at line 675 of file net.h.

◆ nRecvVersion

std::atomic<int> CNode::nRecvVersion {INIT_PROTO_VERSION}

Definition at line 681 of file net.h.

◆ nRefCount

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

Definition at line 716 of file net.h.

◆ nSendOffset

size_t CNode::nSendOffset {0}

Definition at line 666 of file net.h.

◆ nSendSize

size_t CNode::nSendSize {0}

Definition at line 665 of file net.h.

◆ nSendVersion

int CNode::nSendVersion {0}
private

Definition at line 825 of file net.h.

◆ nServices

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

Definition at line 663 of file net.h.

◆ nStartingHeight

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

Definition at line 728 of file net.h.

◆ nTimeConnected

const int64_t CNode::nTimeConnected

Definition at line 685 of file net.h.

◆ nTimeOffset

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

Definition at line 686 of file net.h.

◆ nVersion

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

Definition at line 691 of file net.h.

◆ orphan_work_set

std::set<uint256> CNode::orphan_work_set

Definition at line 796 of file net.h.

◆ vAddrToSend

std::vector<CAddress> CNode::vAddrToSend

Definition at line 731 of file net.h.

◆ vRecvGetData

std::deque<CInv> CNode::vRecvGetData

Definition at line 679 of file net.h.

◆ vRecvMsg

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

Definition at line 827 of file net.h.


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