mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Add type hints to peer folder
This commit is contained in:
@ -1,13 +1,22 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import (
|
||||
List,
|
||||
Sequence,
|
||||
)
|
||||
|
||||
|
||||
from multiaddr import Multiaddr
|
||||
|
||||
from .id import ID
|
||||
|
||||
|
||||
class IAddrBook(ABC):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_addr(self, peer_id, addr, ttl):
|
||||
def add_addr(self, peer_id: ID, addr: Multiaddr, ttl: int) -> None:
|
||||
"""
|
||||
Calls add_addrs(peer_id, [addr], ttl)
|
||||
:param peer_id: the peer to add address for
|
||||
@ -16,7 +25,7 @@ class IAddrBook(ABC):
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def add_addrs(self, peer_id, addrs, ttl):
|
||||
def add_addrs(self, peer_id: ID, addrs: Sequence[Multiaddr], ttl: int) -> None:
|
||||
"""
|
||||
Adds addresses for a given peer all with the same time-to-live. If one of the
|
||||
addresses already exists for the peer and has a longer TTL, no operation should take place.
|
||||
@ -27,21 +36,21 @@ class IAddrBook(ABC):
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def addrs(self, peer_id):
|
||||
def addrs(self, peer_id: ID) -> List[Multiaddr]:
|
||||
"""
|
||||
:param peer_id: peer to get addresses of
|
||||
:return: all known (and valid) addresses for the given peer
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def clear_addrs(self, peer_id):
|
||||
def clear_addrs(self, peer_id: ID) -> None:
|
||||
"""
|
||||
Removes all previously stored addresses
|
||||
:param peer_id: peer to remove addresses of
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def peers_with_addrs(self):
|
||||
def peers_with_addrs(self) -> List[ID]:
|
||||
"""
|
||||
:return: all of the peer IDs stored with addresses
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user