latest.ipv8.messaging.interfaces.endpoint

Exceptions

IllegalEndpointListenerError

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

EndpointClosedException

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

DataTooBigException

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

IllegalDestination

Exception raised when trying to send to the 0 address.

Classes

Endpoint

Interface for sending messages over the Internet.

EndpointListener

Handler for messages coming in through an Endpoint.

Module Contents

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

Interface for sending messages over the Internet.

_logger
_listeners: list[EndpointListener] = []
_prefix_map: dict[bytes, list[EndpointListener]]
prefixlen: int = 22
listener_update_lock: threading.RLock
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.messaging.interfaces.udp.endpoint.Address, bytes]) None

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

notify_listeners(packet: tuple[latest.ipv8.messaging.interfaces.udp.endpoint.Address, bytes]) None

Send data to all listeners.

abstractmethod assert_open() None

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

Raises:

Exception – if this endpoint is not open.

abstractmethod is_open() bool

Whether this endpoint is open.

abstractmethod get_address() latest.ipv8.messaging.interfaces.udp.endpoint.Address

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

abstractmethod send(socket_address: latest.ipv8.messaging.interfaces.udp.endpoint.Address, packet: bytes) None

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

abstractmethod open() bool
Async:

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

abstractmethod close() None | collections.abc.Awaitable

Close this endpoint as quick as possible.

abstractmethod 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.

_use_main_thread = True
endpoint
_my_estimated_lan: latest.ipv8.messaging.interfaces.udp.endpoint.Address | None = None
my_estimated_wan = ('::1', 0)
property my_estimated_lan: latest.ipv8.messaging.interfaces.udp.endpoint.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.

abstractmethod on_packet(packet: tuple[latest.ipv8.messaging.interfaces.udp.endpoint.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.

property is_ipv6_listener: bool

Whether we are on an IPv6 address.

_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.messaging.interfaces.udp.endpoint.Address

Get the IPv6 address of our endpoint.

_get_lan_address(bootstrap: bool = False) latest.ipv8.messaging.interfaces.udp.endpoint.Address

Attempt to get the newest lan ip of this machine.

_guess_lan_address(addresses: collections.abc.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.