Modify stream to use connection

This commit is contained in:
Stuckinaboot 2018-10-31 22:40:21 +01:00
parent bab97f5648
commit ad7a449f6e
2 changed files with 5 additions and 7 deletions

View File

@ -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):
"""

View File

@ -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):