py-libp2p/libp2p/peer/peerdata_interface.py

86 lines
2.0 KiB
Python
Raw Normal View History

from abc import ABC, abstractmethod
2019-08-01 06:00:12 +08:00
from typing import Any, List, Sequence
2019-07-27 16:27:01 +08:00
from multiaddr import Multiaddr
2019-11-26 12:27:59 +08:00
from libp2p.crypto.keys import PrivateKey, PublicKey
2019-07-30 15:31:02 +08:00
from .peermetadata_interface import IPeerMetadata
2019-01-10 02:38:56 +08:00
class IPeerData(ABC):
@abstractmethod
2019-07-27 16:27:01 +08:00
def get_protocols(self) -> List[str]:
"""
:return: all protocols associated with given peer
"""
@abstractmethod
2019-07-27 16:27:01 +08:00
def add_protocols(self, protocols: Sequence[str]) -> None:
"""
:param protocols: protocols to add
"""
@abstractmethod
2019-07-27 16:27:01 +08:00
def set_protocols(self, protocols: Sequence[str]) -> None:
"""
2019-11-26 12:27:59 +08:00
:param protocols: protocols to set
"""
@abstractmethod
2019-07-27 16:27:01 +08:00
def add_addrs(self, addrs: Sequence[Multiaddr]) -> None:
"""
:param addrs: multiaddresses to add
"""
@abstractmethod
2019-07-27 16:27:01 +08:00
def get_addrs(self) -> List[Multiaddr]:
"""
:return: all multiaddresses
"""
@abstractmethod
2019-07-27 16:27:01 +08:00
def clear_addrs(self) -> None:
"""Clear all addresses."""
@abstractmethod
2019-07-30 15:31:02 +08:00
def put_metadata(self, key: str, val: Any) -> None:
"""
:param key: key in KV pair
:param val: val to associate with key
"""
@abstractmethod
2019-07-30 15:31:02 +08:00
def get_metadata(self, key: str) -> IPeerMetadata:
"""
:param key: key in KV pair
:return: val for key
2019-11-26 12:27:59 +08:00
:raise PeerDataError: key not found
"""
@abstractmethod
def add_pubkey(self, pubkey: PublicKey) -> None:
"""
:param pubkey:
"""
@abstractmethod
def get_pubkey(self) -> PublicKey:
"""
:return: public key of the peer
:raise PeerDataError: if public key not found
"""
@abstractmethod
def add_privkey(self, privkey: PrivateKey) -> None:
"""
:param privkey:
"""
@abstractmethod
def get_privkey(self) -> PrivateKey:
"""
:return: private key of the peer
:raise PeerDataError: if private key not found
"""