3.0.ipv8.test.mocking.endpoint ============================== .. py:module:: 3.0.ipv8.test.mocking.endpoint Attributes ---------- .. autoapisummary:: 3.0.ipv8.test.mocking.endpoint.internet Classes ------- .. autoapisummary:: 3.0.ipv8.test.mocking.endpoint.MockEndpoint 3.0.ipv8.test.mocking.endpoint.AddressTester 3.0.ipv8.test.mocking.endpoint.AutoMockEndpoint 3.0.ipv8.test.mocking.endpoint.MockEndpointListener Functions --------- .. autoapisummary:: 3.0.ipv8.test.mocking.endpoint.crash_event_loop Module Contents --------------- .. py:data:: internet .. py:function:: crash_event_loop(forwarded_exception: Exception) -> None :async: Raise an exception on the event loop. :param forwarded_exception: the exception instance to raise. .. py:class:: MockEndpoint(lan_address: 3.0.ipv8.types.Address, wan_address: 3.0.ipv8.types.Address) Bases: :py:obj:`3.0.ipv8.messaging.interfaces.endpoint.Endpoint` Endpoint that registers an address in the "internet" dictionary instead of using The Internet. .. py:attribute:: SEND_INET_EXCEPTION_TO_LOOP :value: True Raise an uncaught AssertionError on the ``asyncio`` event loop if attempting to send to an unknown address. Useful for use in defensively-programmed code: bypasses most exception handling. .. py:attribute:: lan_address .. py:attribute:: wan_address .. py:attribute:: _port .. py:attribute:: _open :value: False .. py:method:: assert_open() -> None Throw an assertion error if this endpoint is not open. .. py:method:: is_open() -> bool Check if this endpoint is open. .. py:method:: get_address() -> 3.0.ipv8.types.Address Get our own registered WAN address. .. py:method:: send(socket_address: 3.0.ipv8.types.Address, packet: bytes) -> None Route a message through the "internet" dictionary. WARNING: We schedule a call on the event loop. Otherwise, you can easily create infinite loops! .. py:method:: open() -> None Set this endpoint to be open. .. py:method:: close(timeout: float = 0.0) -> None Close this endpoint. .. py:method:: reset_byte_counters() -> None Reset our byte counters (we have none). .. py:class:: AddressTester(endpoint: 3.0.ipv8.messaging.interfaces.endpoint.Endpoint) Bases: :py:obj:`3.0.ipv8.messaging.interfaces.endpoint.EndpointListener` Generating addresses that are on our physical machine's actual physical LAN can lead to issues. .. py:attribute:: singleton :value: None .. py:method:: get_singleton(endpoint: 3.0.ipv8.messaging.interfaces.endpoint.Endpoint) -> AddressTester :classmethod: Create a singleton AddressTester, you only need one. .. py:method:: on_packet(packet: tuple[3.0.ipv8.types.Address, bytes]) -> None This should never be called. .. py:method:: is_lan(address: str) -> bool Check if the given address is on our physical LAN. .. py:class:: AutoMockEndpoint Bases: :py:obj:`MockEndpoint` Randomly generate LAN + WAN addresses that are globally unique and register them in the "internet" dictionary. .. py:attribute:: IPV6_ADDRESSES .. py:attribute:: _open :value: False .. py:attribute:: _port :value: 0 .. py:method:: _generate_address() -> 3.0.ipv8.messaging.interfaces.udp.endpoint.UDPv4Address | 3.0.ipv8.messaging.interfaces.udp.endpoint.UDPv6Address .. py:method:: _is_lan(address: 3.0.ipv8.types.Address) -> bool Avoid false positives for the actual machine's lan. .. py:method:: _generate_unique_address() -> 3.0.ipv8.types.Address .. py:class:: MockEndpointListener(endpoint: 3.0.ipv8.messaging.interfaces.endpoint.Endpoint, main_thread: bool = False) Bases: :py:obj:`3.0.ipv8.messaging.interfaces.endpoint.EndpointListener` Listener that simply stores all data sent to it. .. py:attribute:: received_packets :value: [] .. py:method:: on_packet(packet: tuple[3.0.ipv8.types.Address, bytes]) -> None Callback for when packets are received: simply store them.