mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
Integrate security selectin into libp2p system
This commit is contained in:
@ -82,9 +82,10 @@ class TCP(ITransport):
|
||||
await writer.drain()
|
||||
|
||||
# Await ack for peer id
|
||||
ack = (await reader.read(1024)).decode()
|
||||
expected_ack_str = "received peer id"
|
||||
ack = (await reader.read(len(expected_ack_str))).decode()
|
||||
|
||||
if ack != "received peer id":
|
||||
if ack != expected_ack_str:
|
||||
raise Exception("Receiver did not receive peer id")
|
||||
|
||||
return RawConnection(host, port, reader, writer, True)
|
||||
|
||||
@ -1,11 +1,17 @@
|
||||
from libp2p.stream_muxer.mplex.mplex import Mplex
|
||||
from libp2p.security.security_multistream import SecurityMultistream
|
||||
|
||||
|
||||
class TransportUpgrader:
|
||||
# pylint: disable=no-self-use
|
||||
|
||||
def __init__(self, secOpt, muxerOpt):
|
||||
self.sec = secOpt
|
||||
# Store security option
|
||||
self.security_multistream = SecurityMultistream()
|
||||
for key in secOpt:
|
||||
self.security_multistream.add_transport(key, secOpt[key])
|
||||
|
||||
# Store muxer option
|
||||
self.muxer = muxerOpt
|
||||
|
||||
def upgrade_listener(self, transport, listeners):
|
||||
@ -13,12 +19,14 @@ class TransportUpgrader:
|
||||
Upgrade multiaddr listeners to libp2p-transport listeners
|
||||
"""
|
||||
|
||||
def upgrade_security(self, conn, peer_id):
|
||||
async def upgrade_security(self, raw_conn, peer_id, initiator):
|
||||
"""
|
||||
Upgrade conn to be a secured connection
|
||||
"""
|
||||
# TODO: Do exchange to determine security module
|
||||
pass
|
||||
if initiator:
|
||||
return await self.security_multistream.secure_outbound(raw_conn, peer_id)
|
||||
else:
|
||||
return await self.security_multistream.secure_inbound(raw_conn)
|
||||
|
||||
def upgrade_connection(self, conn, generic_protocol_handler, peer_id):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user