3.0.ipv8.messaging.interfaces.dispatcher.endpoint ================================================= .. py:module:: 3.0.ipv8.messaging.interfaces.dispatcher.endpoint Attributes ---------- .. autoapisummary:: 3.0.ipv8.messaging.interfaces.dispatcher.endpoint.INTERFACES 3.0.ipv8.messaging.interfaces.dispatcher.endpoint.PREFERENCE_ORDER 3.0.ipv8.messaging.interfaces.dispatcher.endpoint.FAST_ADDR_TO_INTERFACE Classes ------- .. autoapisummary:: 3.0.ipv8.messaging.interfaces.dispatcher.endpoint.DispatcherEndpoint Functions --------- .. autoapisummary:: 3.0.ipv8.messaging.interfaces.dispatcher.endpoint.guess_interface Module Contents --------------- .. py:data:: INTERFACES The INTERFACES dictionary describes the mapping of interface names to interface classes. .. py:data:: PREFERENCE_ORDER :value: ['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. .. py:data:: FAST_ADDR_TO_INTERFACE :type: 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. .. py:function:: 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. .. py:class:: DispatcherEndpoint(interfaces: list[str], **kwargs) Bases: :py:obj:`3.0.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. .. py:attribute:: interfaces .. py:attribute:: interface_order .. py:attribute:: _preferred_interface .. py:property:: bytes_up :type: int Get the number of bytes sent over this endpoint. .. py:property:: bytes_down :type: int Get the number of bytes received over this endpoint. .. py:method:: add_listener(listener: 3.0.ipv8.messaging.interfaces.endpoint.EndpointListener) -> None Reroute a listener to all the interfaces we dispatch to. .. py:method:: add_prefix_listener(listener: 3.0.ipv8.messaging.interfaces.endpoint.EndpointListener, prefix: bytes) -> None Reroute a prefix listener to all the interfaces we dispatch to. .. py:method:: remove_listener(listener: 3.0.ipv8.messaging.interfaces.endpoint.EndpointListener) -> None Remove a listener from all the interfaces we dispatch to. .. py:method:: notify_listeners(packet: tuple[ipv8.types.Address, bytes]) -> None Dispatch a new packet to all interfaces. .. py:method:: assert_open() -> None Perform an assert that we are opened. .. py:method:: is_open() -> bool Check if we have ANY open interface. .. py:method:: get_address(interface: str | None = None) -> ipv8.types.Address Get the most likely interface for our interfaces. .. py:method:: 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. .. py:method:: open() -> bool :async: Open all interfaces. .. py:method:: close() -> None :async: Close all interfaces. .. py:method:: reset_byte_counters() -> None Reset our counters.