Bitcoin Core 28.99.0
P2P Digital Currency
|
Information about a peer. More...
#include <net.h>
Public Member Functions | |
std::shared_ptr< Sock > m_sock | GUARDED_BY (m_sock_mutex) |
Socket used for communication with the node. More... | |
size_t m_send_memusage | GUARDED_BY (cs_vSend) |
Sum of GetMemoryUsage of all vSendMsg entries. More... | |
uint64_t nSendBytes | GUARDED_BY (cs_vSend) |
Total number of bytes sent on the wire to this peer. More... | |
std::deque< CSerializedNetMsg > vSendMsg | GUARDED_BY (cs_vSend) |
Messages still to be fed to m_transport->SetMessageToSend. More... | |
uint64_t nRecvBytes | GUARDED_BY (cs_vRecv) |
std::string cleanSubVer | GUARDED_BY (m_subver_mutex) |
cleanSubVer is a sanitized string of the user agent byte array we read from the wire. More... | |
bool | HasPermission (NetPermissionFlags permission) const |
void | MarkReceivedMsgsForProcessing () EXCLUSIVE_LOCKS_REQUIRED(!m_msg_process_queue_mutex) |
Move all messages from the received queue to the processing queue. More... | |
std::optional< std::pair< CNetMessage, bool > > | PollMessage () EXCLUSIVE_LOCKS_REQUIRED(!m_msg_process_queue_mutex) |
Poll the next message from the processing queue of this connection. More... | |
void | AccountForSentBytes (const std::string &msg_type, size_t sent_bytes) EXCLUSIVE_LOCKS_REQUIRED(cs_vSend) |
Account for the total size of a sent message in the per msg type connection stats. More... | |
bool | IsOutboundOrBlockRelayConn () const |
bool | IsFullOutboundConn () const |
bool | IsManualConn () const |
bool | IsManualOrFullOutboundConn () const |
bool | IsBlockOnlyConn () const |
bool | IsFeelerConn () const |
bool | IsAddrFetchConn () const |
bool | IsInboundConn () const |
bool | ExpectServicesFromConn () const |
Network | ConnectedThroughNetwork () const |
Get network the peer connected through. More... | |
bool | IsConnectedThroughPrivacyNet () const |
Whether this peer connected through a privacy network. More... | |
CNode (NodeId id, std::shared_ptr< Sock > sock, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn, ConnectionType conn_type_in, bool inbound_onion, CNodeOptions &&node_opts={}) | |
CNode (const CNode &)=delete | |
CNode & | operator= (const CNode &)=delete |
NodeId | GetId () const |
uint64_t | GetLocalNonce () const |
int | GetRefCount () const |
bool | ReceiveMsgBytes (Span< const uint8_t > msg_bytes, bool &complete) EXCLUSIVE_LOCKS_REQUIRED(!cs_vRecv) |
Receive bytes from the buffer and deserialize them into messages. More... | |
void | SetCommonVersion (int greatest_common_version) |
int | GetCommonVersion () const |
CService | GetAddrLocal () const EXCLUSIVE_LOCKS_REQUIRED(!m_addr_local_mutex) |
void | SetAddrLocal (const CService &addrLocalIn) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_local_mutex) |
May not be called more than once. More... | |
CNode * | AddRef () |
void | Release () |
void | CloseSocketDisconnect () EXCLUSIVE_LOCKS_REQUIRED(!m_sock_mutex) |
void | CopyStats (CNodeStats &stats) EXCLUSIVE_LOCKS_REQUIRED(!m_subver_mutex |
std::string | ConnectionTypeAsString () const |
void | PongReceived (std::chrono::microseconds ping_time) |
A ping-pong round trip has completed successfully. More... | |
Public Attributes | |
const std::unique_ptr< Transport > | m_transport |
Transport serializer/deserializer. More... | |
const NetPermissionFlags | m_permission_flags |
Mutex | cs_vSend |
Mutex | m_sock_mutex |
Mutex | cs_vRecv |
std::atomic< std::chrono::seconds > | m_last_send {0s} |
std::atomic< std::chrono::seconds > | m_last_recv {0s} |
const std::chrono::seconds | m_connected |
Unix epoch time at peer connection. More... | |
const CAddress | addr |
const CAddress | addrBind |
const std::string | m_addr_name |
const std::string | m_dest |
The pszDest argument provided to ConnectNode(). More... | |
const bool | m_inbound_onion |
Whether this peer is an inbound onion, i.e. connected via our Tor onion service. More... | |
std::atomic< int > | nVersion {0} |
Mutex | m_subver_mutex |
const bool | m_prefer_evict {false} |
std::atomic_bool | fSuccessfullyConnected {false} |
fSuccessfullyConnected is set to true on receiving VERACK from the peer. More... | |
std::atomic_bool | fDisconnect {false} |
CSemaphoreGrant | grantOutbound |
std::atomic< int > | nRefCount {0} |
const uint64_t | nKeyedNetGroup |
std::atomic_bool | fPauseRecv {false} |
std::atomic_bool | fPauseSend {false} |
const ConnectionType | m_conn_type |
std::atomic< bool > | m_bip152_highbandwidth_to {false} |
std::atomic< bool > | m_bip152_highbandwidth_from {false} |
std::atomic_bool | m_has_all_wanted_services {false} |
Whether this peer provides all services that we want. More... | |
std::atomic_bool | m_relays_txs {false} |
Whether we should relay transactions to this peer. More... | |
std::atomic_bool | m_bloom_filter_loaded {false} |
Whether this peer has loaded a bloom filter. More... | |
std::atomic< std::chrono::seconds > | m_last_block_time {0s} |
UNIX epoch time of the last block received from this peer that we had not yet seen (e.g. More... | |
std::atomic< std::chrono::seconds > | m_last_tx_time {0s} |
UNIX epoch time of the last transaction received from this peer that we had not yet seen (e.g. More... | |
std::atomic< std::chrono::microseconds > | m_last_ping_time {0us} |
Last measured round-trip time. More... | |
std::atomic< std::chrono::microseconds > | m_min_ping_time {std::chrono::microseconds::max()} |
Lowest measured round-trip time. More... | |
void | !m_addr_local_mutex |
void | !cs_vSend |
void | !cs_vRecv |
Private Member Functions | |
std::list< CNetMessage > m_msg_process_queue | GUARDED_BY (m_msg_process_queue_mutex) |
size_t m_msg_process_queue_size | GUARDED_BY (m_msg_process_queue_mutex) |
CService m_addr_local | GUARDED_BY (m_addr_local_mutex) |
mapMsgTypeSize mapSendBytesPerMsgType | GUARDED_BY (cs_vSend) |
mapMsgTypeSize mapRecvBytesPerMsgType | GUARDED_BY (cs_vRecv) |
std::unique_ptr< i2p::sam::Session > m_i2p_sam_session | GUARDED_BY (m_sock_mutex) |
If an I2P session is created per connection (for outbound transient I2P connections) then it is stored here so that it can be destroyed when the socket is closed. More... | |
Private Attributes | |
const NodeId | id |
const uint64_t | nLocalHostNonce |
std::atomic< int > | m_greatest_common_version {INIT_PROTO_VERSION} |
const size_t | m_recv_flood_size |
std::list< CNetMessage > | vRecvMsg |
Mutex | m_msg_process_queue_mutex |
Mutex | m_addr_local_mutex |
CNode::CNode | ( | NodeId | id, |
std::shared_ptr< Sock > | sock, | ||
const CAddress & | addrIn, | ||
uint64_t | nKeyedNetGroupIn, | ||
uint64_t | nLocalHostNonceIn, | ||
const CAddress & | addrBindIn, | ||
const std::string & | addrNameIn, | ||
ConnectionType | conn_type_in, | ||
bool | inbound_onion, | ||
CNodeOptions && | node_opts = {} |
||
) |
|
delete |
|
inline |
|
inline |
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.
Definition at line 597 of file net.cpp.
|
inline |
void CNode::CopyStats | ( | CNodeStats & | stats | ) |
|
inline |
CService CNode::GetAddrLocal | ( | ) | const |
|
inline |
|
inline |
|
private |
|
inline |
|
inline |
std::deque< CSerializedNetMsg > vSendMsg CNode::GUARDED_BY | ( | cs_vSend | ) |
Messages still to be fed to m_transport->SetMessageToSend.
|
private |
|
private |
|
private |
|
inlineprivate |
std::shared_ptr< Sock > m_sock CNode::GUARDED_BY | ( | m_sock_mutex | ) |
Socket used for communication with the node.
May not own a Sock object (after CloseSocketDisconnect()
or during tests). shared_ptr
(instead of unique_ptr
) is used to avoid premature close of the underlying file descriptor by one thread while another thread is poll(2)-ing it for activity.
|
private |
If an I2P session is created per connection (for outbound transient I2P connections) then it is stored here so that it can be destroyed when the socket is closed.
I2P sessions involve a data/transport socket (in m_sock
) and a control socket (in m_i2p_sam_session
). For transient sessions, once the data socket is closed, the control socket is not going to be used anymore and is just taking up resources. So better close it as soon as m_sock
is closed. Otherwise this unique_ptr is empty.
|
inline |
|
inline |
bool CNode::IsConnectedThroughPrivacyNet | ( | ) | const |
|
inline |
|
inline |
|
inline |
void CNode::MarkReceivedMsgsForProcessing | ( | ) |
std::optional< std::pair< CNetMessage, bool > > CNode::PollMessage | ( | ) |
|
inline |
bool CNode::ReceiveMsgBytes | ( | Span< const uint8_t > | msg_bytes, |
bool & | complete | ||
) |
Receive bytes from the buffer and deserialize them into messages.
[in] | msg_bytes | The raw data |
[out] | complete | Set True if at least one message has been deserialized and is ready to be processed |
Definition at line 655 of file net.cpp.
void CNode::SetAddrLocal | ( | const CService & | addrLocalIn | ) |
|
inline |
std::atomic_bool CNode::fSuccessfullyConnected {false} |
CSemaphoreGrant CNode::grantOutbound |
std::atomic_bool CNode::m_bloom_filter_loaded {false} |
const ConnectionType CNode::m_conn_type |
const std::chrono::seconds CNode::m_connected |
const std::string CNode::m_dest |
|
private |
std::atomic_bool CNode::m_has_all_wanted_services {false} |
const bool CNode::m_inbound_onion |
std::atomic<std::chrono::seconds> CNode::m_last_block_time {0s} |
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.
std::atomic<std::chrono::microseconds> CNode::m_last_ping_time {0us} |
std::atomic<std::chrono::seconds> CNode::m_last_tx_time {0s} |
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.
std::atomic<std::chrono::microseconds> CNode::m_min_ping_time {std::chrono::microseconds::max()} |
Lowest measured round-trip time.
Used as an inbound peer eviction criterium in CConnman::AttemptToEvictConnection.
const NetPermissionFlags CNode::m_permission_flags |
std::atomic_bool CNode::m_relays_txs {false} |
const std::unique_ptr<Transport> CNode::m_transport |
|
private |