neo3.network.convenience.nodemanager
P2P network node manager.
NodeManager
— Convenience class that helps establish and maintain a pool of active connections to NEO nodes.It will track the node quality and swap them out if considered bad as to always try and keep a healty pool.
neo3.network.convenience.nodemanager.
NodeManager
(
*args
, **kwds
)
Convenience class that helps establish and maintain a pool of active connections to NEO nodes.It will track the node quality and swap them out if considered bad as to always try and keep a healty pool.
Attention: This class is singleton.
max_clients
— THe maximum number of clients to have connected at any time.min_clients
—Nodemanager.MAX_NODE_ERROR_COUNT
times then recovery logic will trigger.nodes
(list) — A list of nodes that we're actively using to request data from.queued_addresses
(A list of host) — port addresses that have a task pending to connect to, but are not fully processed.
get_least_failed_node
(
ri
)
(Optional) — Return the node with the least fail count for the target item as specified in the RequestInfo.get_node_addresses
(
)
(list) — Return the addresses of connected nodes.get_node_by_nodeid
(
nodeid
)
(Optional) — Return the node instance matching the provided nodeid.get_node_with_height
(
height
)
(Optional) — Return a node that has a chain height of at leastheight
.increase_node_error_count
(
nodeid
)
— Utility function to increase a node'serror_response_count
param by 1 and disconnect the node if it exceedsthe threshold set byNodeManager.MAX_NODE_ERROR_COUNT
.increase_node_timeout_count
(
nodeid
)
— Utility function to increase a node'stimeout_count
param by 1 and disconnect the node if it exceeds thethreshold set byNodeManager.MAX_NODE_ERROR_COUNT
.shutdown
(
)
— Gracefully shutdown the node manager.start
(
)
— Start the node manager services.
get_least_failed_node
(
ri
)
Return the node with the least fail count for the target item as specified in the RequestInfo.
ri
(RequestInfo) — the info object indicating which header or block we filter on.
None if there are no connected nodes that can provide the target information as specified in the RequestInfo.Node instance with the lowest failure count.
get_node_addresses
(
)
→ list
Return the addresses of connected nodes.
get_node_by_nodeid
(
nodeid
)
→ Optional
Return the node instance matching the provided nodeid.
get_node_with_height
(
height
)
Return a node that has a chain height of at least height
.
height
(int) — the minimal block height a node must have.
None if there are no nodes in the current pool that match the criteria.Node instance sorted by weight to avoid hitting the same node every time.
increase_node_error_count
(
nodeid
)
Utility function to increase a node's error_response_count
param by 1 and disconnect the node if it exceedsthe threshold set by NodeManager.MAX_NODE_ERROR_COUNT
.
nodeid
(`NeoNode.nodeid`) — the specific node to update.
increase_node_timeout_count
(
nodeid
)
Utility function to increase a node's timeout_count
param by 1 and disconnect the node if it exceeds thethreshold set by NodeManager.MAX_NODE_ERROR_COUNT
.
nodeid
(`NeoNode.nodeid`) — the specific node to update.
shutdown
(
)
Gracefully shutdown the node manager.
Disconnects all active nodes and stops service tasks.
Note
This depents on asyncio's Task canceling logic. It waits for all tasks to be cancelled and/or stopped before returning.
start
(
)
Start the node manager services.
This does 2 things.
1. Connect to the seed list addresses provided in the configuration.
2. Try to maintain a pool of connected nodes according to the `min/max clients` configuration settings and
monitor that they don't get stuck.