2019-08-01 06:00:12 +08:00
|
|
|
from abc import ABC, abstractmethod
|
2019-07-30 17:31:08 +08:00
|
|
|
from typing import Iterable
|
2019-07-27 17:10:03 +08:00
|
|
|
|
2019-07-28 22:30:51 +08:00
|
|
|
from libp2p.peer.id import ID
|
|
|
|
from libp2p.peer.peerinfo import PeerInfo
|
2019-08-01 06:00:12 +08:00
|
|
|
|
2019-01-16 01:43:54 +08:00
|
|
|
|
|
|
|
class IContentRouting(ABC):
|
|
|
|
@abstractmethod
|
2019-07-29 12:42:13 +08:00
|
|
|
def provide(self, cid: bytes, announce: bool = True) -> None:
|
2019-10-24 14:41:10 +08:00
|
|
|
"""Provide adds the given cid to the content routing system.
|
|
|
|
|
|
|
|
If announce is True, it also announces it, otherwise it is just
|
|
|
|
kept in the local accounting of which objects are being
|
|
|
|
provided.
|
2019-01-16 01:43:54 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
2019-07-27 17:10:03 +08:00
|
|
|
def find_provider_iter(self, cid: bytes, count: int) -> Iterable[PeerInfo]:
|
2019-10-24 14:41:10 +08:00
|
|
|
"""Search for peers who are able to provide a given key returns an
|
|
|
|
iterator of peer.PeerInfo."""
|
2019-01-16 01:43:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
class IPeerRouting(ABC):
|
|
|
|
@abstractmethod
|
2019-07-30 15:31:02 +08:00
|
|
|
async def find_peer(self, peer_id: ID) -> PeerInfo:
|
2019-10-24 14:41:10 +08:00
|
|
|
"""Find specific Peer FindPeer searches for a peer with given peer_id,
|
|
|
|
returns a peer.PeerInfo with relevant addresses."""
|