address — Network address classes

This module contains several classes for working with network addresses.

The AddrPayload is used to share NetworkAddresses with other nodes. A NetworkAddress is not just a wrapper around a hostname and port but also holds attributes for labelling its performance using the AddressState enum and a list of capabilities it has (more next).

Not all nodes in the network have similar performance when it comes to responding to network requests. There are many reasons for this such as geographical location and hardware (disk/cpu/memory) in relationship to the amount of connected nodes. In processes like chain syncing one might want to track a node’s performance to ensure the best response times. The network convenience classes do exactly this.

The node listening on a particular address can run a variety of services such as an RPC server, Websocket server or TCP/IPv4 server. This information is shared during the initial handshake with a node (see version), included in the network address state and shared with other nodes asking for addresses (see requesting address list). This allows one to filter addresses based on the specific services it offers.

class neo3.network.payloads.AddrPayload(addresses)

Bases: neo3.core.serialization.ISerializable

deserialize(reader)

Deserialize the object from a binary stream.

Parameters

reader (BinaryReader) – instance.

Return type

None

classmethod deserialize_from_bytes(data)

Parse data into an object instance.

Parameters

data (Union[bytes, bytearray]) – hex escaped bytes.

Return type

~ISerializable_T

Returns

a deserialized instance of the class.

serialize(writer)

Serialize the object into a binary stream.

Parameters

writer (BinaryWriter) – instance.

Return type

None

to_array()

Serialize the object into a bytearray.

Return type

bytes

class neo3.network.payloads.NetworkAddress(address, capabilities=None, timestamp=None, state=<AddressState.NEW: 0>)

Bases: neo3.core.serialization.ISerializable

Create an instance.

deserialize(reader)

Deserialize the object from a binary stream.

Parameters

reader (BinaryReader) – instance.

Return type

None

serialize(writer)

Serialize the object into a binary stream.

Parameters

writer (BinaryWriter) – instance.

Return type

None

set_state_connected()
Return type

None

set_state_dead()
Return type

None

set_state_new()
Return type

None

set_state_poor()
Return type

None

property ip
Return type

str

property is_state_connected
Return type

bool

property is_state_dead
Return type

bool

property is_state_new
Return type

bool

property is_state_poor
Return type

bool

property port
Return type

int

class neo3.network.payloads.DisconnectReason(value)

Bases: enum.IntEnum

Reason for disconnecting a node.

Will also be broadcasted back to the node when this PR is merged. For now only used internally with logging.

HANDSHAKE_VERACK_ERROR = 5
HANDSHAKE_VERSION_ERROR = 4
IPFILTER_NOT_ALLOWED = 3
MAX_CONNECTIONS_REACHED = 1
POOR_PERFORMANCE = 2
SHUTTING_DOWN = 6
UNKNOWN = 0
class neo3.network.payloads.AddressState(value)

Bases: enum.IntEnum

Node state

Used for tracking remote address state.

CONNECTED = 1

an address that is associated with a live node and performing OK.

DEAD = 3

an address that could not be resolved or connected to due to a timeout.

NEW = 0

an address that has not been used before in the current connection cycle.

POOR = 2

an address from a node that has been disconnected from due to

  • bad performance

  • malformed data or protocol responses

  • or max connections reached reasons.