commit
e03c0d4a14
27
network/connection_interface.py
Normal file
27
network/connection_interface.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
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
|
31
network/listener_interface.py
Normal file
31
network/listener_interface.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
class IListener(ABC):
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def listen(self, multiaddr):
|
||||||
|
"""
|
||||||
|
put listener in listening mode and wait for incoming connections
|
||||||
|
:param multiaddr: multiaddr of peer
|
||||||
|
:return: return True if successful
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_addrs(self):
|
||||||
|
"""
|
||||||
|
retrieve list of addresses the listener is listening on
|
||||||
|
:return: return list of addrs
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def close(self, options=None):
|
||||||
|
"""
|
||||||
|
close the listener such that no more connections
|
||||||
|
can be open on this transport instance
|
||||||
|
:param options: optional object potential with timeout
|
||||||
|
a timeout value in ms that fires and destroy all connections
|
||||||
|
:return: return True if successful
|
||||||
|
"""
|
||||||
|
pass
|
|
@ -26,5 +26,5 @@ class INetwork(ABC):
|
||||||
def listen(self, *args):
|
def listen(self, *args):
|
||||||
"""
|
"""
|
||||||
:param *args: one or many multiaddrs to start listening on
|
:param *args: one or many multiaddrs to start listening on
|
||||||
:return: true if at least one success
|
:return: True if at least one success
|
||||||
"""
|
"""
|
||||||
|
|
54
network/tcp.py
Normal file
54
network/tcp.py
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
import asyncio
|
||||||
|
from .transport_interface import ITransport
|
||||||
|
from .listener_interface import IListener
|
||||||
|
|
||||||
|
class TCP(ITransport):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.multiaddr = None
|
||||||
|
|
||||||
|
class Listener(IListener):
|
||||||
|
|
||||||
|
def listen(self, multiaddr):
|
||||||
|
"""
|
||||||
|
put listener in listening mode and wait for incoming connections
|
||||||
|
:param multiaddr: multiaddr of peer
|
||||||
|
:return: return True if successful
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_addrs(self):
|
||||||
|
"""
|
||||||
|
retrieve list of addresses the listener is listening on
|
||||||
|
:return: return list of addrs
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def close(self, options=None):
|
||||||
|
"""
|
||||||
|
close the listener such that no more connections
|
||||||
|
can be open on this transport instance
|
||||||
|
:param options: optional object potential with timeout
|
||||||
|
a timeout value in ms that fires and destroy all connections
|
||||||
|
:return: return True if successful
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def dial(self, multiaddr, options=None):
|
||||||
|
"""
|
||||||
|
dial a transport to peer listening on multiaddr
|
||||||
|
:param multiaddr: multiaddr of peer
|
||||||
|
:param options: optional object
|
||||||
|
:return: list of multiaddrs
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def create_listener(self, handler_function, options=None):
|
||||||
|
"""
|
||||||
|
create listener on transport
|
||||||
|
:param options: optional object with properties the listener must have
|
||||||
|
:param handler_function: a function called when a new conntion is received
|
||||||
|
that takes a connection as argument which implements interface-connection
|
||||||
|
:return: a listener object that implements listener_interface.py
|
||||||
|
"""
|
||||||
|
pass
|
24
network/transport_interface.py
Normal file
24
network/transport_interface.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
class ITransport(ABC):
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def dial(self, multiaddr, options=None):
|
||||||
|
"""
|
||||||
|
dial a transport to peer listening on multiaddr
|
||||||
|
:param multiaddr: multiaddr of peer
|
||||||
|
:param options: optional object
|
||||||
|
:return: list of multiaddrs
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def create_listener(self, handler_function, options=None):
|
||||||
|
"""
|
||||||
|
create listener on transport
|
||||||
|
:param options: optional object with properties the listener must have
|
||||||
|
:param handler_function: a function called when a new conntion is received
|
||||||
|
that takes a connection as argument which implements interface-connection
|
||||||
|
:return: a listener object that implements listener_interface.py
|
||||||
|
"""
|
||||||
|
pass
|
Loading…
Reference in New Issue
Block a user