connecting open_stream to stream constructor

This commit is contained in:
Alex Haynes 2018-11-11 11:52:26 -05:00
parent 7d4227f269
commit 65fe2e400e
3 changed files with 14 additions and 7 deletions

View File

@ -1,4 +1,5 @@
from .muxed_connection_interface import IMuxedConn from .muxed_connection_interface import IMuxedConn
from transport.stream.Stream import Stream
class MuxedConn(IMuxedConn): class MuxedConn(IMuxedConn):
""" """
@ -26,12 +27,14 @@ class MuxedConn(IMuxedConn):
""" """
pass 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 creates a new muxed_stream
:return: a new stream :return: a new stream
""" """
pass
return Stream(peer_id, multi_addr, self)
def accept_stream(self): def accept_stream(self):
""" """

View File

@ -6,7 +6,7 @@ class Swarm(INetwork):
def __init__(self, my_peer_id, peerstore): def __init__(self, my_peer_id, peerstore):
self.my_peer_id = my_peer_id self.my_peer_id = my_peer_id
self.peer_store = peer_store self.peer_store = peerstore
self.connections = {} self.connections = {}
def set_stream_handler(self, stream_handler): def set_stream_handler(self, stream_handler):
@ -41,7 +41,7 @@ class Swarm(INetwork):
muxed_connection = MuxedConnection(conn, True) muxed_connection = MuxedConnection(conn, True)
else: else:
raise Exception("No IP and port in addr") 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): def listen(self, *args):
""" """

View File

@ -4,13 +4,17 @@ from .stream_interface import IStream
class Stream(IStream): class Stream(IStream):
def __init__(self, peer_id, multi_addr, connection): 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 self.peer_id = peer_id
stream_ip = multi_addr.get_protocol_value("ip4") self.multi_addr = multi_addr
stream_port = multi_addr.get_protocol_value("tcp")
self.stream_ip = multi_addr.get_protocol_value("ip4")
self.stream_port = multi_addr.get_protocol_value("tcp")
self.reader = connection.reader self.reader = connection.reader
self.writer = connection.writer self.writer = connection.writer
# TODO should construct protocol id from constructor # TODO should construct protocol id from constructor
self.protocol_id = None self.protocol_id = None