mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
* refactored : host_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored : network_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored : notifee_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored : net_connection_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored: raw_connection_interface, secure_conn_interface and stream_muxer abc.py * refactored: addrbook_interface * refactored :peerdata_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :peermetadata_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :multiselect_client_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :multiselect_communicator_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :multiselect_muxer_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :interfaces Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :security_transport_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :listener_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * moved all interfaces and typing files Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * fixed documentation and moved pubsub abc.py Co-authored-by: Khwahish Patel <khwahish.p1@ahduni.edu.in> * added exclude-members in custom_types docs * added : newsfragment for moving all interfaces to libp2p.abc --------- Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> Co-authored-by: Mystical <125946525+mystical-prog@users.noreply.github.com>
71 lines
1.9 KiB
Python
71 lines
1.9 KiB
Python
from libp2p.abc import (
|
|
IRawConnection,
|
|
ISecureConn,
|
|
ISecureTransport,
|
|
)
|
|
from libp2p.crypto.keys import (
|
|
KeyPair,
|
|
PrivateKey,
|
|
)
|
|
from libp2p.custom_types import (
|
|
TProtocol,
|
|
)
|
|
from libp2p.peer.id import (
|
|
ID,
|
|
)
|
|
|
|
from .patterns import (
|
|
IPattern,
|
|
PatternXX,
|
|
)
|
|
|
|
PROTOCOL_ID = TProtocol("/noise")
|
|
|
|
|
|
class Transport(ISecureTransport):
|
|
libp2p_privkey: PrivateKey
|
|
noise_privkey: PrivateKey
|
|
local_peer: ID
|
|
early_data: bytes
|
|
with_noise_pipes: bool
|
|
|
|
# NOTE: Implementations that support Noise Pipes must decide whether to use
|
|
# an XX or IK handshake based on whether they possess a cached static
|
|
# Noise key for the remote peer.
|
|
# TODO: A storage of seen noise static keys for pattern IK?
|
|
|
|
def __init__(
|
|
self,
|
|
libp2p_keypair: KeyPair,
|
|
noise_privkey: PrivateKey = None,
|
|
early_data: bytes = None,
|
|
with_noise_pipes: bool = False,
|
|
) -> None:
|
|
self.libp2p_privkey = libp2p_keypair.private_key
|
|
self.noise_privkey = noise_privkey
|
|
self.local_peer = ID.from_pubkey(libp2p_keypair.public_key)
|
|
self.early_data = early_data
|
|
self.with_noise_pipes = with_noise_pipes
|
|
|
|
if self.with_noise_pipes:
|
|
raise NotImplementedError
|
|
|
|
def get_pattern(self) -> IPattern:
|
|
if self.with_noise_pipes:
|
|
raise NotImplementedError
|
|
else:
|
|
return PatternXX(
|
|
self.local_peer,
|
|
self.libp2p_privkey,
|
|
self.noise_privkey,
|
|
self.early_data,
|
|
)
|
|
|
|
async def secure_inbound(self, conn: IRawConnection) -> ISecureConn:
|
|
pattern = self.get_pattern()
|
|
return await pattern.handshake_inbound(conn)
|
|
|
|
async def secure_outbound(self, conn: IRawConnection, peer_id: ID) -> ISecureConn:
|
|
pattern = self.get_pattern()
|
|
return await pattern.handshake_outbound(conn, peer_id)
|