Bitcoin Core  22.99.0
P2P Digital Currency
Classes | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
CConnman Class Reference

#include <net.h>

Inheritance diagram for CConnman:
[legend]
Collaboration diagram for CConnman:
[legend]

Classes

struct  CachedAddrResponse
 Cache responses to addr requests to minimize privacy leak. More...
 
struct  ListenSocket
 
class  NodesSnapshot
 RAII helper to atomically create a copy of m_nodes and add a reference to each of the nodes. More...
 
struct  Options
 

Public Types

using NodeFn = std::function< void(CNode *)>
 

Public Member Functions

void Init (const Options &connOptions)
 
 CConnman (uint64_t seed0, uint64_t seed1, AddrMan &addrman, bool network_active=true)
 
 ~CConnman ()
 
bool Start (CScheduler &scheduler, const Options &options)
 
void StopThreads ()
 
void StopNodes ()
 
void Stop ()
 
void Interrupt ()
 
bool GetNetworkActive () const
 
bool GetUseAddrmanOutgoing () const
 
void SetNetworkActive (bool active)
 
void OpenNetworkConnection (const CAddress &addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *strDest, ConnectionType conn_type)
 
bool CheckIncomingNonce (uint64_t nonce)
 
bool ForNode (NodeId id, std::function< bool(CNode *pnode)> func)
 
void PushMessage (CNode *pnode, CSerializedNetMsg &&msg)
 
void ForEachNode (const NodeFn &func)
 
void ForEachNode (const NodeFn &func) const
 
std::vector< CAddressGetAddresses (size_t max_addresses, size_t max_pct, std::optional< Network > network) const
 Return all or many randomly selected addresses, optionally by network. More...
 
std::vector< CAddressGetAddresses (CNode &requestor, size_t max_addresses, size_t max_pct)
 Cache is used to minimize topology leaks, so it should be used for all non-trusted calls, for example, p2p. More...
 
void SetTryNewOutboundPeer (bool flag)
 
bool GetTryNewOutboundPeer () const
 
void StartExtraBlockRelayPeers ()
 
int GetExtraFullOutboundCount () const
 
int GetExtraBlockRelayCount () const
 
bool AddNode (const std::string &node)
 
bool RemoveAddedNode (const std::string &node)
 
std::vector< AddedNodeInfoGetAddedNodeInfo () const
 
bool AddConnection (const std::string &address, ConnectionType conn_type)
 Attempts to open a connection. More...
 
size_t GetNodeCount (ConnectionDirection) const
 
void GetNodeStats (std::vector< CNodeStats > &vstats) const
 
bool DisconnectNode (const std::string &node)
 
bool DisconnectNode (const CSubNet &subnet)
 
bool DisconnectNode (const CNetAddr &addr)
 
bool DisconnectNode (NodeId id)
 
ServiceFlags GetLocalServices () const
 Used to convey which local services we are offering peers during node connection. More...
 
uint64_t GetMaxOutboundTarget () const
 
std::chrono::seconds GetMaxOutboundTimeframe () const
 
bool OutboundTargetReached (bool historicalBlockServingLimit) const
 check if the outbound target is reached if param historicalBlockServingLimit is set true, the function will response true if the limit for serving historical blocks has been reached More...
 
uint64_t GetOutboundTargetBytesLeft () const
 response the bytes left in the current max outbound cycle in case of no limit, it will always response 0 More...
 
std::chrono::seconds GetMaxOutboundTimeLeftInCycle () const
 returns the time left in the current max outbound cycle in case of no limit, it will always return 0 More...
 
uint64_t GetTotalBytesRecv () const
 
uint64_t GetTotalBytesSent () const
 
CSipHasher GetDeterministicRandomizer (uint64_t id) const
 Get a unique deterministic randomizer. More...
 
unsigned int GetReceiveFloodSize () const
 
void WakeMessageHandler ()
 
std::chrono::microseconds PoissonNextSendInbound (std::chrono::microseconds now, std::chrono::seconds average_interval)
 Attempts to obfuscate tx time through exponentially distributed emitting. More...
 
bool ShouldRunInactivityChecks (const CNode &node, int64_t secs_now) const
 Return true if we should disconnect the peer for failing an inactivity check. More...
 

Private Member Functions

bool BindListenPort (const CService &bindAddr, bilingual_str &strError, NetPermissionFlags permissions)
 
bool Bind (const CService &addr, unsigned int flags, NetPermissionFlags permissions)
 
bool InitBinds (const Options &options)
 
void ThreadOpenAddedConnections ()
 
void AddAddrFetch (const std::string &strDest)
 
void ProcessAddrFetch ()
 
void ThreadOpenConnections (std::vector< std::string > connect)
 
void ThreadMessageHandler ()
 
void ThreadI2PAcceptIncoming ()
 
void AcceptConnection (const ListenSocket &hListenSocket)
 
void CreateNodeFromAcceptedSocket (SOCKET hSocket, NetPermissionFlags permissionFlags, const CAddress &addr_bind, const CAddress &addr)
 Create a CNode object from a socket that has just been accepted and add the node to the m_nodes member. More...
 
void DisconnectNodes ()
 
void NotifyNumConnectionsChanged ()
 
bool InactivityCheck (const CNode &node) const
 Return true if the peer is inactive and should be disconnected. More...
 
bool GenerateSelectSet (const std::vector< CNode * > &nodes, std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
 Generate a collection of sockets to check for IO readiness. More...
 
void SocketEvents (const std::vector< CNode * > &nodes, std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
 Check which sockets are ready for IO. More...
 
void SocketHandler ()
 Check connected and listening sockets for IO readiness and process them accordingly. More...
 
void SocketHandlerConnected (const std::vector< CNode * > &nodes, const std::set< SOCKET > &recv_set, const std::set< SOCKET > &send_set, const std::set< SOCKET > &error_set)
 Do the read/write for connected sockets that are ready for IO. More...
 
void SocketHandlerListening (const std::set< SOCKET > &recv_set)
 Accept incoming connections, one from each read-ready listening socket. More...
 
void ThreadSocketHandler ()
 
void ThreadDNSAddressSeed ()
 
uint64_t CalculateKeyedNetGroup (const CAddress &ad) const
 
CNodeFindNode (const CNetAddr &ip)
 
CNodeFindNode (const CSubNet &subNet)
 
CNodeFindNode (const std::string &addrName)
 
CNodeFindNode (const CService &addr)
 
bool AlreadyConnectedToAddress (const CAddress &addr)
 Determine whether we're already connected to a given address, in order to avoid initiating duplicate connections. More...
 
bool AttemptToEvictConnection ()
 Try to find a connection to evict when the node is full. More...
 
CNodeConnectNode (CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type)
 
void AddWhitelistPermissionFlags (NetPermissionFlags &flags, const CNetAddr &addr) const
 
void DeleteNode (CNode *pnode)
 
NodeId GetNewNodeId ()
 
size_t SocketSendData (CNode &node) const EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend)
 
void DumpAddresses ()
 
void RecordBytesRecv (uint64_t bytes)
 
void RecordBytesSent (uint64_t bytes)
 
std::vector< CAddressGetCurrentBlockRelayOnlyConns () const
 Return vector of current BLOCK_RELAY peers. More...
 
uint64_t nTotalBytesSent GUARDED_BY (cs_totalBytesSent)
 
uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY (cs_totalBytesSent)
 
std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY (cs_totalBytesSent)
 
uint64_t nMaxOutboundLimit GUARDED_BY (cs_totalBytesSent)
 
std::deque< std::string > m_addr_fetches GUARDED_BY (m_addr_fetches_mutex)
 
std::vector< std::string > m_added_nodes GUARDED_BY (m_added_nodes_mutex)
 
std::vector< CNode * > m_nodes GUARDED_BY (m_nodes_mutex)
 
bool fMsgProcWake GUARDED_BY (mutexMsgProc)
 flag for waking the message processor. More...
 

Static Private Member Functions

static bool NodeFullyConnected (const CNode *pnode)
 

Private Attributes

RecursiveMutex cs_totalBytesSent
 
std::atomic< uint64_t > nTotalBytesRecv {0}
 
int64_t m_peer_connect_timeout
 
std::vector< NetWhitelistPermissionsvWhitelistedRange
 
unsigned int nSendBufferMaxSize {0}
 
unsigned int nReceiveFloodSize {0}
 
std::vector< ListenSocketvhListenSocket
 
std::atomic< bool > fNetworkActive {true}
 
bool fAddressesInitialized {false}
 
AddrManaddrman
 
Mutex m_addr_fetches_mutex
 
Mutex m_added_nodes_mutex
 
std::list< CNode * > m_nodes_disconnected
 
RecursiveMutex m_nodes_mutex
 
std::atomic< NodeIdnLastNodeId {0}
 
unsigned int nPrevNodeCount {0}
 
std::map< uint64_t, CachedAddrResponsem_addr_response_caches
 Addr responses stored in different caches per (network, local socket) prevent cross-network node identification. More...
 
ServiceFlags nLocalServices
 Services this instance offers. More...
 
std::unique_ptr< CSemaphoresemOutbound
 
std::unique_ptr< CSemaphoresemAddnode
 
int nMaxConnections
 
int m_max_outbound_full_relay
 
int m_max_outbound_block_relay
 
int nMaxAddnode
 
int nMaxFeeler
 
int m_max_outbound
 
bool m_use_addrman_outgoing
 
CClientUIInterfacem_client_interface
 
NetEventsInterfacem_msgproc
 
BanManm_banman
 Pointer to this node's banman. More...
 
std::vector< CAddressm_anchors
 Addresses that were saved during the previous clean shutdown. More...
 
const uint64_t nSeed0
 SipHasher seeds for deterministic randomness. More...
 
const uint64_t nSeed1
 
std::condition_variable condMsgProc
 
Mutex mutexMsgProc
 
std::atomic< bool > flagInterruptMsgProc {false}
 
CThreadInterrupt interruptNet
 This is signaled when network activity should cease. More...
 
std::unique_ptr< i2p::sam::Sessionm_i2p_sam_session
 I2P SAM session. More...
 
std::thread threadDNSAddressSeed
 
std::thread threadSocketHandler
 
std::thread threadOpenAddedConnections
 
std::thread threadOpenConnections
 
std::thread threadMessageHandler
 
std::thread threadI2PAcceptIncoming
 
std::atomic_bool m_try_another_outbound_peer
 flag for deciding to connect to an extra outbound peer, in excess of m_max_outbound_full_relay This takes the place of a feeler connection More...
 
std::atomic_bool m_start_extra_block_relay_peers {false}
 flag for initiating extra block-relay-only peer connections. More...
 
std::atomic< std::chrono::microseconds > m_next_send_inv_to_incoming {0us}
 
std::vector< CServicem_onion_binds
 A vector of -bind=<address>:<port>=onion arguments each of which is an address and port that are designated for incoming Tor connections. More...
 

Friends

struct CConnmanTest
 
struct ConnmanTestMsg
 

Detailed Description

Definition at line 740 of file net.h.

Member Typedef Documentation

◆ NodeFn

using CConnman::NodeFn = std::function<void(CNode*)>

Definition at line 823 of file net.h.

Constructor & Destructor Documentation

◆ CConnman()

CConnman::CConnman ( uint64_t  seed0,
uint64_t  seed1,
AddrMan addrman,
bool  network_active = true 
)

Definition at line 2464 of file net.cpp.

Here is the call graph for this function:

◆ ~CConnman()

CConnman::~CConnman ( )

Definition at line 2728 of file net.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ AcceptConnection()

void CConnman::AcceptConnection ( const ListenSocket hListenSocket)
private

Definition at line 1098 of file net.cpp.

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

◆ AddAddrFetch()

void CConnman::AddAddrFetch ( const std::string &  strDest)
private

Definition at line 119 of file net.cpp.

Here is the caller graph for this function:

◆ AddConnection()

bool CConnman::AddConnection ( const std::string &  address,
ConnectionType  conn_type 
)

Attempts to open a connection.

Currently only used from tests.

Parameters
[in]addressAddress of node to try connecting to
[in]conn_typeConnectionType::OUTBOUND or ConnectionType::BLOCK_RELAY or ConnectionType::ADDR_FETCH
Returns
bool Returns false if there are no available slots for this connection:
  • conn_type not a supported ConnectionType
  • Max total outbound connection capacity filled
  • Max connection capacity for type is filled

Definition at line 1221 of file net.cpp.

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

◆ AddNode()

bool CConnman::AddNode ( const std::string &  node)

Definition at line 2786 of file net.cpp.

Here is the caller graph for this function:

◆ AddWhitelistPermissionFlags()

void CConnman::AddWhitelistPermissionFlags ( NetPermissionFlags flags,
const CNetAddr addr 
) const
private

Definition at line 527 of file net.cpp.

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

◆ AlreadyConnectedToAddress()

bool CConnman::AlreadyConnectedToAddress ( const CAddress addr)
private

Determine whether we're already connected to a given address, in order to avoid initiating duplicate connections.

Definition at line 371 of file net.cpp.

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

◆ AttemptToEvictConnection()

bool CConnman::AttemptToEvictConnection ( )
private

Try to find a connection to evict when the node is full.

Extreme care must be taken to avoid opening the node to attacker triggered network partitioning. The strategy used here is to protect a small number of peers for each of several distinct characteristics which are difficult to forge. In order to partition a node the attacker must be simultaneously better at all of them than honest peers.

Definition at line 1054 of file net.cpp.

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

◆ Bind()

bool CConnman::Bind ( const CService addr,
unsigned int  flags,
NetPermissionFlags  permissions 
)
private

Definition at line 2480 of file net.cpp.

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

◆ BindListenPort()

bool CConnman::BindListenPort ( const CService bindAddr,
bilingual_str strError,
NetPermissionFlags  permissions 
)
private

Definition at line 2337 of file net.cpp.

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

◆ CalculateKeyedNetGroup()

uint64_t CConnman::CalculateKeyedNetGroup ( const CAddress ad) const
private

Definition at line 3092 of file net.cpp.

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

◆ CheckIncomingNonce()

bool CConnman::CheckIncomingNonce ( uint64_t  nonce)

Definition at line 376 of file net.cpp.

◆ ConnectNode()

CNode * CConnman::ConnectNode ( CAddress  addrConnect,
const char *  pszDest,
bool  fCountFailure,
ConnectionType  conn_type 
)
private

debug print

Definition at line 402 of file net.cpp.

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

◆ CreateNodeFromAcceptedSocket()

void CConnman::CreateNodeFromAcceptedSocket ( SOCKET  hSocket,
NetPermissionFlags  permissionFlags,
const CAddress addr_bind,
const CAddress addr 
)
private

Create a CNode object from a socket that has just been accepted and add the node to the m_nodes member.

Parameters
[in]hSocketConnected socket to communicate with the peer.
[in]permissionFlagsThe peer's permissions.
[in]addr_bindThe address and port at our side of the connection.
[in]addrThe address and port at the peer's side of the connection.

Definition at line 1126 of file net.cpp.

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

◆ DeleteNode()

void CConnman::DeleteNode ( CNode pnode)
private

Definition at line 2721 of file net.cpp.

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

◆ DisconnectNode() [1/4]

bool CConnman::DisconnectNode ( const CNetAddr addr)

Definition at line 2862 of file net.cpp.

Here is the call graph for this function:

◆ DisconnectNode() [2/4]

bool CConnman::DisconnectNode ( const CSubNet subnet)

Definition at line 2848 of file net.cpp.

Here is the call graph for this function:

◆ DisconnectNode() [3/4]

bool CConnman::DisconnectNode ( const std::string &  node)

Definition at line 2837 of file net.cpp.

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

◆ DisconnectNode() [4/4]

bool CConnman::DisconnectNode ( NodeId  id)

Definition at line 2867 of file net.cpp.

◆ DisconnectNodes()

void CConnman::DisconnectNodes ( )
private

Definition at line 1255 of file net.cpp.

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

◆ DumpAddresses()

void CConnman::DumpAddresses ( )
private

Definition at line 1780 of file net.cpp.

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

◆ FindNode() [1/4]

CNode * CConnman::FindNode ( const CNetAddr ip)
private

Definition at line 327 of file net.cpp.

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

◆ FindNode() [2/4]

CNode * CConnman::FindNode ( const CService addr)
private

Definition at line 360 of file net.cpp.

◆ FindNode() [3/4]

CNode * CConnman::FindNode ( const CSubNet subNet)
private

Definition at line 338 of file net.cpp.

Here is the call graph for this function:

◆ FindNode() [4/4]

CNode * CConnman::FindNode ( const std::string &  addrName)
private

Definition at line 349 of file net.cpp.

◆ ForEachNode() [1/2]

void CConnman::ForEachNode ( const NodeFn func)
inline

Definition at line 824 of file net.h.

Here is the call graph for this function:

◆ ForEachNode() [2/2]

void CConnman::ForEachNode ( const NodeFn func) const
inline

Definition at line 833 of file net.h.

Here is the call graph for this function:

◆ ForNode()

bool CConnman::ForNode ( NodeId  id,
std::function< bool(CNode *pnode)>  func 
)

Definition at line 3057 of file net.cpp.

Here is the call graph for this function:

◆ GenerateSelectSet()

bool CConnman::GenerateSelectSet ( const std::vector< CNode * > &  nodes,
std::set< SOCKET > &  recv_set,
std::set< SOCKET > &  send_set,
std::set< SOCKET > &  error_set 
)
private

Generate a collection of sockets to check for IO readiness.

Parameters
[in]nodesSelect from these nodes' sockets.
[out]recv_setSockets to check for read readiness.
[out]send_setSockets to check for write readiness.
[out]error_setSockets to check for errors.
Returns
true if at least one socket is to be checked (the returned set is not empty)

Definition at line 1356 of file net.cpp.

Here is the caller graph for this function:

◆ GetAddedNodeInfo()

std::vector< AddedNodeInfo > CConnman::GetAddedNodeInfo ( ) const

Definition at line 2139 of file net.cpp.

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

◆ GetAddresses() [1/2]

std::vector< CAddress > CConnman::GetAddresses ( CNode requestor,
size_t  max_addresses,
size_t  max_pct 
)

Cache is used to minimize topology leaks, so it should be used for all non-trusted calls, for example, p2p.

A non-malicious call (from RPC or a peer with addr permission) should call the function without a parameter to avoid using the cache.

Definition at line 2745 of file net.cpp.

Here is the call graph for this function:

◆ GetAddresses() [2/2]

std::vector< CAddress > CConnman::GetAddresses ( size_t  max_addresses,
size_t  max_pct,
std::optional< Network network 
) const

Return all or many randomly selected addresses, optionally by network.

Parameters
[in]max_addressesMaximum number of addresses to return (0 = all).
[in]max_pctMaximum percentage of addresses to return (0 = all).
[in]networkSelect only addresses of this network (nullopt = all).

Definition at line 2734 of file net.cpp.

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

◆ GetCurrentBlockRelayOnlyConns()

std::vector< CAddress > CConnman::GetCurrentBlockRelayOnlyConns ( ) const
private

Return vector of current BLOCK_RELAY peers.

Definition at line 2126 of file net.cpp.

Here is the caller graph for this function:

◆ GetDeterministicRandomizer()

CSipHasher CConnman::GetDeterministicRandomizer ( uint64_t  id) const

Get a unique deterministic randomizer.

Definition at line 3087 of file net.cpp.

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

◆ GetExtraBlockRelayCount()

int CConnman::GetExtraBlockRelayCount ( ) const

Definition at line 1838 of file net.cpp.

◆ GetExtraFullOutboundCount()

int CConnman::GetExtraFullOutboundCount ( ) const

Definition at line 1824 of file net.cpp.

◆ GetLocalServices()

ServiceFlags CConnman::GetLocalServices ( ) const

Used to convey which local services we are offering peers during node connection.

The data returned by this is used in CNode construction, which is used to advertise which services we are offering that peer during net_processing.cpp:PushNodeVersion().

Definition at line 2967 of file net.cpp.

◆ GetMaxOutboundTarget()

uint64_t CConnman::GetMaxOutboundTarget ( ) const

Definition at line 2902 of file net.cpp.

Here is the caller graph for this function:

◆ GetMaxOutboundTimeframe()

std::chrono::seconds CConnman::GetMaxOutboundTimeframe ( ) const

Definition at line 2908 of file net.cpp.

Here is the caller graph for this function:

◆ GetMaxOutboundTimeLeftInCycle()

std::chrono::seconds CConnman::GetMaxOutboundTimeLeftInCycle ( ) const

returns the time left in the current max outbound cycle in case of no limit, it will always return 0

Definition at line 2913 of file net.cpp.

Here is the caller graph for this function:

◆ GetNetworkActive()

bool CConnman::GetNetworkActive ( ) const
inline

Definition at line 813 of file net.h.

Here is the caller graph for this function:

◆ GetNewNodeId()

NodeId CConnman::GetNewNodeId ( )
private

Definition at line 2474 of file net.cpp.

Here is the caller graph for this function:

◆ GetNodeCount()

size_t CConnman::GetNodeCount ( ConnectionDirection  flags) const

Definition at line 2809 of file net.cpp.

Here is the caller graph for this function:

◆ GetNodeStats()

void CConnman::GetNodeStats ( std::vector< CNodeStats > &  vstats) const

Definition at line 2825 of file net.cpp.

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

◆ GetOutboundTargetBytesLeft()

uint64_t CConnman::GetOutboundTargetBytesLeft ( ) const

response the bytes left in the current max outbound cycle in case of no limit, it will always response 0

Definition at line 2947 of file net.cpp.

Here is the caller graph for this function:

◆ GetReceiveFloodSize()

unsigned int CConnman::GetReceiveFloodSize ( ) const

Definition at line 2972 of file net.cpp.

◆ GetTotalBytesRecv()

uint64_t CConnman::GetTotalBytesRecv ( ) const

Definition at line 2956 of file net.cpp.

Here is the caller graph for this function:

◆ GetTotalBytesSent()

uint64_t CConnman::GetTotalBytesSent ( ) const

Definition at line 2961 of file net.cpp.

Here is the caller graph for this function:

◆ GetTryNewOutboundPeer()

bool CConnman::GetTryNewOutboundPeer ( ) const

Definition at line 1807 of file net.cpp.

Here is the caller graph for this function:

◆ GetUseAddrmanOutgoing()

bool CConnman::GetUseAddrmanOutgoing ( ) const
inline

Definition at line 814 of file net.h.

◆ GUARDED_BY() [1/8]

uint64_t nTotalBytesSent CConnman::GUARDED_BY ( cs_totalBytesSent  )
inlineprivate

Definition at line 1079 of file net.h.

◆ GUARDED_BY() [2/8]

uint64_t nMaxOutboundTotalBytesSentInCycle CConnman::GUARDED_BY ( cs_totalBytesSent  )
inlineprivate

Definition at line 1082 of file net.h.

◆ GUARDED_BY() [3/8]

std::chrono::seconds nMaxOutboundCycleStartTime CConnman::GUARDED_BY ( cs_totalBytesSent  )
inlineprivate

Definition at line 1083 of file net.h.

◆ GUARDED_BY() [4/8]

uint64_t nMaxOutboundLimit CConnman::GUARDED_BY ( cs_totalBytesSent  )
private

◆ GUARDED_BY() [5/8]

std::vector<std::string> m_added_nodes CConnman::GUARDED_BY ( m_added_nodes_mutex  )
private

◆ GUARDED_BY() [6/8]

std::deque<std::string> m_addr_fetches CConnman::GUARDED_BY ( m_addr_fetches_mutex  )
private

◆ GUARDED_BY() [7/8]

std::vector<CNode*> m_nodes CConnman::GUARDED_BY ( m_nodes_mutex  )
private

◆ GUARDED_BY() [8/8]

bool fMsgProcWake CConnman::GUARDED_BY ( mutexMsgProc  )
private

flag for waking the message processor.

◆ InactivityCheck()

bool CConnman::InactivityCheck ( const CNode node) const
private

Return true if the peer is inactive and should be disconnected.

Definition at line 1325 of file net.cpp.

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

◆ Init()

void CConnman::Init ( const Options connOptions)
inline

Definition at line 773 of file net.h.

Here is the caller graph for this function:

◆ InitBinds()

bool CConnman::InitBinds ( const Options options)
private

Definition at line 2502 of file net.cpp.

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

◆ Interrupt()

void CConnman::Interrupt ( )

Definition at line 2638 of file net.cpp.

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

◆ NodeFullyConnected()

bool CConnman::NodeFullyConnected ( const CNode pnode)
staticprivate

Definition at line 3011 of file net.cpp.

Here is the caller graph for this function:

◆ NotifyNumConnectionsChanged()

void CConnman::NotifyNumConnectionsChanged ( )
private

Definition at line 1305 of file net.cpp.

Here is the caller graph for this function:

◆ OpenNetworkConnection()

void CConnman::OpenNetworkConnection ( const CAddress addrConnect,
bool  fCountFailure,
CSemaphoreGrant grantOutbound,
const char *  strDest,
ConnectionType  conn_type 
)

Definition at line 2222 of file net.cpp.

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

◆ OutboundTargetReached()

bool CConnman::OutboundTargetReached ( bool  historicalBlockServingLimit) const

check if the outbound target is reached if param historicalBlockServingLimit is set true, the function will response true if the limit for serving historical blocks has been reached

Definition at line 2927 of file net.cpp.

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

◆ PoissonNextSendInbound()

std::chrono::microseconds CConnman::PoissonNextSendInbound ( std::chrono::microseconds  now,
std::chrono::seconds  average_interval 
)

Attempts to obfuscate tx time through exponentially distributed emitting.

Works assuming that a single interval is used. Variable intervals will result in privacy decrease.

Definition at line 3070 of file net.cpp.

Here is the call graph for this function:

◆ ProcessAddrFetch()

void CConnman::ProcessAddrFetch ( )
private

Definition at line 1790 of file net.cpp.

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

◆ PushMessage()

void CConnman::PushMessage ( CNode pnode,
CSerializedNetMsg &&  msg 
)

Definition at line 3016 of file net.cpp.

Here is the call graph for this function:

◆ RecordBytesRecv()

void CConnman::RecordBytesRecv ( uint64_t  bytes)
private

Definition at line 2880 of file net.cpp.

Here is the caller graph for this function:

◆ RecordBytesSent()

void CConnman::RecordBytesSent ( uint64_t  bytes)
private

Definition at line 2885 of file net.cpp.

Here is the caller graph for this function:

◆ RemoveAddedNode()

bool CConnman::RemoveAddedNode ( const std::string &  node)

Definition at line 2797 of file net.cpp.

Here is the caller graph for this function:

◆ SetNetworkActive()

void CConnman::SetNetworkActive ( bool  active)

Definition at line 2449 of file net.cpp.

Here is the caller graph for this function:

◆ SetTryNewOutboundPeer()

void CConnman::SetTryNewOutboundPeer ( bool  flag)

Definition at line 1812 of file net.cpp.

Here is the caller graph for this function:

◆ ShouldRunInactivityChecks()

bool CConnman::ShouldRunInactivityChecks ( const CNode node,
int64_t  secs_now 
) const

Return true if we should disconnect the peer for failing an inactivity check.

Definition at line 1320 of file net.cpp.

Here is the caller graph for this function:

◆ SocketEvents()

void CConnman::SocketEvents ( const std::vector< CNode * > &  nodes,
std::set< SOCKET > &  recv_set,
std::set< SOCKET > &  send_set,
std::set< SOCKET > &  error_set 
)
private

Check which sockets are ready for IO.

Parameters
[in]nodesSelect from these nodes' sockets.
[out]recv_setSockets which are ready for read.
[out]send_setSockets which are ready for write.
[out]error_setSockets which have errors. This calls GenerateSelectSet() to gather a list of sockets to check.

Definition at line 1447 of file net.cpp.

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

◆ SocketHandler()

void CConnman::SocketHandler ( )
private

Check connected and listening sockets for IO readiness and process them accordingly.

Definition at line 1525 of file net.cpp.

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

◆ SocketHandlerConnected()

void CConnman::SocketHandlerConnected ( const std::vector< CNode * > &  nodes,
const std::set< SOCKET > &  recv_set,
const std::set< SOCKET > &  send_set,
const std::set< SOCKET > &  error_set 
)
private

Do the read/write for connected sockets that are ready for IO.

Parameters
[in]nodesNodes to process. The socket of each node is checked against recv_set, send_set and error_set.
[in]recv_setSockets that are ready for read.
[in]send_setSockets that are ready for send.
[in]error_setSockets that have an exceptional condition (error).

Definition at line 1548 of file net.cpp.

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

◆ SocketHandlerListening()

void CConnman::SocketHandlerListening ( const std::set< SOCKET > &  recv_set)
private

Accept incoming connections, one from each read-ready listening socket.

Parameters
[in]recv_setSockets that are ready for read.

Definition at line 1637 of file net.cpp.

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

◆ SocketSendData()

size_t CConnman::SocketSendData ( CNode node) const
private

Definition at line 791 of file net.cpp.

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

◆ Start()

bool CConnman::Start ( CScheduler scheduler,
const Options options 
)

Definition at line 2524 of file net.cpp.

Here is the call graph for this function:

◆ StartExtraBlockRelayPeers()

void CConnman::StartExtraBlockRelayPeers ( )
inline

Definition at line 864 of file net.h.

◆ Stop()

void CConnman::Stop ( )
inline

Definition at line 806 of file net.h.

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

◆ StopNodes()

void CConnman::StopNodes ( )

Definition at line 2679 of file net.cpp.

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

◆ StopThreads()

void CConnman::StopThreads ( )

Definition at line 2662 of file net.cpp.

Here is the caller graph for this function:

◆ ThreadDNSAddressSeed()

void CConnman::ThreadDNSAddressSeed ( )
private

Definition at line 1669 of file net.cpp.

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

◆ ThreadI2PAcceptIncoming()

void CConnman::ThreadI2PAcceptIncoming ( )
private

Definition at line 2298 of file net.cpp.

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

◆ ThreadMessageHandler()

void CConnman::ThreadMessageHandler ( )
private

Definition at line 2257 of file net.cpp.

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

◆ ThreadOpenAddedConnections()

void CConnman::ThreadOpenAddedConnections ( )
private

Definition at line 2193 of file net.cpp.

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

◆ ThreadOpenConnections()

void CConnman::ThreadOpenConnections ( std::vector< std::string >  connect)
private

Definition at line 1852 of file net.cpp.

Here is the call graph for this function:

◆ ThreadSocketHandler()

void CConnman::ThreadSocketHandler ( )
private

Definition at line 1649 of file net.cpp.

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

◆ WakeMessageHandler()

void CConnman::WakeMessageHandler ( )

Definition at line 1660 of file net.cpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ CConnmanTest

friend struct CConnmanTest
friend

Definition at line 1264 of file net.h.

◆ ConnmanTestMsg

friend struct ConnmanTestMsg
friend

Definition at line 1265 of file net.h.

Member Data Documentation

◆ addrman

AddrMan& CConnman::addrman
private

Definition at line 1099 of file net.h.

◆ condMsgProc

std::condition_variable CConnman::condMsgProc
private

Definition at line 1183 of file net.h.

◆ cs_totalBytesSent

RecursiveMutex CConnman::cs_totalBytesSent
mutableprivate

Definition at line 1077 of file net.h.

◆ fAddressesInitialized

bool CConnman::fAddressesInitialized {false}
private

Definition at line 1098 of file net.h.

◆ flagInterruptMsgProc

std::atomic<bool> CConnman::flagInterruptMsgProc {false}
private

Definition at line 1185 of file net.h.

◆ fNetworkActive

std::atomic<bool> CConnman::fNetworkActive {true}
private

Definition at line 1097 of file net.h.

◆ interruptNet

CThreadInterrupt CConnman::interruptNet
private

This is signaled when network activity should cease.

A pointer to it is saved in m_i2p_sam_session, so make sure that the lifetime of interruptNet is not shorter than the lifetime of m_i2p_sam_session.

Definition at line 1193 of file net.h.

◆ m_added_nodes_mutex

Mutex CConnman::m_added_nodes_mutex
mutableprivate

Definition at line 1103 of file net.h.

◆ m_addr_fetches_mutex

Mutex CConnman::m_addr_fetches_mutex
private

Definition at line 1101 of file net.h.

◆ m_addr_response_caches

std::map<uint64_t, CachedAddrResponse> CConnman::m_addr_response_caches
private

Addr responses stored in different caches per (network, local socket) prevent cross-network node identification.

If a node for example is multi-homed under Tor and IPv6, a single cache (or no cache at all) would let an attacker to easily detect that it is the same node by comparing responses. Indexing by local socket prevents leakage when a node has multiple listening addresses on the same network.

The used memory equals to 1000 CAddress records (or around 40 bytes) per distinct Network (up to 5) we have/had an inbound peer from, resulting in at most ~196 KB. Every separate local socket may add up to ~196 KB extra.

Definition at line 1135 of file net.h.

◆ m_anchors

std::vector<CAddress> CConnman::m_anchors
private

Addresses that were saved during the previous clean shutdown.

We'll attempt to make block-relay-only connections to them.

Definition at line 1175 of file net.h.

◆ m_banman

BanMan* CConnman::m_banman
private

Pointer to this node's banman.

May be nullptr - check existence before dereferencing.

Definition at line 1169 of file net.h.

◆ m_client_interface

CClientUIInterface* CConnman::m_client_interface
private

Definition at line 1166 of file net.h.

◆ m_i2p_sam_session

std::unique_ptr<i2p::sam::Session> CConnman::m_i2p_sam_session
private

I2P SAM session.

Used to accept incoming and make outgoing I2P connections.

Definition at line 1199 of file net.h.

◆ m_max_outbound

int CConnman::m_max_outbound
private

Definition at line 1164 of file net.h.

◆ m_max_outbound_block_relay

int CConnman::m_max_outbound_block_relay
private

Definition at line 1160 of file net.h.

◆ m_max_outbound_full_relay

int CConnman::m_max_outbound_full_relay
private

Definition at line 1156 of file net.h.

◆ m_msgproc

NetEventsInterface* CConnman::m_msgproc
private

Definition at line 1167 of file net.h.

◆ m_next_send_inv_to_incoming

std::atomic<std::chrono::microseconds> CConnman::m_next_send_inv_to_incoming {0us}
private

Definition at line 1219 of file net.h.

◆ m_nodes_disconnected

std::list<CNode*> CConnman::m_nodes_disconnected
private

Definition at line 1105 of file net.h.

◆ m_nodes_mutex

RecursiveMutex CConnman::m_nodes_mutex
mutableprivate

Definition at line 1106 of file net.h.

◆ m_onion_binds

std::vector<CService> CConnman::m_onion_binds
private

A vector of -bind=<address>:<port>=onion arguments each of which is an address and port that are designated for incoming Tor connections.

Definition at line 1225 of file net.h.

◆ m_peer_connect_timeout

int64_t CConnman::m_peer_connect_timeout
private

Definition at line 1087 of file net.h.

◆ m_start_extra_block_relay_peers

std::atomic_bool CConnman::m_start_extra_block_relay_peers {false}
private

flag for initiating extra block-relay-only peer connections.

this should only be enabled after initial chain sync has occurred, as these connections are intended to be short-lived and low-bandwidth.

Definition at line 1217 of file net.h.

◆ m_try_another_outbound_peer

std::atomic_bool CConnman::m_try_another_outbound_peer
private

flag for deciding to connect to an extra outbound peer, in excess of m_max_outbound_full_relay This takes the place of a feeler connection

Definition at line 1211 of file net.h.

◆ m_use_addrman_outgoing

bool CConnman::m_use_addrman_outgoing
private

Definition at line 1165 of file net.h.

◆ mutexMsgProc

Mutex CConnman::mutexMsgProc
private

Definition at line 1184 of file net.h.

◆ nLastNodeId

std::atomic<NodeId> CConnman::nLastNodeId {0}
private

Definition at line 1107 of file net.h.

◆ nLocalServices

ServiceFlags CConnman::nLocalServices
private

Services this instance offers.

This data is replicated in each CNode instance we create during peer connection (in ConnectNode()) under a member also called nLocalServices.

This data is not marked const, but after being set it should not change. See the note in CNode::nLocalServices documentation.

See also
CNode::nLocalServices

Definition at line 1149 of file net.h.

◆ nMaxAddnode

int CConnman::nMaxAddnode
private

Definition at line 1162 of file net.h.

◆ nMaxConnections

int CConnman::nMaxConnections
private

Definition at line 1153 of file net.h.

◆ nMaxFeeler

int CConnman::nMaxFeeler
private

Definition at line 1163 of file net.h.

◆ nPrevNodeCount

unsigned int CConnman::nPrevNodeCount {0}
private

Definition at line 1108 of file net.h.

◆ nReceiveFloodSize

unsigned int CConnman::nReceiveFloodSize {0}
private

Definition at line 1094 of file net.h.

◆ nSeed0

const uint64_t CConnman::nSeed0
private

SipHasher seeds for deterministic randomness.

Definition at line 1178 of file net.h.

◆ nSeed1

const uint64_t CConnman::nSeed1
private

Definition at line 1178 of file net.h.

◆ nSendBufferMaxSize

unsigned int CConnman::nSendBufferMaxSize {0}
private

Definition at line 1093 of file net.h.

◆ nTotalBytesRecv

std::atomic<uint64_t> CConnman::nTotalBytesRecv {0}
private

Definition at line 1078 of file net.h.

◆ semAddnode

std::unique_ptr<CSemaphore> CConnman::semAddnode
private

Definition at line 1152 of file net.h.

◆ semOutbound

std::unique_ptr<CSemaphore> CConnman::semOutbound
private

Definition at line 1151 of file net.h.

◆ threadDNSAddressSeed

std::thread CConnman::threadDNSAddressSeed
private

Definition at line 1201 of file net.h.

◆ threadI2PAcceptIncoming

std::thread CConnman::threadI2PAcceptIncoming
private

Definition at line 1206 of file net.h.

◆ threadMessageHandler

std::thread CConnman::threadMessageHandler
private

Definition at line 1205 of file net.h.

◆ threadOpenAddedConnections

std::thread CConnman::threadOpenAddedConnections
private

Definition at line 1203 of file net.h.

◆ threadOpenConnections

std::thread CConnman::threadOpenConnections
private

Definition at line 1204 of file net.h.

◆ threadSocketHandler

std::thread CConnman::threadSocketHandler
private

Definition at line 1202 of file net.h.

◆ vhListenSocket

std::vector<ListenSocket> CConnman::vhListenSocket
private

Definition at line 1096 of file net.h.

◆ vWhitelistedRange

std::vector<NetWhitelistPermissions> CConnman::vWhitelistedRange
private

Definition at line 1091 of file net.h.


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