latest.ipv8.messaging.interfaces.dispatcher.endpoint

Module Contents

Classes

DispatcherEndpoint

An Endpoint implementation to dispatch to other Endpoint implementations.

Functions

guess_interface(→ str | None)

Attempt to guess the interface for the given address.

Attributes

INTERFACES

The INTERFACES dictionary describes the mapping of interface names to interface classes.

PREFERENCE_ORDER

The PREFERENCE_ORDER list describes the order of preference for the available interfaces.

FAST_ADDR_TO_INTERFACE

The FAST_ADDR_TO_INTERFACE is an internal DispatcherEndpoint mapping, to quickly route information.

latest.ipv8.messaging.interfaces.dispatcher.endpoint.INTERFACES

The INTERFACES dictionary describes the mapping of interface names to interface classes.

latest.ipv8.messaging.interfaces.dispatcher.endpoint.PREFERENCE_ORDER = ['UDPIPv4', 'UDPIPv6']

The PREFERENCE_ORDER list describes the order of preference for the available interfaces. For example, ["UDPIPv4", "UDPIPv6"] means: use IPv4 over IPv6, if it is available.

latest.ipv8.messaging.interfaces.dispatcher.endpoint.FAST_ADDR_TO_INTERFACE: dict[type, str]

The FAST_ADDR_TO_INTERFACE is an internal DispatcherEndpoint mapping, to quickly route information. For addresses which do not use these classes the slower guess_interface will be used.

latest.ipv8.messaging.interfaces.dispatcher.endpoint.guess_interface(socket_address: Any) str | None

Attempt to guess the interface for the given address.

If the given address is a tuple of a valid IPv4 address string and a port this returns “UDPIPv4”. If the given address is a tuple of a valid IPv6 address string and a port this returns “UDPIPv6”. Otherwise, this returns None.

class latest.ipv8.messaging.interfaces.dispatcher.endpoint.DispatcherEndpoint(interfaces: list[str], **kwargs)

Bases: latest.ipv8.messaging.interfaces.endpoint.Endpoint

An Endpoint implementation to dispatch to other Endpoint implementations.

The added complexity is as follows:

  • Receiving of packets is hooked directly into the sub-Endpoints, no speed is lost.

  • Sending packets will be directed to the appropriate interface. If an address object class is not defined in FAST_ADDR_TO_INTERFACE, this will have to use guess_interface.

  • Adding and removing listeners will have to be forwarded to all sub-Endpoints.

property bytes_up: int

Get the number of bytes sent over this endpoint.

property bytes_down: int

Get the number of bytes received over this endpoint.

add_listener(listener: latest.ipv8.messaging.interfaces.endpoint.EndpointListener) None

Reroute a listener to all the interfaces we dispatch to.

add_prefix_listener(listener: latest.ipv8.messaging.interfaces.endpoint.EndpointListener, prefix: bytes) None

Reroute a prefix listener to all the interfaces we dispatch to.

remove_listener(listener: latest.ipv8.messaging.interfaces.endpoint.EndpointListener) None

Remove a listener from all the interfaces we dispatch to.

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

Dispatch a new packet to all interfaces.

assert_open() None

Perform an assert that we are opened.

is_open() bool

Check if we have ANY open interface.

get_address(interface: str | None = None) ipv8.types.Address

Get the most likely interface for our interfaces.

send(socket_address: ipv8.types.Address, packet: bytes, interface: str | None = None) None

Send a packet to a given address over the most likely interface, or a given interface.

async open() bool

Open all interfaces.

async close() None

Close all interfaces.

reset_byte_counters() None

Reset our counters.