Add type hints to routing folder

This commit is contained in:
NIC619
2019-07-27 17:10:03 +08:00
parent f2de986c74
commit e1592997a8
3 changed files with 36 additions and 9 deletions

View File

@ -1,9 +1,14 @@
from typing import (
Iterable,
)
from libp2p.peer.peerinfo import PeerInfo
from libp2p.routing.interfaces import IContentRouting
class KadmeliaContentRouter(IContentRouting):
def provide(self, cid, announce=True):
def provide(self, cid: bytes, announce: bool=True) -> None:
"""
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
@ -12,7 +17,7 @@ class KadmeliaContentRouter(IContentRouting):
# 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.
def find_provider_iter(self, cid, count):
def find_provider_iter(self, cid: bytes, count: int) -> Iterable[PeerInfo]:
"""
Search for peers who are able to provide a given key
returns an iterator of peer.PeerInfo