2018-10-20 16:55:37 -04:00
|
|
|
from abc import ABC, abstractmethod
|
2019-07-31 15:00:12 -07:00
|
|
|
from typing import Any, List, Sequence
|
2019-07-27 16:27:01 +08:00
|
|
|
|
|
|
|
from multiaddr import Multiaddr
|
2018-10-20 16:55:37 -04:00
|
|
|
|
2019-07-30 15:31:02 +08:00
|
|
|
from .peermetadata_interface import IPeerMetadata
|
|
|
|
|
2019-01-09 21:38:56 +03:00
|
|
|
|
2018-10-20 16:55:37 -04:00
|
|
|
class IPeerData(ABC):
|
2018-11-02 16:16:46 -04:00
|
|
|
@abstractmethod
|
2019-07-27 16:27:01 +08:00
|
|
|
def get_protocols(self) -> List[str]:
|
2018-11-02 16:16:46 -04:00
|
|
|
"""
|
|
|
|
:return: all protocols associated with given peer
|
|
|
|
"""
|
2018-10-20 16:55:37 -04:00
|
|
|
|
2018-11-02 16:16:46 -04:00
|
|
|
@abstractmethod
|
2019-07-27 16:27:01 +08:00
|
|
|
def add_protocols(self, protocols: Sequence[str]) -> None:
|
2018-11-02 16:16:46 -04:00
|
|
|
"""
|
|
|
|
:param protocols: protocols to add
|
|
|
|
"""
|
2018-10-20 16:55:37 -04:00
|
|
|
|
2018-11-02 16:16:46 -04:00
|
|
|
@abstractmethod
|
2019-07-27 16:27:01 +08:00
|
|
|
def set_protocols(self, protocols: Sequence[str]) -> None:
|
2018-11-02 16:16:46 -04:00
|
|
|
"""
|
|
|
|
:param protocols: protocols to add
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
2019-07-27 16:27:01 +08:00
|
|
|
def add_addrs(self, addrs: Sequence[Multiaddr]) -> None:
|
2018-11-02 16:16:46 -04:00
|
|
|
"""
|
|
|
|
:param addrs: multiaddresses to add
|
|
|
|
"""
|
2018-10-20 16:55:37 -04:00
|
|
|
|
2018-11-02 16:16:46 -04:00
|
|
|
@abstractmethod
|
2019-07-27 16:27:01 +08:00
|
|
|
def get_addrs(self) -> List[Multiaddr]:
|
2018-11-02 16:16:46 -04:00
|
|
|
"""
|
|
|
|
:return: all multiaddresses
|
|
|
|
"""
|
2018-10-20 16:55:37 -04:00
|
|
|
|
2018-11-02 16:16:46 -04:00
|
|
|
@abstractmethod
|
2019-07-27 16:27:01 +08:00
|
|
|
def clear_addrs(self) -> None:
|
2018-11-02 16:16:46 -04:00
|
|
|
"""
|
|
|
|
Clear all addresses
|
|
|
|
"""
|
2018-10-20 16:55:37 -04:00
|
|
|
|
2018-11-02 16:16:46 -04:00
|
|
|
@abstractmethod
|
2019-07-30 15:31:02 +08:00
|
|
|
def put_metadata(self, key: str, val: Any) -> None:
|
2018-11-02 16:16:46 -04:00
|
|
|
"""
|
|
|
|
:param key: key in KV pair
|
|
|
|
:param val: val to associate with key
|
|
|
|
:raise Exception: unsuccesful put
|
|
|
|
"""
|
2018-10-20 16:55:37 -04:00
|
|
|
|
2018-11-02 16:16:46 -04:00
|
|
|
@abstractmethod
|
2019-07-30 15:31:02 +08:00
|
|
|
def get_metadata(self, key: str) -> IPeerMetadata:
|
2018-11-02 16:16:46 -04:00
|
|
|
"""
|
|
|
|
:param key: key in KV pair
|
|
|
|
:return: val for key
|
|
|
|
:raise Exception: key not found
|
|
|
|
"""
|