fix connection

This commit is contained in:
zixuanzh
2018-10-31 23:08:47 +01:00
parent ad7a449f6e
commit 2315388589
3 changed files with 10 additions and 38 deletions

View File

@ -1,27 +0,0 @@
from abc import ABC, abstractmethod
class IConnection(ABC):
@abstractmethod
def get_observed_addrs(self):
"""
retrieve observed addresses from underlying transport
:return: list of multiaddrs
"""
pass
@abstractmethod
def get_peer_info(self):
"""
retrieve peer info object that the connection connects to
:return: a peer info object
"""
pass
@abstractmethod
def set_peer_info(self, peer_info):
"""
:param peer_info: a peer info object that contains info of peer
:return: True if successful
"""
pass

View File

@ -1,10 +1,14 @@
from .raw_connection import IRawConnection
import asyncio
from .raw_connection_interface import IRawConnection
class RawConnection(IRawConnection):
def __init__(self, ip, port):
self.ip = ip
self.port = port
self.conn_ip = ip
self.conn_port = port
self.reader = None
self.writer = None
async def open_connection(self):
self.reader, self.writer = await asyncio.open_connection(self.ip, self.port)
self.reader, self.writer = \
await asyncio.open_connection(self.conn_ip, self.conn_port)

View File

@ -1,13 +1,8 @@
from abc import ABC, abstractmethod
import asyncio
class IRawConnection(ABC):
@abstractmethod
def __init__(self, ip, port):
pass
@abstractmethod
async def open_connection(self):
pass