2018-11-27 07:24:29 +08:00
|
|
|
from abc import abstractmethod
|
2019-07-27 16:27:01 +08:00
|
|
|
from typing import (
|
|
|
|
List,
|
|
|
|
Sequence,
|
|
|
|
)
|
2019-01-10 02:38:56 +08:00
|
|
|
|
2019-07-27 16:27:01 +08:00
|
|
|
|
|
|
|
from .id import ID
|
|
|
|
from .peerinfo import PeerInfo
|
2018-10-22 03:15:53 +08:00
|
|
|
from .addrbook_interface import IAddrBook
|
2018-10-21 04:55:15 +08:00
|
|
|
from .peermetadata_interface import IPeerMetadata
|
|
|
|
|
2019-01-10 02:38:56 +08:00
|
|
|
|
2018-11-03 04:16:46 +08:00
|
|
|
class IPeerStore(IAddrBook, IPeerMetadata):
|
2018-10-21 04:55:15 +08:00
|
|
|
|
2019-07-27 16:27:01 +08:00
|
|
|
def __init__(self) -> None:
|
2018-10-27 03:51:25 +08:00
|
|
|
IPeerMetadata.__init__(self)
|
|
|
|
IAddrBook.__init__(self)
|
2018-10-21 04:55:15 +08:00
|
|
|
|
2018-10-22 03:15:53 +08:00
|
|
|
@abstractmethod
|
2019-07-27 16:27:01 +08:00
|
|
|
def peer_info(self, peer_id: ID) -> PeerInfo:
|
2018-10-22 03:15:53 +08:00
|
|
|
"""
|
|
|
|
:param peer_id: peer ID to get info for
|
2018-10-21 04:55:15 +08:00
|
|
|
:return: peer info object
|
|
|
|
"""
|
|
|
|
|
2018-10-22 03:15:53 +08:00
|
|
|
@abstractmethod
|
2019-07-27 16:27:01 +08:00
|
|
|
def get_protocols(self, peer_id: ID) -> List[str]:
|
2018-10-22 03:15:53 +08:00
|
|
|
"""
|
|
|
|
:param peer_id: peer ID to get protocols for
|
2018-10-29 20:13:39 +08:00
|
|
|
:return: protocols (as strings)
|
|
|
|
:raise Exception: peer ID not found exception
|
2018-10-21 04:55:15 +08:00
|
|
|
"""
|
|
|
|
|
2018-10-22 03:15:53 +08:00
|
|
|
@abstractmethod
|
2019-07-27 16:27:01 +08:00
|
|
|
def add_protocols(self, peer_id: ID, protocols: Sequence[str]) -> None:
|
2018-10-22 03:15:53 +08:00
|
|
|
"""
|
|
|
|
:param peer_id: peer ID to add protocols for
|
2018-10-21 04:55:15 +08:00
|
|
|
:param protocols: protocols to add
|
2018-10-30 07:03:19 +08:00
|
|
|
:raise Exception: peer ID not found
|
2018-10-21 04:55:15 +08:00
|
|
|
"""
|
|
|
|
|
2018-10-22 03:15:53 +08:00
|
|
|
@abstractmethod
|
2019-07-27 16:27:01 +08:00
|
|
|
def set_protocols(self, peer_id: ID, protocols: Sequence[str]) -> None:
|
2018-10-22 03:15:53 +08:00
|
|
|
"""
|
|
|
|
:param peer_id: peer ID to set protocols for
|
2018-10-21 04:55:15 +08:00
|
|
|
:param protocols: protocols to set
|
2018-10-30 07:03:19 +08:00
|
|
|
:raise Exception: peer ID not found
|
2018-10-21 04:55:15 +08:00
|
|
|
"""
|
|
|
|
|
2018-10-22 03:15:53 +08:00
|
|
|
@abstractmethod
|
2019-07-27 16:27:01 +08:00
|
|
|
def peer_ids(self) -> List[ID]:
|
2018-10-22 03:15:53 +08:00
|
|
|
"""
|
2018-10-21 04:55:15 +08:00
|
|
|
:return: all of the peer IDs stored in peer store
|
|
|
|
"""
|