Skip to content
module

neo3.network.node

P2P node. Connects over TCP. Handles network messages.

Classes
Functions
  • encode_base62(num) Encode number in base62, returns a string.
class

neo3.network.node.NeoNode(reader, writer)

P2P network actor.

Methods
  • connection_made() Event called by the NeoNode.connect_to.
  • disconnect(reason) Close the connection to remote endpoint.
  • handler_addr(msg) Handler for a message with the ADDR type.
  • handler_block(msg) Handler for a message with the BLOCK type.
  • handler_consensus(msg) Handler for a message with the CONSENSUS type.
  • handler_extensible(msg) Handler for a message with the EXTENSIBLE type.
  • handler_filteradd(msg) Handler for a message with the FILTERADD type.
  • handler_filterclear(msg) Handler for a message with the FILTERCLEAR type.
  • handler_filterload(msg) Handler for a message with the FILTERLOAD type.
  • handler_getaddr(msg) Handler for a message with the GETADDR type.
  • handler_getblockdata(msg) Handler for a message with the GETBLOCKBYINDEX type.
  • handler_getblocks(msg) Handler for a message with the GETBLOCKS type.
  • handler_getdata(msg) Handler for a message with the GETDATA type.
  • handler_getheaders(msg) Handler for a message with the GETHEADERS type.
  • handler_headers(msg) Handler for a message with the HEADERS type.
  • handler_inv(msg) Handler for a message with the INV type.
  • handler_mempool(msg) Handler for a message with the MEMPOOL type.
  • handler_merkleblock(msg) Handler for a message with the MERKLEBLOCK type.
  • handler_ping(msg) Handler for a message with the PING type.
  • handler_pong(msg) Handler for a message with the PONG type.
  • handler_transaction(msg) Handler for a message with the TRANSACTION type.
  • read_message(timeout) (Optional) Read a message from the network.
  • relay(inv) (bool) Relay the inventory to the network.
  • request_address_list() Send a request for receiving known network addresses.
  • request_block_data(index_start, count) Send a request for count blocks starting from index_start.
  • request_blocks(hash_start, count) Send a request for retrieving block hashes from hash_start to hash_start+count.
  • request_data(type, hashes) Send a request for receiving the specified inventory data.
  • request_headers(index_start, count) Send a request for headers from index_start to index_start+count.
  • send_address_list(network_addresses) Send network addresses.
  • send_headers(headers) Send a list of Header objects.
  • send_inventory(inv_type, inv_hash) Send an inventory to the network.
  • send_message(msg) Broadcast a message to the network.
  • send_ping() Send a Ping message and expecting a Pong response.
  • start_message_handler() A convenience function to start a message reading loop and forward the messages to their respective handlers asconfigured in :attr:~neo3.network.node.NeoNode.dispatch_table.
  • get_address_new() (Optional) Utility function to return the first address with the state NEW.
  • connect_to(host, port, timeout, socket, _test_data) (tuple[NeoNode, None]) Connect to another node.
staticmethod

connect_to(host=None, port=None, timeout=3, socket=None, _test_data=None)

Connect to another node.

Parameters
  • host (Optional, optional) node ip.
  • port (Optional, optional) node port.
  • timeout (optional) max time to wait before aborting.
  • socket (optional) use an existing socket.
Returns (tuple[NeoNode, None])

if connection was established succesfully.tuple[None, tuple[host:port, failure_reason]]: if connection is not established successfully.

method

connection_made()

Event called by the NeoNode.connect_to.

method

disconnect(reason)

Close the connection to remote endpoint.

Parameters
  • reason (DisconnectReason) reason for disconnecting.
classmethod

get_address_new() → Optional

Utility function to return the first address with the state NEW.

method

handler_addr(msg)

Handler for a message with the ADDR type.

method

handler_block(msg)

Handler for a message with the BLOCK type.

method

handler_consensus(msg)

Handler for a message with the CONSENSUS type.

method

handler_extensible(msg)

Handler for a message with the EXTENSIBLE type.

method

handler_filteradd(msg)

Handler for a message with the FILTERADD type.

method

handler_filterclear(msg)

Handler for a message with the FILTERCLEAR type.

method

handler_filterload(msg)

Handler for a message with the FILTERLOAD type.

method

handler_getaddr(msg)

Handler for a message with the GETADDR type.

method

handler_getblockdata(msg)

Handler for a message with the GETBLOCKBYINDEX type.

method

handler_getblocks(msg)

Handler for a message with the GETBLOCKS type.

method

handler_getdata(msg)

Handler for a message with the GETDATA type.

method

handler_getheaders(msg)

Handler for a message with the GETHEADERS type.

method

handler_headers(msg)

Handler for a message with the HEADERS type.

method

handler_inv(msg)

Handler for a message with the INV type.

method

handler_mempool(msg)

Handler for a message with the MEMPOOL type.

method

handler_merkleblock(msg)

Handler for a message with the MERKLEBLOCK type.

method

handler_ping(msg)

Handler for a message with the PING type.

method

handler_pong(msg)

Handler for a message with the PONG type.

method

handler_transaction(msg)

Handler for a message with the TRANSACTION type.

method

read_message(timeout=30) → Optional

Read a message from the network.

Parameters
  • timeout (Optional, optional) maximum time to wait for a message to arrive over the network.
method

relay(inv) → bool

Relay the inventory to the network.

Parameters
  • inv (IInventory) should be of type Block, Transaction or Consensus.

Send a request for receiving known network addresses.

method

request_block_data(index_start, count)

Send a request for count blocks starting from index_start.

Count cannot exceed :attr:~neo3.network.payloads.block.GetBlockByIndexPayload.MAX_BLOCKS_COUNT.

See also: :meth:~neo3.network.node.NeoNode.request_blocks() to only request block hashes.

Parameters
  • index_start block index to start from.
  • count number of blocks to return.
method

request_blocks(hash_start, count=None)

Send a request for retrieving block hashes from hash_start to hash_start+count.

Not specifying a count results in requesting at most 500 blocks.

Note

The remote node is expected to reply with a Message with the :const:~neo3.network.message.MessageType.INV type containing the hashes of the requested blocks. Use :meth:~neo3.network.node.NeoNode.request_data in combination with these hashes to return the actual :class:~neo3.network.payloads.block.Block objects.

See also: NeoNode.request_block_data() to immediately retrieve neo3.network.payloads.block.Block objects.

Parameters
  • hash_start (UInt256) block hash to start from.
  • count (Optional, optional) number of blocks to return.
method

request_data(type, hashes)

Send a request for receiving the specified inventory data.

Parameters
  • type (InventoryType) the inventory type to request.
  • hashes (Sequence) the hashes of type to request.
method

request_headers(index_start, count=2000)

Send a request for headers from index_start to index_start+count.

Not specifying a count results in requesting at most 2000 headers.

Parameters
  • index_start (int) block height to start from.
  • count (int, optional) number of headers to request.
method

send_address_list(network_addresses)

Send network addresses.

Parameters
  • network_addresses (Sequence) list of addresses of other network actors.
method

send_headers(headers)

Send a list of Header objects.

method

send_inventory(inv_type, inv_hash)

Send an inventory to the network.

method

send_message(msg)

Broadcast a message to the network.

method

send_ping()

Send a Ping message and expecting a Pong response.

A convenience function to start a message reading loop and forward the messages to their respective handlers asconfigured in :attr:~neo3.network.node.NeoNode.dispatch_table.

function

neo3.network.node.encode_base62(num)

Encode number in base62, returns a string.