From 6e46e3ec096a0cdc8cf09a3e034775a16fd94e85 Mon Sep 17 00:00:00 2001 From: zixuanzh Date: Fri, 26 Oct 2018 21:11:51 +0200 Subject: [PATCH 1/4] conn interface --- network/connection_interface.py | 26 ++++++++++++++++++++++++++ network/tcp.py | 0 network/transport_interface.py | 0 3 files changed, 26 insertions(+) create mode 100644 network/connection_interface.py create mode 100644 network/tcp.py create mode 100644 network/transport_interface.py diff --git a/network/connection_interface.py b/network/connection_interface.py new file mode 100644 index 0000000..356c2ab --- /dev/null +++ b/network/connection_interface.py @@ -0,0 +1,26 @@ +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 + """ diff --git a/network/tcp.py b/network/tcp.py new file mode 100644 index 0000000..e69de29 diff --git a/network/transport_interface.py b/network/transport_interface.py new file mode 100644 index 0000000..e69de29 From b89710a40b357f981c77f2cd3eefc684e9108174 Mon Sep 17 00:00:00 2001 From: zixuanzh Date: Fri, 26 Oct 2018 22:09:39 +0200 Subject: [PATCH 2/4] transport interface --- network/transport_interface.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/network/transport_interface.py b/network/transport_interface.py index e69de29..324ea43 100644 --- a/network/transport_interface.py +++ b/network/transport_interface.py @@ -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 From 4f5f95352396c3b50381b5c2bfbe51eca38ab622 Mon Sep 17 00:00:00 2001 From: zixuanzh Date: Fri, 26 Oct 2018 22:16:24 +0200 Subject: [PATCH 3/4] listener interface --- network/connection_interface.py | 3 ++- network/listener_interface.py | 32 ++++++++++++++++++++++++++++++++ network/network_interface.py | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 network/listener_interface.py diff --git a/network/connection_interface.py b/network/connection_interface.py index 356c2ab..813ea7d 100644 --- a/network/connection_interface.py +++ b/network/connection_interface.py @@ -22,5 +22,6 @@ class IConnection(ABC): def set_peer_info(self, peer_info): """ :param peer_info: a peer info object that contains info of peer - :return: true if successful + :return: True if successful """ + pass diff --git a/network/listener_interface.py b/network/listener_interface.py new file mode 100644 index 0000000..05b2aed --- /dev/null +++ b/network/listener_interface.py @@ -0,0 +1,32 @@ +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 + diff --git a/network/network_interface.py b/network/network_interface.py index ae805d3..7fb0176 100644 --- a/network/network_interface.py +++ b/network/network_interface.py @@ -26,5 +26,5 @@ class INetwork(ABC): def listen(self, *args): """ :param *args: one or many multiaddrs to start listening on - :return: true if at least one success + :return: True if at least one success """ From 64a82fd470c43247571e9ed75ac3f80cb93f3bb6 Mon Sep 17 00:00:00 2001 From: zixuanzh Date: Sat, 27 Oct 2018 00:06:56 +0200 Subject: [PATCH 4/4] 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 05b2aed..9398bf9 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 e69de29..d2a0687 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