2019-01-10 02:38:56 +08:00
|
|
|
from libp2p.stream_muxer.mplex.mplex import Mplex
|
2018-11-12 08:37:07 +08:00
|
|
|
|
2018-11-13 02:02:49 +08:00
|
|
|
|
2019-01-10 02:38:56 +08:00
|
|
|
class TransportUpgrader:
|
2018-11-27 07:24:29 +08:00
|
|
|
# pylint: disable=no-self-use
|
2018-11-11 22:56:44 +08:00
|
|
|
|
2018-11-12 05:09:37 +08:00
|
|
|
def __init__(self, secOpt, muxerOpt):
|
|
|
|
self.sec = secOpt
|
|
|
|
self.muxer = muxerOpt
|
2018-11-11 22:56:44 +08:00
|
|
|
|
2018-11-12 05:09:37 +08:00
|
|
|
def upgrade_listener(self, transport, listeners):
|
|
|
|
"""
|
2019-04-30 06:05:38 +08:00
|
|
|
Upgrade multiaddr listeners to libp2p-transport listeners
|
2018-11-12 05:09:37 +08:00
|
|
|
"""
|
2018-11-13 02:02:49 +08:00
|
|
|
|
2019-04-30 06:05:38 +08:00
|
|
|
def upgrade_security(self, conn, peer_id):
|
|
|
|
"""
|
|
|
|
Upgrade conn to be a secured connection
|
|
|
|
"""
|
|
|
|
# TODO: Do exchange to determine security module
|
2018-11-12 05:09:37 +08:00
|
|
|
pass
|
2018-11-11 22:56:44 +08:00
|
|
|
|
2019-03-24 01:52:02 +08:00
|
|
|
def upgrade_connection(self, conn, generic_protocol_handler, peer_id):
|
2018-11-12 05:09:37 +08:00
|
|
|
"""
|
2019-04-30 06:05:38 +08:00
|
|
|
Upgrade raw connection to muxed connection
|
2018-11-12 05:09:37 +08:00
|
|
|
"""
|
2018-11-13 02:02:49 +08:00
|
|
|
|
|
|
|
# For PoC, no security, default to mplex
|
2018-11-12 08:37:07 +08:00
|
|
|
# TODO do exchange to determine multiplexer
|
2019-03-24 01:52:02 +08:00
|
|
|
return Mplex(conn, generic_protocol_handler, peer_id)
|