mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
fix connection
This commit is contained in:
@ -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
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user