mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
fixed types and improved code
This commit is contained in:
@ -1,7 +1,4 @@
|
|||||||
from typing import (
|
from collections.abc import Callable
|
||||||
Callable,
|
|
||||||
Optional,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.abc import (
|
from libp2p.abc import (
|
||||||
IPeerStore,
|
IPeerStore,
|
||||||
@ -45,6 +42,7 @@ from libp2p.security.base_session import (
|
|||||||
)
|
)
|
||||||
from libp2p.security.base_transport import (
|
from libp2p.security.base_transport import (
|
||||||
BaseSecureTransport,
|
BaseSecureTransport,
|
||||||
|
default_secure_bytes_provider,
|
||||||
)
|
)
|
||||||
from libp2p.security.exceptions import (
|
from libp2p.security.exceptions import (
|
||||||
HandshakeFailure,
|
HandshakeFailure,
|
||||||
@ -111,8 +109,8 @@ async def run_handshake(
|
|||||||
local_private_key: PrivateKey,
|
local_private_key: PrivateKey,
|
||||||
conn: IRawConnection,
|
conn: IRawConnection,
|
||||||
is_initiator: bool,
|
is_initiator: bool,
|
||||||
remote_peer_id: ID,
|
remote_peer_id: ID | None,
|
||||||
peerstore: Optional[IPeerStore] = None,
|
peerstore: IPeerStore | None = None,
|
||||||
) -> ISecureConn:
|
) -> ISecureConn:
|
||||||
"""Raise `HandshakeFailure` when handshake failed."""
|
"""Raise `HandshakeFailure` when handshake failed."""
|
||||||
msg = make_exchange_message(local_private_key.get_public_key())
|
msg = make_exchange_message(local_private_key.get_public_key())
|
||||||
@ -196,9 +194,12 @@ class InsecureTransport(BaseSecureTransport):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
local_key_pair: KeyPair,
|
local_key_pair: KeyPair,
|
||||||
secure_bytes_provider: Optional[Callable[[int], bytes]] = None,
|
secure_bytes_provider: Callable[[int], bytes] | None = None,
|
||||||
peerstore: Optional[IPeerStore] = None,
|
peerstore: IPeerStore | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
# If secure_bytes_provider is None, use the default one
|
||||||
|
if secure_bytes_provider is None:
|
||||||
|
secure_bytes_provider = default_secure_bytes_provider
|
||||||
super().__init__(local_key_pair, secure_bytes_provider)
|
super().__init__(local_key_pair, secure_bytes_provider)
|
||||||
self.peerstore = peerstore
|
self.peerstore = peerstore
|
||||||
|
|
||||||
@ -210,6 +211,7 @@ class InsecureTransport(BaseSecureTransport):
|
|||||||
|
|
||||||
:return: secure connection object (that implements secure_conn_interface)
|
:return: secure connection object (that implements secure_conn_interface)
|
||||||
"""
|
"""
|
||||||
|
# For inbound connections, we don't know the remote peer ID yet
|
||||||
return await run_handshake(
|
return await run_handshake(
|
||||||
self.local_peer, self.local_private_key, conn, False, None, self.peerstore
|
self.local_peer, self.local_private_key, conn, False, None, self.peerstore
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user