latest.ipv8.messaging.interfaces.endpoint

Module Contents

Classes

Endpoint

Interface for sending messages over the Internet.

EndpointListener

Handler for messages coming in through an Endpoint.

class latest.ipv8.messaging.interfaces.endpoint.Endpoint(prefixlen: int = 22)

Interface for sending messages over the Internet.

add_listener(listener: EndpointListener) None

Add an EndpointListener to our listeners.

Raises:

IllegalEndpointListenerError if the provided listener is not an EndpointListener

add_prefix_listener(listener: EndpointListener, prefix: bytes) None

Add an EndpointListener to our listeners, only triggers on packets with a specific prefix.

Raises:

IllegalEndpointListenerError if the provided listener is not an EndpointListener

remove_listener(listener: EndpointListener) None

Remove a listener from our listeners, if it is registered.

_deliver_later(listener: EndpointListener, packet: tuple[latest.ipv8.types.Address, bytes]) None

Ensure that the listener is still loaded when delivering the packet later.

notify_listeners(packet: tuple[latest.ipv8.types.Address, bytes]) None

Send data to all listeners.

abstract assert_open() None

Crash with an exception (explaining the situation) if this endpoint is not opened.

Raises:

Exception – if this endpoint is not open.

abstract is_open() bool

Whether this endpoint is open.

abstract get_address() latest.ipv8.types.Address

Get the MOST LIKELY external address for this endpoint. This is often wrong!

abstract send(socket_address: latest.ipv8.types.Address, packet: bytes) None

Try to send data to some address. No delivery guarantees.

abstract async open() bool

Attempt to open this endpoint and return if this was successful.

abstract close() None | Awaitable

Close this endpoint as quick as possible.

abstract reset_byte_counters() None

Reset any internal byte counting mechanisms.

class latest.ipv8.messaging.interfaces.endpoint.EndpointListener(endpoint: Endpoint, main_thread: bool = True)

Handler for messages coming in through an Endpoint.

property my_estimated_lan: latest.ipv8.types.Address

Estimate our LAN address and port.

If the endpoint is closed this returns (“::1”, 0) for IPv6 and (“0.0.0.0”, 0) otherwise. If the endpoint is open and we have no idea what our address is, attempt to estimate it. Otherwise, return the current value of the estimated LAN address and port.

property use_main_thread: bool

Does the callback of this listener need to be executed on the main thread.

property is_ipv6_listener: bool

Whether we are on an IPv6 address.

abstract on_packet(packet: tuple[latest.ipv8.types.Address, bytes]) None

Callback for when data is received on this endpoint.

Parameters:

packet – the received packet, in (source, binary string) format.

_is_ipv6_address(address: str) bool

Whether the supplied address is IPv6.

_address_in_subnet(address: str, subnet: tuple[str, int]) bool

Checks whether a given address is in a given subnet.

Parameters:
  • address – an ip v4 address as a string formatted as four pairs of decimals separated by dots

  • subnet – a tuple consisting of the main address of the subnet formatted as above, and the subnet

formatted as an int with the number of significant bits in the address. :return: True if the address is in the subnet, False otherwise

address_in_lan_subnets(address: str) bool

Whether the given address exists in any common lan subnet.

address_is_lan(address: str) bool

Whether the given address is a lan address.

get_ipv6_address() latest.ipv8.types.Address

Get the IPv6 address of our endpoint.

_get_lan_address(bootstrap: bool = False) latest.ipv8.types.Address

Attempt to get the newest lan ip of this machine.

_guess_lan_address(addresses: Iterable[str]) str

Chooses the most likely Interface instance out of INTERFACES to use as our LAN address.

exception latest.ipv8.messaging.interfaces.endpoint.IllegalEndpointListenerError(other: object)

Bases: RuntimeError

Exception raised when an EndpointListener instance was expected, but not supplied.

exception latest.ipv8.messaging.interfaces.endpoint.EndpointClosedException(endpoint: Endpoint)

Bases: Exception

Exception raised when an endpoint is expected to be open, but is closed.

exception latest.ipv8.messaging.interfaces.endpoint.DataTooBigException(size: int, max_size: int)

Bases: Exception

Exception raised when the data being sent exceeds the maximum size.

exception latest.ipv8.messaging.interfaces.endpoint.IllegalDestination

Bases: Exception

Exception raised when trying to send to the 0 address.