latest.ipv8.messaging.interfaces.endpoint
Module Contents
Classes
Interface for sending messages over the Internet. |
|
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 get_address() latest.ipv8.types.Address
Get the MOST LIKELY external address for this endpoint. This is often wrong!
- 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.
- 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.
- _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.
- get_ipv6_address() latest.ipv8.types.Address
Get the IPv6 address of our endpoint.
- 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.