Manages all P2P connections: opening, accepting, servicing and tearing them down.

Synopsis

Declared in <net.h>

class CConnman;

Types

Name

Description

Options

Configuration options used to start a CConnman.

PrivateBroadcast

Group of private broadcast related members.

Type Aliases

Name

Description

NodeFn

Callback type invoked for each node by ForEachNode.

Member Functions

Name

Description

CConnman [constructor]

Construct a connection manager with the given randomness seeds and dependencies.

~CConnman [destructor]

Destroy the connection manager, stopping any remaining activity.

ASMapHealthCheck

Log a warning if the configured ASMap looks unhealthy.

AddConnection

Attempts to open a connection. Currently only used from tests.

AddLocalServices

Updates the local services that this node advertises to other peers during connection handshake.

AddNode

Add a manually added node, returning false if it was already present.

AddedNodesContain

Return whether the given address matches one of the manually added nodes.

CheckIncomingNonce

Return whether the given nonce differs from every outbound connection's local nonce.

DisconnectNode

DisconnectNode overloads

EvictTxPeerIfFull

If we are at capacity for inbound tx‐relay peers, attempt to evict one.

ForEachNode

ForEachNode overloads

ForNode

Invoke a callback on the node with the given id, if it is fully connected.

GetAddedNodeInfo

Return connection info for all manually added nodes.

GetAddresses

Return addresses from the per‐requestor cache. If no cache entry exists, it is populated with randomly selected addresses. This function can be used in untrusted contexts.

GetAddressesUnsafe

Return randomly selected addresses. This function does not use the address response cache and should only be used in trusted contexts.

GetDeterministicRandomizer

Get a unique deterministic randomizer.

GetExtraBlockRelayCount

Return the number of block‐relay‐only peers we have over our limit.

GetExtraFullOutboundCount

Return the number of outbound peers we have in excess of our target.

GetFullOutboundConnCount

Return the number of full‐relay outbound peers we have.

GetLocalServices

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

GetMappedAS

Return the autonomous system number the given address maps to.

GetMaxOutboundTarget

Return the configured maximum number of bytes to upload per cycle (0 = unlimited).

GetMaxOutboundTimeLeftInCycle

Return the time left in the current max‐outbound cycle (0 if there is no limit).

GetMaxOutboundTimeframe

Return the length of a max‐outbound cycle.

GetNetworkActive

Return whether networking is currently active.

GetNodeCount

Return the number of connections in the given direction (inbound, outbound, or both).

GetNodeStats

Collect per‐peer statistics into the given vector.

GetNodesMutex

Return the mutex guarding the node list (for thread‐safety annotations only).

GetOutboundTargetBytesLeft

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

GetTotalBytesRecv

Return the total number of bytes received across all connections.

GetTotalBytesSent

Return the total number of bytes sent across all connections.

GetTryNewOutboundPeer

Return whether we are currently trying to open an extra outbound peer.

GetUseAddrmanOutgoing

Return whether outgoing peers are selected via the address manager.

Init

Apply the given options to this connection manager.

Interrupt

Interrupt any blocking operations so the manager can shut down.

MultipleManualOrFullOutboundConns

Return whether we have more than one manual or full‐relay connection to the given network.

OpenNetworkConnection

Open a new P2P connection and initialize it with the PeerManager at m_msgproc.

OutboundTargetReached

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

PushMessage

Queue a serialized message to be sent to the given node.

RemoveAddedNode

Remove a manually added node, returning false if it was not present.

RemoveLocalServices

Removes service flags from the ones this node advertises to peers.

SetCaptureMessages

Enable or disable message capture (test only).

SetNetworkActive

Enable or disable networking activity.

SetTryNewOutboundPeer

Set whether to try opening an extra outbound peer beyond the normal target.

ShouldRunInactivityChecks

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

Start

Start the connection manager and its worker threads.

StartExtraBlockRelayPeers

Begin opening extra block‐relay‐only peer connections.

Stop

Stop the connection manager: stop the threads, then the nodes.

StopNodes

Disconnect and delete all nodes.

StopThreads

Stop and join all worker threads.

WakeMessageHandler

Wake the message handling thread so it processes pending work.

getNetLocalAddresses

Return a copy of our known local addresses and their service info.

Data Members

Name

Description

m_private_broadcast

Group of private broadcast related members.

Friends

Name

Description

ConnmanTestMsg

Test harness that exposes CConnman internals for unit tests.

Non-Member Functions

Name

Description

EnsureConnman

Get the connection manager from a node context, asserting it is present.

Created with MrDocs