neo3.network.node
P2P node. Connects over TCP. Handles network messages.
NeoNode
— P2P network actor.
encode_base62
(
num
)
— Encode number in base62, returns a string.
neo3.network.node.
NeoNode
(
reader
, writer
)
P2P network actor.
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 theADDR
type.handler_block
(
msg
)
— Handler for a message with theBLOCK
type.handler_consensus
(
msg
)
— Handler for a message with theCONSENSUS
type.handler_extensible
(
msg
)
— Handler for a message with theEXTENSIBLE
type.handler_filteradd
(
msg
)
— Handler for a message with theFILTERADD
type.handler_filterclear
(
msg
)
— Handler for a message with theFILTERCLEAR
type.handler_filterload
(
msg
)
— Handler for a message with theFILTERLOAD
type.handler_getaddr
(
msg
)
— Handler for a message with theGETADDR
type.handler_getblockdata
(
msg
)
— Handler for a message with theGETBLOCKBYINDEX
type.handler_getblocks
(
msg
)
— Handler for a message with theGETBLOCKS
type.handler_getdata
(
msg
)
— Handler for a message with theGETDATA
type.handler_getheaders
(
msg
)
— Handler for a message with theGETHEADERS
type.handler_headers
(
msg
)
— Handler for a message with theHEADERS
type.handler_inv
(
msg
)
— Handler for a message with theINV
type.handler_mempool
(
msg
)
— Handler for a message with theMEMPOOL
type.handler_merkleblock
(
msg
)
— Handler for a message with theMERKLEBLOCK
type.handler_ping
(
msg
)
— Handler for a message with thePING
type.handler_pong
(
msg
)
— Handler for a message with thePONG
type.handler_transaction
(
msg
)
— Handler for a message with theTRANSACTION
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 forcount
blocks starting fromindex_start
.request_blocks
(
hash_start
,count
)
— Send a request for retrieving block hashes fromhash_start
tohash_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 fromindex_start
toindex_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.
connect_to
(
host=None
, port=None
, timeout=3
, socket=None
, _test_data=None
)
Connect to another node.
host
(Optional, optional) — node ip.port
(Optional, optional) — node port.timeout
(optional) — max time to wait before aborting.socket
(optional) — use an existing socket.
if connection was established succesfully.tuple[None, tuple[host:port, failure_reason]]: if connection is not established successfully.
connection_made
(
)
Event called by the NeoNode.connect_to.
disconnect
(
reason
)
Close the connection to remote endpoint.
reason
(DisconnectReason) — reason for disconnecting.
get_address_new
(
)
→ Optional
Utility function to return the first address with the state NEW.
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=30
)
→ Optional
Read a message from the network.
timeout
(Optional, optional) — maximum time to wait for a message to arrive over the network.
relay
(
inv
)
→ bool
Relay the inventory to the network.
inv
(IInventory) — should be of type Block, Transaction or Consensus.
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
.
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.
index_start
— block index to start from.count
— number of blocks to return.
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.
hash_start
(UInt256) — block hash to start from.count
(Optional, optional) — number of blocks to return.
request_data
(
type
, hashes
)
Send a request for receiving the specified inventory data.
type
(InventoryType) — the inventory type to request.hashes
(Sequence) — the hashes oftype
to request.
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.
index_start
(int) — block height to start from.count
(int, optional) — number of headers to request.
send_address_list
(
network_addresses
)
Send network addresses.
network_addresses
(Sequence) — list of addresses of other network actors.
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
.
neo3.network.node.
encode_base62
(
num
)
Encode number in base62, returns a string.