Browse Source

Modify stream to use connection

pull/28/head
Stuckinaboot 6 years ago
parent
commit
ad7a449f6e
  1. 9
      stream/stream.py
  2. 3
      stream/stream_interface.py

9
stream/stream.py

@ -3,17 +3,14 @@ import asyncio
class Stream(IStream):
def __init__(self, peer_id, multi_addr):
def __init__(self, peer_id, multi_addr, connection):
IStream.__init__(self, peer_id, multi_addr)
self.peer_id = peer_id
ip = multi_addr.get_protocol_value("ip4")
port = multi_addr.get_protocol_value("tcp")
self.open_connection(ip, port)
async def open_connection(self, ip, port):
self.reader, self.writer = await asyncio.open_connection(ip, port)
self.reader = connection.reader
self.writer = connection.writer
def protocol(self):
"""

3
stream/stream_interface.py

@ -2,9 +2,10 @@ from abc import ABC, abstractmethod
class IStream(ABC):
def __init__(self, peer_id, multi_addr):
def __init__(self, peer_id, multi_addr, connection):
self.peer_id = peer_id
self.multi_addr = multi_addr
self.connection = connection
@abstractmethod
def protocol(self):

Loading…
Cancel
Save