3.0.ipv8.messaging.interfaces.endpoint ====================================== .. py:module:: 3.0.ipv8.messaging.interfaces.endpoint Exceptions ---------- .. autoapisummary:: 3.0.ipv8.messaging.interfaces.endpoint.IllegalEndpointListenerError 3.0.ipv8.messaging.interfaces.endpoint.EndpointClosedException 3.0.ipv8.messaging.interfaces.endpoint.DataTooBigException 3.0.ipv8.messaging.interfaces.endpoint.IllegalDestination Classes ------- .. autoapisummary:: 3.0.ipv8.messaging.interfaces.endpoint.Endpoint 3.0.ipv8.messaging.interfaces.endpoint.EndpointListener Module Contents --------------- .. py:class:: Endpoint(prefixlen: int = 22) Interface for sending messages over the Internet. .. py:attribute:: _logger .. py:attribute:: _listeners :type: list[EndpointListener] :value: [] .. py:attribute:: _prefix_map :type: dict[bytes, list[EndpointListener]] .. py:attribute:: prefixlen :type: int .. py:attribute:: listener_update_lock :type: threading.RLock .. py:method:: add_listener(listener: EndpointListener) -> None Add an EndpointListener to our listeners. :raises: IllegalEndpointListenerError if the provided listener is not an EndpointListener .. py:method:: 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 .. py:method:: remove_listener(listener: EndpointListener) -> None Remove a listener from our listeners, if it is registered. .. py:method:: _deliver_later(listener: EndpointListener, packet: tuple[3.0.ipv8.types.Address, bytes]) -> None Ensure that the listener is still loaded when delivering the packet later. .. py:method:: notify_listeners(packet: tuple[3.0.ipv8.types.Address, bytes]) -> None Send data to all listeners. .. py:method:: assert_open() -> None :abstractmethod: Crash with an exception (explaining the situation) if this endpoint is not opened. :raises Exception: if this endpoint is not open. .. py:method:: is_open() -> bool :abstractmethod: Whether this endpoint is open. .. py:method:: get_address() -> 3.0.ipv8.types.Address :abstractmethod: Get the MOST LIKELY external address for this endpoint. This is often wrong! .. py:method:: send(socket_address: 3.0.ipv8.types.Address, packet: bytes) -> None :abstractmethod: Try to send data to some address. No delivery guarantees. .. py:method:: open() -> bool :abstractmethod: :async: Attempt to open this endpoint and return if this was successful. .. py:method:: close() -> None | collections.abc.Awaitable :abstractmethod: Close this endpoint as quick as possible. .. py:method:: reset_byte_counters() -> None :abstractmethod: Reset any internal byte counting mechanisms. .. py:class:: EndpointListener(endpoint: Endpoint, main_thread: bool = True) Handler for messages coming in through an Endpoint. .. py:attribute:: _use_main_thread .. py:attribute:: endpoint .. py:attribute:: _my_estimated_lan :value: None .. py:attribute:: my_estimated_wan .. py:property:: my_estimated_lan :type: 3.0.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. .. py:property:: use_main_thread :type: bool Does the callback of this listener need to be executed on the main thread. .. py:method:: on_packet(packet: tuple[3.0.ipv8.types.Address, bytes]) -> None :abstractmethod: Callback for when data is received on this endpoint. :param packet: the received packet, in (source, binary string) format. .. py:method:: _is_ipv6_address(address: str) -> bool Whether the supplied address is IPv6. .. py:property:: is_ipv6_listener :type: bool Whether we are on an IPv6 address. .. py:method:: _address_in_subnet(address: str, subnet: tuple[str, int]) -> bool Checks whether a given address is in a given subnet. :param address: an ip v4 address as a string formatted as four pairs of decimals separated by dots :param 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 .. py:method:: address_in_lan_subnets(address: str) -> bool Whether the given address exists in any common lan subnet. .. py:method:: address_is_lan(address: str) -> bool Whether the given address is a lan address. .. py:method:: get_ipv6_address() -> 3.0.ipv8.types.Address Get the IPv6 address of our endpoint. .. py:method:: _get_lan_address(bootstrap: bool = False) -> 3.0.ipv8.types.Address Attempt to get the newest lan ip of this machine. .. py:method:: _guess_lan_address(addresses: collections.abc.Iterable[str]) -> str Chooses the most likely Interface instance out of INTERFACES to use as our LAN address. .. py:exception:: IllegalEndpointListenerError(other: object) Bases: :py:obj:`RuntimeError` Exception raised when an EndpointListener instance was expected, but not supplied. .. py:exception:: EndpointClosedException(endpoint: Endpoint) Bases: :py:obj:`Exception` Exception raised when an endpoint is expected to be open, but is closed. .. py:exception:: DataTooBigException(size: int, max_size: int) Bases: :py:obj:`Exception` Exception raised when the data being sent exceeds the maximum size. .. py:exception:: IllegalDestination Bases: :py:obj:`Exception` Exception raised when trying to send to the 0 address.