MultiNodeCnxnMgr

class MultiNodeCnxnMgr(val name: String, netType: ChainSelector, seed: Array<IpPort>) : CommonCnxnMgr

A connection manager that handles connections to multiple nodes

Constructors

Link copied to clipboard
constructor(name: String, netType: ChainSelector, seed: Array<IpPort>)

Properties

Link copied to clipboard

Tell peers to only be interested in things that match this bloom

Link copied to clipboard
val bannedLock: iMutex

Don't reconnect to these nodes

Link copied to clipboard
Link copied to clipboard

a block has arrived. This could be a BCHBlock or a MerkleBlock

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
val cnxnLock: iGate

All current connections

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

What index in the sorted list of prospects are we on

Link copied to clipboard
val dataLock: iGate
Link copied to clipboard

Maintain this many connections to the bitcoin network

Link copied to clipboard

Active seeders

Link copied to clipboard

True if the connection manager should stop operating & clean up any threads

Link copied to clipboard
Link copied to clipboard
open override val electrumCnxns: List<ElectrumClient>

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
val electrumConnectionPacer: LeakyBucket
Link copied to clipboard
Link copied to clipboard

supply electrum server ip and ports if we need them

Link copied to clipboard

a block header has arrived

Link copied to clipboard

This connection is coming up

Link copied to clipboard
var invCallback: (List<Inv>) -> Unit?

a notification of an object's existence has arrived

Link copied to clipboard
open override val name: String

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

Link copied to clipboard

If a seeder was supplied, store its domain name here

Link copied to clipboard
open override 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

A partially complete MerkleBlock arrived

Link copied to clipboard

if this is not null, try all communications to this connection first

Link copied to clipboard
Link copied to clipboard
var processingThread: iThread?
Link copied to clipboard

once we get into 0 priority prospects, if the length of prospects is this number then loop back to 0. This stops us from trying more than a few unlikely connections (provided by ADDR messages)

Link copied to clipboard
Link copied to clipboard
val reconnectTimer: LeakyBucket

schedule connection retries: we'll take 5 per retry, so this results in a try every 5 seconds on average, but you can build up a max of 5 quick tries.

Link copied to clipboard
open override val rejectHandler: Callbacker<RejectInfo>

Add a callback to handle incoming transactions

Link copied to clipboard
Link copied to clipboard
open override val size: Int

Returns the number of currently connected peers.

Link copied to clipboard

If fully connected, close a connection whose average latency is this (in milliseconds) to free up space for something faster

Link copied to clipboard

If a message of a certain type comes in, call this callback with the message for processing

Link copied to clipboard
val wakingDelay: iGate

Functions

Link copied to clipboard

Return a list of connections that are active (either connected or being initialized)

Link copied to clipboard
open override fun add(inIpp: IpPort, priority: Int, keepForever: Boolean)
open override fun add(ip: String, port: Int, priority: Int, keepForever: Boolean)

Add a new possible P2P connection into the manager

Link copied to clipboard
open override 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
open override fun addBlockHeadersHandler(cb: (List<out iBlockHeader>) -> Unit)

Add a callback to handle incoming block headers

Link copied to clipboard
open override 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
open override fun addPartialBlockHandler(cb: (List<out iMerkleBlock>) -> Unit)

Add a callback to handle incoming incomplete MerkleBlocks

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

Add a callback to handle incoming transactions

Link copied to clipboard
fun awaitAvailable(maxDelay: Long): Boolean
Link copied to clipboard
fun ban(nodeIp: String, bd: BanData)

Do not connect to this node again (until the ban list is cleared

Link copied to clipboard
open override fun broadcastMsg(msg: CapdMsg)
Link copied to clipboard
open override fun broadcastTransaction(tx: ByteArray)
Link copied to clipboard

Go through the connection list, removing any dead connections (called automatically)

Link copied to clipboard
open override fun clear()

clear all incoming messages, drop all connections

Link copied to clipboard
open override fun clearBanned(ip: String?)

remove a node (or all nodes if ip==null) from the ban table

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

Returns true if we are connected to this node/port

Link copied to clipboard
open suspend override fun coReport(problemCnxn: P2pClient?)

wake up and analyze my connections, especially the optional passed connection

Link copied to clipboard

disconnect from the lowest N performing peers

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

Configure exclusive nodes. Use null to remove them. If some exclusive nodes are defined, the connection manager will only connect to them.

Link copied to clipboard
fun find(name: String, portp: Int = -1): P2pClient?

Given a name and port, return the connection if we have one, or null if we don't. This includes pending connections

Link copied to clipboard
open override fun getAnotherElectrum(notThese: Set<ElectrumClient>): ElectrumClient?

Returns a random connection from the connection manager's node set, but not one of these. Returns null if no connections left. You must return any received connection back (when finished with it via returnElecturm

Link copied to clipboard
open override 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
open override fun getElectrum(): ElectrumClient

Returns a random connection from the connection manager's node set. Tries 10 candidates then throws @ref ElectrumNoNodesException You must return the connection back to the connection manager via returnElectrum

Link copied to clipboard
open override fun getNode(block: Int): P2pClient

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

Link copied to clipboard
open suspend override fun getp2p(): P2pClient

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

Link copied to clipboard

Loops looking for an alive connection, returns null if no connections are left

Link copied to clipboard
Link copied to clipboard

Return a list of connections that are being initialized

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

Returns a list of connected peers. This API works simultaneously as map (transformation) and filter functions and calls the passed function on every item in the connection list.

Link copied to clipboard
open override fun misbehaving(cnxn: P2pClient, reason: BanReason, count: Int)

report a node as having a problem

Link copied to clipboard
open override fun numPeers(): Int

Returns the number of currently connected peers

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

Configure preferred nodes. Use null to remove an existing one. The connection manager always tries to connect to and use preferred nodes, but will also connect to other nodes.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun report(problemCnxn: P2pClient?)

wake up and analyze my connections, especially the optional passed connection

Link copied to clipboard
open override fun restart()

Restart connection manager operation after suspend may have killed threads

Link copied to clipboard
open override fun returnElectrum(e: ElectrumClient)

After calling getElectrum, give it back to the connection manager for reuse or to be cleaned up

Link copied to clipboard
open override fun sendTransaction(tx: ByteArray)

Send a transaction to one node

Link copied to clipboard
open override 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
open override 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
open override fun start()

Start the connection manager processing thread

Link copied to clipboard
open override fun stop()

Stop the connection manager processing thread asynchronously

Link copied to clipboard
open override fun toString(): String