muxer scaffolding

This commit is contained in:
zixuanzh 2018-10-31 23:02:00 +01:00
parent 19650d0f72
commit 8756320e85
6 changed files with 22 additions and 19 deletions

View File

@ -1,6 +1,6 @@
from .muxed_connection_interface import IMuxedConnection
from .muxed_connection_interface import IMuxedConn
class MuxedConnection(IMuxedConnection):
class MuxedConn(IMuxedConn):
"""
reference: https://github.com/libp2p/go-mplex/blob/master/multiplex.go
"""
@ -26,7 +26,7 @@ class MuxedConnection(IMuxedConnection):
"""
pass
def open_stream(self):
def open_stream(self, protocol_id, stream_name):
"""
creates a new muxed_stream
:return: a new stream
@ -38,4 +38,4 @@ class MuxedConnection(IMuxedConnection):
accepts a muxed stream opened by the other end
:return: the accepted stream
"""
pass
pass

View File

@ -16,9 +16,11 @@ class IMuxedConn(ABC):
pass
@abstractmethod
def open_stream(self):
def open_stream(self, protocol_id, stream_name):
"""
creates a new muxed_stream
:param protocol_id: id to be associated with stream
:param stream_name: name as part of identifier
:return: a new stream
"""
pass
@ -29,4 +31,4 @@ class IMuxedConn(ABC):
accepts a muxed stream opened by the other end
:return: the accepted stream
"""
pass
pass

View File

@ -1,11 +1,12 @@
from .muxed_stream_interface import IMuxedStream
class MuxedStream(IMuxedStream):
"""
reference: https://github.com/libp2p/go-mplex/blob/master/stream.go
"""
def __init__(self, stream_id, stream_name):
self.id = stream_id
"""
reference: https://github.com/libp2p/go-mplex/blob/master/stream.go
"""
def __init__(self, protocol_id, stream_name):
self.protocol_id = protocol_id
self.name = stream_name
def read(self):
@ -15,7 +16,7 @@ class MuxedStream(IMuxedStream):
pass
def close(self):
pass
pass
def reset(self):
"""

View File

@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from datetime import time
# from datetime import time
class IMuxedStream(ABC):

View File

@ -25,19 +25,19 @@ class Multiplex(object):
"""
return self.muxed_conn.is_closed()
def open_stream(self):
def open_stream(self, protocol_id, stream_name):
"""
creates a new muxed_stream
:return: a new stream
"""
return self.muxed_conn.open_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
"""
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):