From 4b971410bcb69563a378899d0c2f8e3298700c89 Mon Sep 17 00:00:00 2001 From: Alex Haynes Date: Sun, 11 Nov 2018 20:32:23 -0500 Subject: [PATCH] accept stream --- muxer/mplex/muxed_connection.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/muxer/mplex/muxed_connection.py b/muxer/mplex/muxed_connection.py index 9603ab0..dc0bf8a 100644 --- a/muxer/mplex/muxed_connection.py +++ b/muxer/mplex/muxed_connection.py @@ -53,7 +53,25 @@ class MuxedConn(IMuxedConn): accepts a muxed stream opened by the other end :return: the accepted stream """ - pass + data = bytearray() + while True: + chunk = self.raw_conn.reader.read(100) + if not chunk: + break + data += chunk + header, end_index = decode_uvarint(data, 0) + length, end_index = decode_uvarint(data, end_index) + message = data[end_index, end_index + length] + + flag = header & 0x07 + stream_id = header >> 3 + + # TODO update to pull out protocol_id from message + protocol_id = "/echo/1.0.0" + + stream = MuxedStream(stream_id, False, self) + + return stream, stream_id, protocol_id def send_message(self, flag, data, stream_id): """ @@ -95,7 +113,6 @@ class MuxedConn(IMuxedConn): # Read message length # Read message into corresponding buffer - def add_incoming_task(self): loop = asyncio.get_event_loop() handle_incoming_task = loop.create_task(self.handle_incoming())