mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
run lint and fix errors, except mypy
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
# PeerStore
|
||||
|
||||
The PeerStore contains a mapping of peer IDs to PeerData objects. Each PeerData object represents a peer, and each PeerData contains a collection of protocols, addresses, and a mapping of metadata. PeerStore implements the IPeerStore (peer protocols), IAddrBook (address book), and IPeerMetadata (peer metadata) interfaces, which allows the peer store to effectively function as a dictionary for peer ID to protocol, address, and metadata.
|
||||
The PeerStore contains a mapping of peer IDs to PeerData objects. Each PeerData object represents a peer, and each PeerData contains a collection of protocols, addresses, and a mapping of metadata. PeerStore implements the IPeerStore (peer protocols), IAddrBook (address book), and IPeerMetadata (peer metadata) interfaces, which allows the peer store to effectively function as a dictionary for peer ID to protocol, address, and metadata.
|
||||
|
||||
Note: PeerInfo represents a read-only summary of a PeerData object. Only the attributes assigned in PeerInfo are readable by references to PeerInfo objects.
|
||||
Note: PeerInfo represents a read-only summary of a PeerData object. Only the attributes assigned in PeerInfo are readable by references to PeerInfo objects.
|
||||
|
||||
@ -1,9 +1,19 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import List, Sequence
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
from typing import (
|
||||
List,
|
||||
Sequence,
|
||||
)
|
||||
|
||||
from multiaddr import Multiaddr
|
||||
from multiaddr import (
|
||||
Multiaddr,
|
||||
)
|
||||
|
||||
from .id import ID
|
||||
from .id import (
|
||||
ID,
|
||||
)
|
||||
|
||||
|
||||
class IAddrBook(ABC):
|
||||
@ -15,7 +25,7 @@ class IAddrBook(ABC):
|
||||
:param peer_id: the peer to add address for
|
||||
:param addr: multiaddress of the peer
|
||||
:param ttl: time-to-live for the address (after this time, address is no longer valid)
|
||||
"""
|
||||
""" # noqa: E501
|
||||
|
||||
@abstractmethod
|
||||
def add_addrs(self, peer_id: ID, addrs: Sequence[Multiaddr], ttl: int) -> None:
|
||||
@ -28,7 +38,7 @@ class IAddrBook(ABC):
|
||||
:param peer_id: the peer to add address for
|
||||
:param addr: multiaddresses of the peer
|
||||
:param ttl: time-to-live for the address (after this time, address is no longer valid
|
||||
"""
|
||||
""" # noqa: E501
|
||||
|
||||
@abstractmethod
|
||||
def addrs(self, peer_id: ID) -> List[Multiaddr]:
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
import hashlib
|
||||
from typing import Union
|
||||
from typing import (
|
||||
Union,
|
||||
)
|
||||
|
||||
import base58
|
||||
import multihash
|
||||
|
||||
from libp2p.crypto.keys import PublicKey
|
||||
from libp2p.crypto.keys import (
|
||||
PublicKey,
|
||||
)
|
||||
|
||||
# NOTE: On inlining...
|
||||
# See: https://github.com/libp2p/specs/issues/138
|
||||
|
||||
@ -1,14 +1,25 @@
|
||||
from typing import Any, Dict, List, Sequence
|
||||
from typing import (
|
||||
Any,
|
||||
Dict,
|
||||
List,
|
||||
Sequence,
|
||||
)
|
||||
|
||||
from multiaddr import Multiaddr
|
||||
from multiaddr import (
|
||||
Multiaddr,
|
||||
)
|
||||
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.crypto.keys import (
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
|
||||
from .peerdata_interface import IPeerData
|
||||
from .peerdata_interface import (
|
||||
IPeerData,
|
||||
)
|
||||
|
||||
|
||||
class PeerData(IPeerData):
|
||||
|
||||
pubkey: PublicKey
|
||||
privkey: PrivateKey
|
||||
metadata: Dict[Any, Any]
|
||||
|
||||
@ -1,11 +1,25 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, List, Sequence
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
from typing import (
|
||||
Any,
|
||||
List,
|
||||
Sequence,
|
||||
)
|
||||
|
||||
from multiaddr import Multiaddr
|
||||
from multiaddr import (
|
||||
Multiaddr,
|
||||
)
|
||||
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.crypto.keys import (
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
|
||||
from .peermetadata_interface import IPeerMetadata
|
||||
from .peermetadata_interface import (
|
||||
IPeerMetadata,
|
||||
)
|
||||
|
||||
|
||||
class IPeerData(ABC):
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
from typing import Any, List, Sequence
|
||||
from typing import (
|
||||
Any,
|
||||
List,
|
||||
Sequence,
|
||||
)
|
||||
|
||||
import multiaddr
|
||||
|
||||
from .id import ID
|
||||
from .id import (
|
||||
ID,
|
||||
)
|
||||
|
||||
|
||||
class PeerInfo:
|
||||
|
||||
@ -1,7 +1,14 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
from typing import (
|
||||
Any,
|
||||
)
|
||||
|
||||
from .id import ID
|
||||
from .id import (
|
||||
ID,
|
||||
)
|
||||
|
||||
|
||||
class IPeerMetadata(ABC):
|
||||
|
||||
@ -1,18 +1,39 @@
|
||||
from collections import defaultdict
|
||||
from typing import Any, Dict, List, Sequence
|
||||
from collections import (
|
||||
defaultdict,
|
||||
)
|
||||
from typing import (
|
||||
Any,
|
||||
Dict,
|
||||
List,
|
||||
Sequence,
|
||||
)
|
||||
|
||||
from multiaddr import Multiaddr
|
||||
from multiaddr import (
|
||||
Multiaddr,
|
||||
)
|
||||
|
||||
from libp2p.crypto.keys import KeyPair, PrivateKey, PublicKey
|
||||
from libp2p.crypto.keys import (
|
||||
KeyPair,
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
|
||||
from .id import ID
|
||||
from .peerdata import PeerData, PeerDataError
|
||||
from .peerinfo import PeerInfo
|
||||
from .peerstore_interface import IPeerStore
|
||||
from .id import (
|
||||
ID,
|
||||
)
|
||||
from .peerdata import (
|
||||
PeerData,
|
||||
PeerDataError,
|
||||
)
|
||||
from .peerinfo import (
|
||||
PeerInfo,
|
||||
)
|
||||
from .peerstore_interface import (
|
||||
IPeerStore,
|
||||
)
|
||||
|
||||
|
||||
class PeerStore(IPeerStore):
|
||||
|
||||
peer_data_map: Dict[ID, PeerData]
|
||||
|
||||
def __init__(self) -> None:
|
||||
|
||||
@ -1,14 +1,34 @@
|
||||
from abc import abstractmethod
|
||||
from typing import Any, List, Sequence
|
||||
from abc import (
|
||||
abstractmethod,
|
||||
)
|
||||
from typing import (
|
||||
Any,
|
||||
List,
|
||||
Sequence,
|
||||
)
|
||||
|
||||
from multiaddr import Multiaddr
|
||||
from multiaddr import (
|
||||
Multiaddr,
|
||||
)
|
||||
|
||||
from libp2p.crypto.keys import KeyPair, PrivateKey, PublicKey
|
||||
from libp2p.crypto.keys import (
|
||||
KeyPair,
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
|
||||
from .addrbook_interface import IAddrBook
|
||||
from .id import ID
|
||||
from .peerinfo import PeerInfo
|
||||
from .peermetadata_interface import IPeerMetadata
|
||||
from .addrbook_interface import (
|
||||
IAddrBook,
|
||||
)
|
||||
from .id import (
|
||||
ID,
|
||||
)
|
||||
from .peerinfo import (
|
||||
PeerInfo,
|
||||
)
|
||||
from .peermetadata_interface import (
|
||||
IPeerMetadata,
|
||||
)
|
||||
|
||||
|
||||
class IPeerStore(IAddrBook, IPeerMetadata):
|
||||
|
||||
Reference in New Issue
Block a user