Modify stream to use connection
This commit is contained in:
parent
bab97f5648
commit
ad7a449f6e
|
@ -3,17 +3,14 @@ import asyncio
|
||||||
|
|
||||||
class Stream(IStream):
|
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)
|
IStream.__init__(self, peer_id, multi_addr)
|
||||||
self.peer_id = peer_id
|
self.peer_id = peer_id
|
||||||
|
|
||||||
ip = multi_addr.get_protocol_value("ip4")
|
ip = multi_addr.get_protocol_value("ip4")
|
||||||
port = multi_addr.get_protocol_value("tcp")
|
port = multi_addr.get_protocol_value("tcp")
|
||||||
|
self.reader = connection.reader
|
||||||
self.open_connection(ip, port)
|
self.writer = connection.writer
|
||||||
|
|
||||||
async def open_connection(self, ip, port):
|
|
||||||
self.reader, self.writer = await asyncio.open_connection(ip, port)
|
|
||||||
|
|
||||||
def protocol(self):
|
def protocol(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -2,9 +2,10 @@ from abc import ABC, abstractmethod
|
||||||
|
|
||||||
class IStream(ABC):
|
class IStream(ABC):
|
||||||
|
|
||||||
def __init__(self, peer_id, multi_addr):
|
def __init__(self, peer_id, multi_addr, connection):
|
||||||
self.peer_id = peer_id
|
self.peer_id = peer_id
|
||||||
self.multi_addr = multi_addr
|
self.multi_addr = multi_addr
|
||||||
|
self.connection = connection
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def protocol(self):
|
def protocol(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user