3.0.ipv8.peerdiscovery.network ============================== .. py:module:: 3.0.ipv8.peerdiscovery.network Attributes ---------- .. autoapisummary:: 3.0.ipv8.peerdiscovery.network.MID 3.0.ipv8.peerdiscovery.network.PublicKeyMat 3.0.ipv8.peerdiscovery.network.Service 3.0.ipv8.peerdiscovery.network.ServiceSet Classes ------- .. autoapisummary:: 3.0.ipv8.peerdiscovery.network.WalkableAddress 3.0.ipv8.peerdiscovery.network.PeerObserver 3.0.ipv8.peerdiscovery.network.Network Module Contents --------------- .. py:data:: MID .. py:data:: PublicKeyMat .. py:data:: Service .. py:data:: ServiceSet .. py:class:: WalkableAddress Bases: :py:obj:`NamedTuple` A walkable address. .. py:attribute:: introduced_by :type: bytes .. py:attribute:: services :type: bytes | None .. py:attribute:: new_style :type: bool .. py:class:: PeerObserver An observer that gets called back when a peer is added or removed from the Network. .. py:method:: on_peer_added(peer: 3.0.ipv8.types.Peer) -> None :abstractmethod: A given peer was added to the Network. .. py:method:: on_peer_removed(peer: 3.0.ipv8.types.Peer) -> None :abstractmethod: A given peer was removed from the Network. .. py:class:: Network A class that stores Peer instances and their various states and interconnections. .. py:attribute:: _all_addresses :type: dict[3.0.ipv8.types.Address, WalkableAddress] All known IP:port addresses, mapped to (introduction peer, services, new_style). .. py:attribute:: verified_peers :type: set[3.0.ipv8.types.Peer] All verified Peer objects (Peer.address must be in _all_addresses). .. py:attribute:: verified_by_public_key_bin :type: dict[PublicKeyMat, 3.0.ipv8.types.Peer] Map of known public keys to Peer objects. .. py:attribute:: graph_lock Lock for all updates of the peer pool. .. py:attribute:: blacklist :type: list[3.0.ipv8.types.Address] :value: [] Peers we should not add to the network (e.g., bootstrap peers), by address. .. py:attribute:: blacklist_mids :type: list[MID] :value: [] Peers we should not add to the network (e.g., bootstrap peers), by mid. .. py:attribute:: services_per_peer :type: dict[PublicKeyMat, ServiceSet] Map of advertised services (set) per peer. .. py:attribute:: service_overlays :type: dict[Service, 3.0.ipv8.types.Overlay] Map of service identifiers to local overlays. .. py:attribute:: reverse_ip_cache_size :value: 500 .. py:attribute:: reverse_ip_lookup :type: collections.OrderedDict[3.0.ipv8.types.Address, 3.0.ipv8.types.Peer] Cache of IP:port -> Peer. This is a cache rather than a normal dictionary (the addresses of a peer are temporal and can grow infinitely): we rotate out old information to avoid a memory leak. .. py:attribute:: reverse_intro_cache_size :value: 500 .. py:attribute:: reverse_intro_lookup :type: collections.OrderedDict[3.0.ipv8.types.Peer, list[3.0.ipv8.types.Address]] Map of Peer -> [IP:port], reversing the information from _all_addresses. This is a cache rather than a normal dictionary (the addresses of a peer are temporal and can grow infinitely): we rotate out old information to avoid a memory leak. .. py:attribute:: reverse_service_cache_size :value: 500 .. py:attribute:: reverse_service_lookup :type: collections.OrderedDict[Service, list[3.0.ipv8.types.Peer]] Cache of service_id -> [Peer]. This is a cache rather than a normal dictionary (the services of a peer may be temporal and can grow infinitely): we rotate out old information to avoid a memory leak. .. py:attribute:: peer_observers :type: set[PeerObserver] Set of observers for peer addition and removal. .. py:method:: is_new_style(address: 3.0.ipv8.types.Address) -> bool Check if an address supports new-style introduction requests and responses. :param address: the address to check for. :returns: True iff the address is both known and known to support new-style introductions. .. py:method:: discover_address(peer: 3.0.ipv8.types.Peer, address: 3.0.ipv8.types.Address, service: Service | None = None, new_style: bool = False) -> None A peer has introduced us to another IP address. :param peer: the peer that performed the introduction. :param address: the introduced address. :param service: the service through which we discovered the peer. :param new_style: the introduced address uses new introduction logic. .. py:method:: discover_services(peer: 3.0.ipv8.types.Peer, services: collections.abc.Iterable) -> None A peer has advertised some services he can use. :param peer: the peer to update the services for. :param services: the list of services to register. .. py:method:: add_verified_peer(peer: 3.0.ipv8.types.Peer) -> None The holepunching layer has a new peer for us. :param peer: the new peer. .. py:method:: register_service_provider(service_id: Service, overlay: 3.0.ipv8.types.Overlay) -> None Register an overlay to provide a certain service id. :param service_id: the name/id of the service. :param overlay: the actual service. .. py:method:: get_peers_for_service(service_id: Service) -> list[3.0.ipv8.types.Peer] Get peers which support a certain service. :param service_id: the service name/id to fetch peers for. .. py:method:: get_services_for_peer(peer: 3.0.ipv8.types.Peer) -> set[bytes] Get the known services supported by a peer. :param peer: the peer to check services for. .. py:method:: get_walkable_addresses(service_id: Service | None = None, old_style: bool = False) -> list[3.0.ipv8.types.Address] Get all addresses ready to be walked to. :param service_id: the service_id to filter on. :param old_style: only return addresses that are not new-style. .. py:method:: get_verified_by_address(address: 3.0.ipv8.types.Address) -> 3.0.ipv8.types.Peer | None Get a verified Peer by its IP address. If multiple Peers use the same IP address, this method returns only one of these peers. :param address: the (IP, port) tuple to search for :return: the Peer object for this address or None .. py:method:: get_verified_by_public_key_bin(public_key_bin: PublicKeyMat) -> 3.0.ipv8.types.Peer | None Get a verified Peer by its public key bin. :param public_key_bin: the string representation of the public key :return: the Peer object for this public_key_bin or None .. py:method:: get_introductions_from(peer: 3.0.ipv8.types.Peer) -> list[3.0.ipv8.types.Address] Get the addresses introduced to us by a certain peer. :param peer: the peer to get the introductions for :return: a list of the introduced addresses (ip, port) .. py:method:: remove_by_address(address: 3.0.ipv8.types.Address) -> None Remove all walkable addresses and verified peers using a certain IP address. :param address: the (ip, port) address to remove .. py:method:: remove_peer(peer: 3.0.ipv8.types.Peer) -> None Remove a verified peer. :param peer: the Peer to remove .. py:method:: snapshot() -> bytes Get a snapshot of all verified peers. :return: the serialization (bytes) of all verified peers .. py:method:: load_snapshot(snapshot: bytes) -> None Load a snapshot into the walkable addresses. This method will prefer returning no peers over throwing an Exception. :param snapshot: the snapshot (created by snapshot()) .. py:method:: add_peer_observer(observer: PeerObserver) -> None Add a peer observer to notify about peer addition and removal. :param observer: the observer to register. :returns: None .. py:method:: remove_peer_observer(observer: PeerObserver) -> None Remove a registered peer observer. It will no longer receive notifications. :param observer: the observer to unregister. :returns: None