diff --git a/libp2p/host/basic_host.py b/libp2p/host/basic_host.py index 48c322b..253394e 100644 --- a/libp2p/host/basic_host.py +++ b/libp2p/host/basic_host.py @@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, List, Sequence import multiaddr -from libp2p.crypto.keys import PublicKey +from libp2p.crypto.keys import PrivateKey, PublicKey from libp2p.host.defaults import get_default_protocols from libp2p.host.exceptions import StreamFailure from libp2p.network.network_interface import INetwork @@ -67,7 +67,7 @@ class BasicHost(IHost): def get_public_key(self) -> PublicKey: return self.peerstore.pubkey(self.get_id()) - def get_private_key(self) -> PublicKey: + def get_private_key(self) -> PrivateKey: return self.peerstore.privkey(self.get_id()) def get_network(self) -> INetwork: diff --git a/libp2p/host/host_interface.py b/libp2p/host/host_interface.py index 5e28fda..43f4ac4 100644 --- a/libp2p/host/host_interface.py +++ b/libp2p/host/host_interface.py @@ -3,7 +3,7 @@ from typing import Any, List, Sequence import multiaddr -from libp2p.crypto.keys import PublicKey +from libp2p.crypto.keys import PrivateKey, PublicKey from libp2p.network.network_interface import INetwork from libp2p.network.stream.net_stream_interface import INetStream from libp2p.peer.id import ID @@ -25,7 +25,7 @@ class IHost(ABC): """ @abstractmethod - def get_private_key(self) -> PublicKey: + def get_private_key(self) -> PrivateKey: """ :return: the private key belonging to the peer """ diff --git a/libp2p/peer/peerstore.py b/libp2p/peer/peerstore.py index 7dc367f..4cff54e 100644 --- a/libp2p/peer/peerstore.py +++ b/libp2p/peer/peerstore.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Optional, Sequence, Tuple +from typing import Any, Dict, List, Optional, Sequence, Set from multiaddr import Multiaddr @@ -24,7 +24,8 @@ class PeerStore(IPeerStore): def __create_or_get_peer(self, peer_id: ID) -> PeerData: """ Returns the peer data for peer_id or creates a new peer data (and - stores it in peer_data_map) if peer data for peer_id does not yet exist. + stores it in peer_data_map) if peer data for peer_id does not yet + exist. :param peer_id: peer ID :return: peer data @@ -158,7 +159,9 @@ class PeerStore(IPeerStore): :raise PeerStoreError: if peer ID already has pubkey set """ if peer_id in self.peer_pubkey_map: - raise PeerStoreError(f"peer ID already has pubkey: {self.peer_pubkey_map[peer_id]}") + raise PeerStoreError( + f"peer ID already has pubkey: {self.peer_pubkey_map[peer_id]}" + ) self.peer_pubkey_map[peer_id] = pubkey def pubkey(self, peer_id: ID) -> PublicKey: @@ -178,7 +181,9 @@ class PeerStore(IPeerStore): :raise PeerStoreError: if peer ID already has privkey set """ if peer_id in self.peer_privkey_map: - raise PeerStoreError(f"peer ID already has privkey: {self.peer_privkey_map[peer_id]}") + raise PeerStoreError( + f"peer ID already has privkey: {self.peer_privkey_map[peer_id]}" + ) self.peer_privkey_map[peer_id] = privkey def privkey(self, peer_id: ID) -> PrivateKey: @@ -191,7 +196,7 @@ class PeerStore(IPeerStore): return self.peer_privkey_map[peer_id] raise PeerStoreError("peer ID not found") - def peers_with_keys(self) -> Tuple[ID]: + def peers_with_keys(self) -> Set[ID]: """ :return: all of the peer IDs which has pubkey/privkey stored in peer store """ diff --git a/libp2p/peer/peerstore_interface.py b/libp2p/peer/peerstore_interface.py index fbd1a2e..8ebe1cc 100644 --- a/libp2p/peer/peerstore_interface.py +++ b/libp2p/peer/peerstore_interface.py @@ -1,5 +1,5 @@ from abc import abstractmethod -from typing import Any, List, Sequence, Tuple +from typing import Any, List, Sequence, Set from multiaddr import Multiaddr @@ -132,7 +132,7 @@ class IPeerStore(IAddrBook, IPeerMetadata): """ @abstractmethod - def peers_with_keys(self) -> Tuple[ID]: + def peers_with_keys(self) -> Set[ID]: """ :return: all of the peer IDs which has pubkey/privkey stored in peer store """ diff --git a/libp2p/tools/factories.py b/libp2p/tools/factories.py index 341d691..405e6ed 100644 --- a/libp2p/tools/factories.py +++ b/libp2p/tools/factories.py @@ -34,7 +34,7 @@ from .constants import ( from .utils import connect, connect_swarm -def initialize_peerstore_with_our_keypair(self_id: ID, key_pair: KeyPair): +def initialize_peerstore_with_our_keypair(self_id: ID, key_pair: KeyPair) -> PeerStore: peer_store = PeerStore() peer_store.add_pubkey(self_id, key_pair.public_key) peer_store.add_privkey(self_id, key_pair.private_key)