libp2p.discovery.rendezvous module
Rendezvous protocol implementation for py-libp2p.
This module provides both client and server implementations of the rendezvous protocol, allowing peers to advertise themselves and discover other peers through a centralized rendezvous point.
- exception libp2p.discovery.rendezvous.InternalError(message: str = 'Internal server error')
Bases:
RendezvousErrorRaised when server encounters internal error.
- exception libp2p.discovery.rendezvous.InvalidCookieError(message: str = 'Invalid cookie')
Bases:
RendezvousErrorRaised when discovery cookie is invalid.
- exception libp2p.discovery.rendezvous.InvalidNamespaceError(message: str = 'Invalid namespace')
Bases:
RendezvousErrorRaised when namespace is invalid.
- exception libp2p.discovery.rendezvous.InvalidPeerInfoError(message: str = 'Invalid peer info')
Bases:
RendezvousErrorRaised when peer information is invalid.
- exception libp2p.discovery.rendezvous.InvalidTTLError(message: str = 'Invalid TTL')
Bases:
RendezvousErrorRaised when TTL is invalid.
- exception libp2p.discovery.rendezvous.NotAuthorizedError(message: str = 'Not authorized')
Bases:
RendezvousErrorRaised when operation is not authorized.
- class libp2p.discovery.rendezvous.RendezvousClient(host: IHost, rendezvous_peer: ID, enable_refresh: bool = False)
Bases:
objectRendezvous client for registering with and discovering peers through a rendezvous point.
- async discover(namespace: str, limit: int = 100, cookie: bytes = b'') tuple[list[PeerInfo], bytes]
Discover peers in a namespace.
- Args:
namespace: Namespace to search limit: Maximum number of peers to return cookie: Pagination cookie from previous request
- Returns:
Tuple of (peer list, new cookie for pagination)
- Raises:
RendezvousError: If discovery fails
- async register(namespace: str, ttl: int = 7200) float
Register this peer under a namespace.
- Args:
namespace: Namespace to register under ttl: Time-to-live in seconds (default 2 hours)
- Returns:
Actual TTL granted by the server
- Raises:
RendezvousError: If registration fails
- class libp2p.discovery.rendezvous.RendezvousDiscovery(host: IHost, rendezvous_peer: ID, enable_refresh: bool = False)
Bases:
objectRendezvous-based peer discovery.
This class provides a high-level interface for peer discovery using the rendezvous protocol, including caching. Registration refresh is handled automatically by the underlying RendezvousClient.
- async advertise(namespace: str, ttl: int = 7200) float
Advertise this peer under a namespace.
- Args:
namespace: Namespace to advertise under ttl: Time-to-live in seconds (default 2 hours)
- Returns:
Actual TTL granted by the server
- clear_cache(namespace: str | None = None) None
Clear peer cache.
- Args:
namespace: Specific namespace to clear, or None for all
- async find_all_peers(namespace: str) list[PeerInfo]
Find all peers in a namespace using pagination.
- Args:
namespace: Namespace to search
- Returns:
List of all discovered peers
- async find_peers(namespace: str, limit: int = 100, force_refresh: bool = False) AsyncIterator[PeerInfo]
Find peers in a namespace.
- Args:
namespace: Namespace to search limit: Maximum number of peers to return force_refresh: Force refresh from server instead of using cache
- Yields:
PeerInfo objects for discovered peers
- exception libp2p.discovery.rendezvous.RendezvousError(status: int, message: str = '')
Bases:
ExceptionBase exception for rendezvous protocol errors.
- class libp2p.discovery.rendezvous.RendezvousService(host: IHost)
Bases:
objectRendezvous service for hosting a rendezvous point.
This service allows peers to register under namespaces and discover other peers that have registered under the same namespaces.
Bases:
RendezvousErrorRaised when service is unavailable.
Submodules
libp2p.discovery.rendezvous.client module
Rendezvous client implementation.
- class libp2p.discovery.rendezvous.client.RendezvousClient(host: IHost, rendezvous_peer: ID, enable_refresh: bool = False)
Bases:
objectRendezvous client for registering with and discovering peers through a rendezvous point.
- async discover(namespace: str, limit: int = 100, cookie: bytes = b'') tuple[list[PeerInfo], bytes]
Discover peers in a namespace.
- Args:
namespace: Namespace to search limit: Maximum number of peers to return cookie: Pagination cookie from previous request
- Returns:
Tuple of (peer list, new cookie for pagination)
- Raises:
RendezvousError: If discovery fails
- async register(namespace: str, ttl: int = 7200) float
Register this peer under a namespace.
- Args:
namespace: Namespace to register under ttl: Time-to-live in seconds (default 2 hours)
- Returns:
Actual TTL granted by the server
- Raises:
RendezvousError: If registration fails
libp2p.discovery.rendezvous.service module
Rendezvous service implementation for hosting a rendezvous point.
- class libp2p.discovery.rendezvous.service.RegistrationRecord(peer_id: ID, addrs: list[bytes], namespace: str, ttl: int)
Bases:
objectRepresents a peer registration record.
libp2p.discovery.rendezvous.discovery module
Rendezvous discovery implementation that conforms to py-libp2p’s discovery interface.
- class libp2p.discovery.rendezvous.discovery.PeerCache
Bases:
objectCache for discovered peers with TTL management.
- class libp2p.discovery.rendezvous.discovery.RendezvousDiscovery(host: IHost, rendezvous_peer: ID, enable_refresh: bool = False)
Bases:
objectRendezvous-based peer discovery.
This class provides a high-level interface for peer discovery using the rendezvous protocol, including caching. Registration refresh is handled automatically by the underlying RendezvousClient.
- async advertise(namespace: str, ttl: int = 7200) float
Advertise this peer under a namespace.
- Args:
namespace: Namespace to advertise under ttl: Time-to-live in seconds (default 2 hours)
- Returns:
Actual TTL granted by the server
- clear_cache(namespace: str | None = None) None
Clear peer cache.
- Args:
namespace: Specific namespace to clear, or None for all
- async find_all_peers(namespace: str) list[PeerInfo]
Find all peers in a namespace using pagination.
- Args:
namespace: Namespace to search
- Returns:
List of all discovered peers
- async find_peers(namespace: str, limit: int = 100, force_refresh: bool = False) AsyncIterator[PeerInfo]
Find peers in a namespace.
- Args:
namespace: Namespace to search limit: Maximum number of peers to return force_refresh: Force refresh from server instead of using cache
- Yields:
PeerInfo objects for discovered peers
libp2p.discovery.rendezvous.config module
Configuration constants for the rendezvous protocol implementation.
This module contains all protocol constants, limits, and configuration values used throughout the rendezvous implementation.
libp2p.discovery.rendezvous.messages module
Message construction helpers for rendezvous protocol.
- libp2p.discovery.rendezvous.messages.create_discover_message(namespace: str, limit: int = 0, cookie: bytes = b'') Message
Create a DISCOVER message.
- libp2p.discovery.rendezvous.messages.create_discover_response_message(registrations: list[Register], cookie: bytes = b'', status: int = 0, status_text: str = '') Message
Create a DISCOVER_RESPONSE message.
- libp2p.discovery.rendezvous.messages.create_register_message(namespace: str, peer_id: ID, addrs: list[Multiaddr], ttl: int) Message
Create a REGISTER message.
- libp2p.discovery.rendezvous.messages.create_register_response_message(status: int, status_text: str = '', ttl: int = 0) Message
Create a REGISTER_RESPONSE message.