CnxnMgr

abstract class CnxnMgr(val chainSelector: ChainSelector)

The CnxnMgr handles discovery, connection, and maintenance of all connections into the Peer-2-Peer network. This allows higher layers to treat peers as a grab bag of nodes, ignoring issues like reconnecting, periodically cycling connections, and searching for new nodes.

Inheritors

Constructors

Link copied to clipboard
constructor(chainSelector: ChainSelector)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

If the connection state changes, this function will be called

Link copied to clipboard

Get the current list of electrum protocol connections It is better to use the connection getter functions, rather than accessing this list. This is meant for display, health and statistics, rather than access

Link copied to clipboard
abstract val name: String

returns this connection manager's name (typically the blockchain's name). used for logging/debug

Link copied to clipboard
abstract val p2pCnxns: List<P2pClient>

Get the current list of peer-to-peer connections It is better to use the connection getter functions, rather than accessing this list. This is meant for display, health and statistics, rather than access

Link copied to clipboard

Add a callback to handle incoming transactions

Link copied to clipboard
abstract val size: Int

Returns the number of currently connected peers.

Functions

Link copied to clipboard
abstract fun add(inIpp: IpPort, priority: Int, keepForever: Boolean)

Add a potential node into the list of possible connections. If inIpp resolves to multiple addresses, a random one is chosen

abstract fun add(ip: String, port: Int = -1, priority: Int = 0, keepForever: Boolean = false)

Add a potential node into the list of possible connections

Link copied to clipboard
abstract fun addBlockHandler(cb: (List<out iBlockHeader>) -> Unit)

Add a callback to handle incoming blocks -- downcast the parameter to either BCHBlock or MerkleBlock

Link copied to clipboard
abstract fun addBlockHeadersHandler(cb: (List<out iBlockHeader>) -> Unit)

Add a callback to handle incoming block headers

Link copied to clipboard
abstract fun addInvHandler(cb: (List<Inv>) -> Unit)

Add a callback to handle incoming inventory (right now, only blocks, the CnxnMgr auto-handles tx INVs)

Link copied to clipboard
abstract fun addPartialBlockHandler(cb: (List<out iMerkleBlock>) -> Unit)

Add a callback to handle incoming incomplete MerkleBlocks

Link copied to clipboard
abstract fun addTxHandler(cb: (List<out iTransaction>) -> Unit)

Add a callback to handle incoming transactions

Link copied to clipboard
abstract fun broadcastMsg(msg: CapdMsg)
Link copied to clipboard
Link copied to clipboard
abstract fun clear()

clear all incoming messages, drop all connections

Link copied to clipboard
abstract fun clearBanned(ip: String? = null)

clear all bans (if param is null) or clear any ban of the specified IP address

Link copied to clipboard
abstract fun connectedTo(ip: String, port: Int): Boolean

Returns true if we are connected to this node/port

Link copied to clipboard
abstract suspend fun coReport(problemCnxn: P2pClient? = null)

wake up and analyze the health of connections, especially the optional passed connection

Link copied to clipboard
abstract fun exclusiveNodes(nodes: Set<String>?)

Exclusively connect to a single node. All other existing connections will be dropped

Link copied to clipboard

Returns a random connection from the connection manager's node set, but not one of these. Returns null if no connections left

Link copied to clipboard
abstract fun getAnotherNode(notThese: Set<P2pClient>): P2pClient?

Returns a random connection from the connection manager's node set, but not one of these. @returns null if no connections left

Link copied to clipboard
abstract fun getElectrum(): ElectrumClient

Retrieves an electrum connection. Give it back with @ref returnElectrum()

Link copied to clipboard
abstract fun getNode(block: Int = Int.MAX_VALUE): P2pClient

Returns a random connection from the connection manager's node set

Link copied to clipboard
abstract suspend fun getp2p(): P2pClient

Returns a random connection from the connection manager's node set

Link copied to clipboard
abstract fun <T> mapConnections(mapfilter: (P2pClient) -> T?): List<T>

Returns a list of results of your function applied to each connection in this list. Return null to not include this connection in the list. Note that the underlying data structure is synchronized so your function is called with this lock taken

Link copied to clipboard
abstract fun misbehaving(cnxn: P2pClient, reason: BanReason, count: Int = 100)

report a node as having a problem

Link copied to clipboard
abstract fun numPeers(): Int

Returns the number of currently connected peers

Link copied to clipboard
abstract fun preferNodes(nodes: Set<String>?)

Prefer a particular node. An existing connections may be dropped to make room

Link copied to clipboard
abstract fun report(problemCnxn: P2pClient? = null)

wake up and analyze the health of connections, especially the optional passed connection

Link copied to clipboard
abstract fun restart()

Restart connection manager operation after suspend may have killed threads

Link copied to clipboard

Returns an electrum connection. DO NOT USE AFTER RETURNING

Link copied to clipboard
abstract fun sendTransaction(tx: ByteArray)

Send a transaction to one node

Link copied to clipboard
abstract fun sendTransactions(txes: List<ByteArray>): Boolean

Broadcast a set of transactions to the network, returns true if transactions were sent (otherwise no nodes are available).

Link copied to clipboard
abstract fun setAddressFilter(bloom: ByteArray, onBloomInstalled: () -> Unit?)

tell all nodes, including future connections, that we are only interested in things that match this bloom filter. To enable multiple wallets to use the same Blockchain, do NOT use this API directly. Instead use the blockchain API

Link copied to clipboard
abstract fun start()

Start connection manager operation

Link copied to clipboard
abstract fun stop()

Stop connection manager operation