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):
|
|
|
|
"""
|
|
|
|
upgrade multiaddr listeners to libp2p-transport listeners
|
2018-11-11 22:56:44 +08:00
|
|
|
|
2018-11-12 05:09:37 +08:00
|
|
|
"""
|
2018-11-13 02:02:49 +08:00
|
|
|
|
2018-11-12 05:09:37 +08:00
|
|
|
def upgrade_security(self):
|
|
|
|
pass
|
2018-11-11 22:56:44 +08:00
|
|
|
|
2019-02-25 09:58:23 +08:00
|
|
|
def upgrade_connection(self, conn, generic_protocol_handler):
|
2018-11-12 05:09:37 +08:00
|
|
|
"""
|
|
|
|
upgrade raw connection to muxed connection
|
|
|
|
"""
|
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-02-25 09:58:23 +08:00
|
|
|
return Mplex(conn, generic_protocol_handler)
|