From 64a82fd470c43247571e9ed75ac3f80cb93f3bb6 Mon Sep 17 00:00:00 2001 From: zixuanzh Date: Sat, 27 Oct 2018 00:06:56 +0200 Subject: [PATCH] transport scaffolding --- network/listener_interface.py | 3 +- network/tcp.py | 54 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/network/listener_interface.py b/network/listener_interface.py index 05b2aed4..9398bf98 100644 --- a/network/listener_interface.py +++ b/network/listener_interface.py @@ -2,7 +2,7 @@ from abc import ABC, abstractmethod class IListener(ABC): - @abstractmethod + @abstractmethod def listen(self, multiaddr): """ put listener in listening mode and wait for incoming connections @@ -29,4 +29,3 @@ class IListener(ABC): :return: return True if successful """ pass - diff --git a/network/tcp.py b/network/tcp.py index e69de29b..d2a06875 100644 --- a/network/tcp.py +++ b/network/tcp.py @@ -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