From e047752d82965164413af2f1ef8c92c4a2d3d03d Mon Sep 17 00:00:00 2001 From: zixuanzh Date: Tue, 20 Nov 2018 20:28:41 -0500 Subject: [PATCH] rename muxed_conn --- muxer/mplex/smux_multiplex.py | 45 ------------------- {muxer => stream_muxer}/__init__.py | 0 {muxer => stream_muxer}/mplex/__init__.py | 0 {muxer => stream_muxer}/mplex/constants.py | 0 .../mplex/mplex.py | 10 ++--- .../mplex/mplex_stream.py | 4 +- {muxer => stream_muxer}/mplex/utils.py | 0 .../muxed_connection_interface.py | 0 .../muxed_stream_interface.py | 0 {muxer => stream_muxer}/yamux/__init__.py | 0 transport/upgrader.py | 4 +- 11 files changed, 9 insertions(+), 54 deletions(-) delete mode 100644 muxer/mplex/smux_multiplex.py rename {muxer => stream_muxer}/__init__.py (100%) rename {muxer => stream_muxer}/mplex/__init__.py (100%) rename {muxer => stream_muxer}/mplex/constants.py (100%) rename muxer/mplex/muxed_connection.py => stream_muxer/mplex/mplex.py (94%) rename muxer/mplex/muxed_stream.py => stream_muxer/mplex/mplex_stream.py (97%) rename {muxer => stream_muxer}/mplex/utils.py (100%) rename {muxer/mplex => stream_muxer}/muxed_connection_interface.py (100%) rename {muxer/mplex => stream_muxer}/muxed_stream_interface.py (100%) rename {muxer => stream_muxer}/yamux/__init__.py (100%) diff --git a/muxer/mplex/smux_multiplex.py b/muxer/mplex/smux_multiplex.py deleted file mode 100644 index a99f266..0000000 --- a/muxer/mplex/smux_multiplex.py +++ /dev/null @@ -1,45 +0,0 @@ -from .muxed_connection import MuxedConn - - -class Multiplex(object): - """ - muxing logic currently lives in MuxedConn - reference: https://github.com/whyrusleeping/go-smux-multiplex/blob/master/multiplex.go - """ - def __init__(self, conn, initiator): - """ - :param conn: an instance of raw connection - :param initiator: boolean to prevent multiplex with self - """ - self.muxed_conn = MuxedConn(conn, initiator) - - def close(self): - """ - close the stream muxer and underlying raw connection - """ - return self.muxed_conn.close() - - def is_closed(self): - """ - check connection is fully closed - :return: true if successful - """ - return self.muxed_conn.is_closed() - - def open_stream(self, protocol_id, stream_name): - """ - creates a new muxed_stream - :return: a new stream - """ - return self.muxed_conn.open_stream(protocol_id, stream_name) - - def accept_stream(self, _muxed_stream): - """ - accepts a muxed stream opened by the other end - :param _muxed_stream: stream to be accepted - :return: the accepted stream - """ - pass - - # def new_conn(raw_conn, is_server): - # pass diff --git a/muxer/__init__.py b/stream_muxer/__init__.py similarity index 100% rename from muxer/__init__.py rename to stream_muxer/__init__.py diff --git a/muxer/mplex/__init__.py b/stream_muxer/mplex/__init__.py similarity index 100% rename from muxer/mplex/__init__.py rename to stream_muxer/mplex/__init__.py diff --git a/muxer/mplex/constants.py b/stream_muxer/mplex/constants.py similarity index 100% rename from muxer/mplex/constants.py rename to stream_muxer/mplex/constants.py diff --git a/muxer/mplex/muxed_connection.py b/stream_muxer/mplex/mplex.py similarity index 94% rename from muxer/mplex/muxed_connection.py rename to stream_muxer/mplex/mplex.py index 0a43640..02e6c3d 100644 --- a/muxer/mplex/muxed_connection.py +++ b/stream_muxer/mplex/mplex.py @@ -1,10 +1,10 @@ import asyncio from .utils import encode_uvarint, decode_uvarint -from .muxed_connection_interface import IMuxedConn -from .muxed_stream import MuxedStream +from .mplex_stream import MplexStream +from ..muxed_connection_interface import IMuxedConn -class MuxedConn(IMuxedConn): +class Mplex(IMuxedConn): """ reference: https://github.com/libp2p/go-mplex/blob/master/multiplex.go """ @@ -57,7 +57,7 @@ class MuxedConn(IMuxedConn): :param multi_addr: multi_addr that stream connects to :return: a new stream """ - stream = MuxedStream(stream_id, multi_addr, self) + stream = MplexStream(stream_id, multi_addr, self) self.streams[stream_id] = stream return stream @@ -69,7 +69,7 @@ class MuxedConn(IMuxedConn): # TODO update to pull out protocol_id from message protocol_id = "/echo/1.0.0" stream_id = await self.stream_queue.get() - stream = MuxedStream(stream_id, False, self) + stream = MplexStream(stream_id, False, self) return stream, stream_id, protocol_id async def send_message(self, flag, data, stream_id): diff --git a/muxer/mplex/muxed_stream.py b/stream_muxer/mplex/mplex_stream.py similarity index 97% rename from muxer/mplex/muxed_stream.py rename to stream_muxer/mplex/mplex_stream.py index 11e04f4..ebf77e2 100644 --- a/muxer/mplex/muxed_stream.py +++ b/stream_muxer/mplex/mplex_stream.py @@ -1,8 +1,8 @@ -from .muxed_stream_interface import IMuxedStream from .constants import HEADER_TAGS +from ..muxed_stream_interface import IMuxedStream -class MuxedStream(IMuxedStream): +class MplexStream(IMuxedStream): """ reference: https://github.com/libp2p/go-mplex/blob/master/stream.go """ diff --git a/muxer/mplex/utils.py b/stream_muxer/mplex/utils.py similarity index 100% rename from muxer/mplex/utils.py rename to stream_muxer/mplex/utils.py diff --git a/muxer/mplex/muxed_connection_interface.py b/stream_muxer/muxed_connection_interface.py similarity index 100% rename from muxer/mplex/muxed_connection_interface.py rename to stream_muxer/muxed_connection_interface.py diff --git a/muxer/mplex/muxed_stream_interface.py b/stream_muxer/muxed_stream_interface.py similarity index 100% rename from muxer/mplex/muxed_stream_interface.py rename to stream_muxer/muxed_stream_interface.py diff --git a/muxer/yamux/__init__.py b/stream_muxer/yamux/__init__.py similarity index 100% rename from muxer/yamux/__init__.py rename to stream_muxer/yamux/__init__.py diff --git a/transport/upgrader.py b/transport/upgrader.py index 66cf21c..eeec0f6 100644 --- a/transport/upgrader.py +++ b/transport/upgrader.py @@ -1,4 +1,4 @@ -from muxer.mplex.muxed_connection import MuxedConn +from stream_muxer.mplex.mplex import Mplex class TransportUpgrader(): @@ -24,4 +24,4 @@ class TransportUpgrader(): # For PoC, no security, default to mplex # TODO do exchange to determine multiplexer - return MuxedConn(conn, initiator) + return Mplex(conn, initiator)