Merge pull request #28 from zixuanzh/raw-connection

Raw connection
This commit is contained in:
ZX
2018-10-31 23:32:11 +01:00
committed by GitHub
9 changed files with 68 additions and 48 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

@ -0,0 +1,14 @@
import asyncio
from .raw_connection_interface import IRawConnection
class RawConnection(IRawConnection):
def __init__(self, ip, 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.conn_ip, self.conn_port)

View File

@ -0,0 +1,8 @@
from abc import ABC, abstractmethod
class IRawConnection(ABC):
@abstractmethod
async def open_connection(self):
pass