mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Use types for {Private,Public}Key and address other missing type hints
This commit is contained in:
@ -1,3 +1,6 @@
|
||||
from typing import Optional
|
||||
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.base_transport import BaseSecureTransport
|
||||
@ -17,25 +20,16 @@ class BaseSession(ISecureConn, IRawConnection):
|
||||
self.local_private_key = transport.local_private_key
|
||||
self.conn = conn
|
||||
self.remote_peer_id = peer_id
|
||||
self.remote_permanent_pubkey = b""
|
||||
self.remote_permanent_pubkey = None
|
||||
|
||||
# TODO clean up how this is passed around?
|
||||
@property
|
||||
def initiator(self) -> bool:
|
||||
return self.conn.initiator
|
||||
self.initiator = self.conn.initiator
|
||||
self.writer = self.conn.writer
|
||||
self.reader = self.conn.reader
|
||||
|
||||
# TODO clean up how this is passed around?
|
||||
def next_stream_id(self) -> int:
|
||||
return self.conn.next_stream_id()
|
||||
|
||||
@property
|
||||
def writer(self):
|
||||
return self.conn.writer
|
||||
|
||||
@property
|
||||
def reader(self):
|
||||
return self.conn.reader
|
||||
|
||||
async def write(self, data: bytes) -> None:
|
||||
await self.conn.write(data)
|
||||
|
||||
@ -48,11 +42,11 @@ class BaseSession(ISecureConn, IRawConnection):
|
||||
def get_local_peer(self) -> ID:
|
||||
return self.local_peer
|
||||
|
||||
def get_local_private_key(self) -> bytes:
|
||||
def get_local_private_key(self) -> PrivateKey:
|
||||
return self.local_private_key
|
||||
|
||||
def get_remote_peer(self) -> ID:
|
||||
return self.remote_peer_id
|
||||
|
||||
def get_remote_public_key(self) -> bytes:
|
||||
def get_remote_public_key(self) -> Optional[PublicKey]:
|
||||
return self.remote_permanent_pubkey
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.secure_transport_interface import ISecureTransport
|
||||
|
||||
@ -8,6 +9,8 @@ class BaseSecureTransport(ISecureTransport):
|
||||
is only meant to be used in clases that derive from it.
|
||||
"""
|
||||
|
||||
def __init__(self, local_private_key: bytes, local_public_key: bytes) -> None:
|
||||
def __init__(
|
||||
self, local_private_key: PrivateKey, local_public_key: PublicKey
|
||||
) -> None:
|
||||
self.local_private_key = local_private_key
|
||||
self.local_peer = ID.from_pubkey(local_public_key)
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
|
||||
|
||||
"""
|
||||
@ -18,7 +19,7 @@ class AbstractSecureConn(ABC):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_local_private_key(self) -> bytes:
|
||||
def get_local_private_key(self) -> PrivateKey:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
@ -26,7 +27,7 @@ class AbstractSecureConn(ABC):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_remote_public_key(self) -> bytes:
|
||||
def get_remote_public_key(self) -> PublicKey:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from abc import ABC
|
||||
from typing import Dict
|
||||
from typing import Dict, Mapping
|
||||
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
@ -23,7 +23,9 @@ class SecurityMultistream(ABC):
|
||||
multiselect: Multiselect
|
||||
multiselect_client: MultiselectClient
|
||||
|
||||
def __init__(self, secure_transports_by_protocol) -> None:
|
||||
def __init__(
|
||||
self, secure_transports_by_protocol: Mapping[TProtocol, ISecureTransport]
|
||||
) -> None:
|
||||
self.transports = {}
|
||||
self.multiselect = Multiselect()
|
||||
self.multiselect_client = MultiselectClient()
|
||||
|
||||
Reference in New Issue
Block a user