Merge pull request #37 from zixuanzh/open-stream
connecting open_stream to stream constructor
This commit is contained in:
commit
425166c357
|
@ -1,4 +1,5 @@
|
|||
from .muxed_connection_interface import IMuxedConn
|
||||
from transport.stream.Stream import Stream
|
||||
|
||||
class MuxedConn(IMuxedConn):
|
||||
"""
|
||||
|
@ -26,12 +27,14 @@ class MuxedConn(IMuxedConn):
|
|||
"""
|
||||
pass
|
||||
|
||||
def open_stream(self, protocol_id, stream_name):
|
||||
def open_stream(self, protocol_id, stream_name, peer_id, multi_addr):
|
||||
"""
|
||||
creates a new muxed_stream
|
||||
:return: a new stream
|
||||
"""
|
||||
pass
|
||||
|
||||
return Stream(peer_id, multi_addr, self)
|
||||
|
||||
|
||||
def accept_stream(self):
|
||||
"""
|
||||
|
|
|
@ -6,7 +6,7 @@ class Swarm(INetwork):
|
|||
|
||||
def __init__(self, my_peer_id, peerstore):
|
||||
self.my_peer_id = my_peer_id
|
||||
self.peer_store = peer_store
|
||||
self.peer_store = peerstore
|
||||
self.connections = {}
|
||||
|
||||
def set_stream_handler(self, stream_handler):
|
||||
|
@ -41,7 +41,7 @@ class Swarm(INetwork):
|
|||
muxed_connection = MuxedConnection(conn, True)
|
||||
else:
|
||||
raise Exception("No IP and port in addr")
|
||||
return muxed_connection.open_stream(protocol_id, "")
|
||||
return muxed_connection.open_stream(protocol_id, "", peer_id, addrs)
|
||||
|
||||
def listen(self, *args):
|
||||
"""
|
||||
|
|
|
@ -4,13 +4,17 @@ from .stream_interface import IStream
|
|||
class Stream(IStream):
|
||||
|
||||
def __init__(self, peer_id, multi_addr, connection):
|
||||
IStream.__init__(self, peer_id, multi_addr)
|
||||
IStream.__init__(self, peer_id, multi_addr, connection)
|
||||
self.peer_id = peer_id
|
||||
|
||||
stream_ip = multi_addr.get_protocol_value("ip4")
|
||||
stream_port = multi_addr.get_protocol_value("tcp")
|
||||
self.multi_addr = multi_addr
|
||||
|
||||
self.stream_ip = multi_addr.get_protocol_value("ip4")
|
||||
self.stream_port = multi_addr.get_protocol_value("tcp")
|
||||
|
||||
self.reader = connection.reader
|
||||
self.writer = connection.writer
|
||||
|
||||
# TODO should construct protocol id from constructor
|
||||
self.protocol_id = None
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user