3.0.ipv8.peer ============= .. py:module:: 3.0.ipv8.peer Classes ------- .. autoapisummary:: 3.0.ipv8.peer.DirtyDict 3.0.ipv8.peer.Peer Module Contents --------------- .. py:class:: DirtyDict(**kwargs) Bases: :py:obj:`dict` Dictionary that becomes dirty when elements are changed. .. py:attribute:: dirty :value: True .. py:method:: __setitem__(key: Any, value: Any) -> None Callback for when an item is set to a value. This dirties the dict. .. py:method:: update(mapping: collections.abc.Mapping, **kwargs) -> None Callback for when another mapping is merged into this dict. This dirties the dict. .. py:method:: clear() -> None Callback for when all items are removed. This dirties the dict. .. py:method:: pop(key: Any) -> Any Callback for when a particular item is popped. This dirties the dict. .. py:method:: popitem() -> Any Callback for when an item is popped. This dirties the dict. .. py:class:: Peer(key: 3.0.ipv8.keyvault.keys.Key | bytes, address: 3.0.ipv8.types.Address | None = None, intro: bool = True) A public key that has additional information attached to it (like an IP address, measured RTT, etc.). .. py:attribute:: INTERFACE_ORDER .. py:attribute:: public_key .. py:attribute:: mid .. py:attribute:: _addresses .. py:attribute:: _address .. py:attribute:: creation_time .. py:attribute:: last_response .. py:attribute:: _lamport_timestamp :value: 0 .. py:attribute:: pings :type: collections.deque .. py:attribute:: new_style_intro :value: False .. py:attribute:: address_frozen :value: False Set this to True if you want to avoid this Peer's address being updated. .. py:property:: addresses :type: dict[type[3.0.ipv8.types.Address], 3.0.ipv8.types.Address] Retrieve the addresses belonging to this Peer. You are not allowed to set this addresses dict for a Peer manually. You can change the dictionary itself by setting its items or calling its functions, for example ``update()``. .. py:property:: address :type: 3.0.ipv8.types.Address Retrieve the preferred address for this Peer. If you want to manually select the interface, use the ``.addresses`` dictionary instead. .. py:method:: add_address(value: Any) -> None Add a known address for this Peer. Any object can form an address, but only one type of address can be used per object type. For example (normally A, B and C are ``namedtuple`` types): - Adding instances A(1), B(2) leads to addresses {A: A(1), B: B(2)} - Adding instances A(1), B(2), A(3) leads to addresses {A: A(3), B: B(2)} .. py:method:: _update_preferred_address() -> None Update the current address to be the most preferred. .. py:method:: get_median_ping() -> float | None Get the median ping time of this peer. :return: the median ping or None if no measurements were performed yet :rtype: float or None .. py:method:: get_average_ping() -> float | None Get the average ping time of this peer. :return: the average ping or None if no measurements were performed yet :rtype: float or None .. py:method:: update_clock(timestamp: int) -> None Update the Lamport timestamp for this peer. The Lamport clock dictates that the current timestamp is the maximum of the last known and the most recently delivered timestamp. This is useful when messages are delivered asynchronously. We also keep a real time timestamp of the last received message for timeout purposes. :param timestamp: a received timestamp .. py:method:: get_lamport_timestamp() -> int Get the Lamport timestamp of this peer. .. py:method:: __hash__() -> int Generate a hash based on the mid of this peer. .. py:method:: __eq__(other: object) -> bool Check if the other instance is a peer with the same public key. .. py:method:: __ne__(other: object) -> bool Check if the other instance is NOT a peer with the same public key. .. py:method:: __str__() -> str Represent this peer as a human-readable string.