latest.ipv8.peerdiscovery.network

Module Contents

Classes

WalkableAddress

A walkable address.

PeerObserver

An observer that gets called back when a peer is added or removed from the Network.

Network

A class that stores Peer instances and their various states and interconnections.

Attributes

MID

PublicKeyMat

Service

ServiceSet

latest.ipv8.peerdiscovery.network.MID
latest.ipv8.peerdiscovery.network.PublicKeyMat
latest.ipv8.peerdiscovery.network.Service
latest.ipv8.peerdiscovery.network.ServiceSet
class latest.ipv8.peerdiscovery.network.WalkableAddress

Bases: NamedTuple

A walkable address.

introduced_by: bytes
services: bytes | None
new_style: bool
class latest.ipv8.peerdiscovery.network.PeerObserver

An observer that gets called back when a peer is added or removed from the Network.

abstract on_peer_added(peer: latest.ipv8.types.Peer) None

A given peer was added to the Network.

abstract on_peer_removed(peer: latest.ipv8.types.Peer) None

A given peer was removed from the Network.

class latest.ipv8.peerdiscovery.network.Network

A class that stores Peer instances and their various states and interconnections.

_all_addresses: dict[latest.ipv8.types.Address, WalkableAddress]

All known IP:port addresses, mapped to (introduction peer, services, new_style).

verified_peers: set[latest.ipv8.types.Peer]

All verified Peer objects (Peer.address must be in _all_addresses).

verified_by_public_key_bin: dict[PublicKeyMat, latest.ipv8.types.Peer]

Map of known public keys to Peer objects.

graph_lock

Lock for all updates of the peer pool.

blacklist: list[latest.ipv8.types.Address] = []

Peers we should not add to the network (e.g., bootstrap peers), by address.

blacklist_mids: list[MID] = []

Peers we should not add to the network (e.g., bootstrap peers), by mid.

services_per_peer: dict[PublicKeyMat, ServiceSet]

Map of advertised services (set) per peer.

service_overlays: dict[Service, latest.ipv8.types.Overlay]

Map of service identifiers to local overlays.

reverse_ip_lookup: collections.OrderedDict[latest.ipv8.types.Address, latest.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.

reverse_intro_lookup: collections.OrderedDict[latest.ipv8.types.Peer, list[latest.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.

reverse_service_lookup: collections.OrderedDict[Service, list[latest.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.

peer_observers: set[PeerObserver]

Set of observers for peer addition and removal.

is_new_style(address: latest.ipv8.types.Address) bool

Check if an address supports new-style introduction requests and responses.

Parameters:

address – the address to check for.

Returns:

True iff the address is both known and known to support new-style introductions.

discover_address(peer: latest.ipv8.types.Peer, address: latest.ipv8.types.Address, service: Service | None = None, new_style: bool = False) None

A peer has introduced us to another IP address.

Parameters:
  • peer – the peer that performed the introduction.

  • address – the introduced address.

  • service – the service through which we discovered the peer.

  • new_style – the introduced address uses new introduction logic.

discover_services(peer: latest.ipv8.types.Peer, services: Iterable) None

A peer has advertised some services he can use.

Parameters:
  • peer – the peer to update the services for.

  • services – the list of services to register.

add_verified_peer(peer: latest.ipv8.types.Peer) None

The holepunching layer has a new peer for us.

Parameters:

peer – the new peer.

register_service_provider(service_id: Service, overlay: latest.ipv8.types.Overlay) None

Register an overlay to provide a certain service id.

Parameters:
  • service_id – the name/id of the service.

  • overlay – the actual service.

get_peers_for_service(service_id: Service) list[latest.ipv8.types.Peer]

Get peers which support a certain service.

Parameters:

service_id – the service name/id to fetch peers for.

get_services_for_peer(peer: latest.ipv8.types.Peer) set[bytes]

Get the known services supported by a peer.

Parameters:

peer – the peer to check services for.

get_walkable_addresses(service_id: Service | None = None, old_style: bool = False) list[latest.ipv8.types.Address]

Get all addresses ready to be walked to.

Parameters:
  • service_id – the service_id to filter on.

  • old_style – only return addresses that are not new-style.

get_verified_by_address(address: latest.ipv8.types.Address) latest.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.

Parameters:

address – the (IP, port) tuple to search for

Returns:

the Peer object for this address or None

get_verified_by_public_key_bin(public_key_bin: PublicKeyMat) latest.ipv8.types.Peer | None

Get a verified Peer by its public key bin.

Parameters:

public_key_bin – the string representation of the public key

Returns:

the Peer object for this public_key_bin or None

get_introductions_from(peer: latest.ipv8.types.Peer) list[latest.ipv8.types.Address]

Get the addresses introduced to us by a certain peer.

Parameters:

peer – the peer to get the introductions for

Returns:

a list of the introduced addresses (ip, port)

remove_by_address(address: latest.ipv8.types.Address) None

Remove all walkable addresses and verified peers using a certain IP address.

Parameters:

address – the (ip, port) address to remove

remove_peer(peer: latest.ipv8.types.Peer) None

Remove a verified peer.

Parameters:

peer – the Peer to remove

snapshot() bytes

Get a snapshot of all verified peers.

Returns:

the serialization (bytes) of all verified peers

load_snapshot(snapshot: bytes) None

Load a snapshot into the walkable addresses.

This method will prefer returning no peers over throwing an Exception.

Parameters:

snapshot – the snapshot (created by snapshot())

add_peer_observer(observer: PeerObserver) None

Add a peer observer to notify about peer addition and removal.

Parameters:

observer – the observer to register.

Returns:

None

remove_peer_observer(observer: PeerObserver) None

Remove a registered peer observer. It will no longer receive notifications.

Parameters:

observer – the observer to unregister.

Returns:

None