py-libp2p/libp2p/routing/kademlia/kademlia_content_router.py

25 lines
863 B
Python
Raw Normal View History

2019-07-27 17:10:03 +08:00
from typing import (
Iterable,
)
from libp2p.peer.peerinfo import PeerInfo
2019-03-27 03:44:01 +08:00
from libp2p.routing.interfaces import IContentRouting
class KadmeliaContentRouter(IContentRouting):
2019-07-29 12:42:13 +08:00
def provide(self, cid: bytes, announce: bool = True) -> None:
2019-03-27 03:44:01 +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.
"""
# the DHT finds the closest peers to `key` using the `FIND_NODE` RPC
# then sends a `ADD_PROVIDER` RPC with its own `PeerInfo` to each of these peers.
2019-03-27 03:44:01 +08:00
2019-07-27 17:10:03 +08:00
def find_provider_iter(self, cid: bytes, count: int) -> Iterable[PeerInfo]:
2019-03-27 03:44:01 +08:00
"""
Search for peers who are able to provide a given key
returns an iterator of peer.PeerInfo
"""