diff --git a/muxer/mplex/muxed_connection.py b/muxer/mplex/muxed_connection.py index c0b9926..b7caa62 100644 --- a/muxer/mplex/muxed_connection.py +++ b/muxer/mplex/muxed_connection.py @@ -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): """ diff --git a/network/swarm.py b/network/swarm.py index 231ee46..d9f2b59 100644 --- a/network/swarm.py +++ b/network/swarm.py @@ -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): """ diff --git a/transport/stream/stream.py b/transport/stream/stream.py index cce6ad6..34daf97 100644 --- a/transport/stream/stream.py +++ b/transport/stream/stream.py @@ -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