2018-10-27 04:09:39 +08:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
2019-08-05 10:20:30 +08:00
|
|
|
from multiaddr import Multiaddr
|
2019-08-05 11:22:44 +08:00
|
|
|
|
2019-08-05 10:20:30 +08:00
|
|
|
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
2019-08-05 11:22:44 +08:00
|
|
|
|
2019-08-05 10:20:30 +08:00
|
|
|
from .listener_interface import IListener
|
|
|
|
from .typing import THandler
|
2019-08-02 16:32:33 +08:00
|
|
|
|
2018-11-13 02:02:49 +08:00
|
|
|
|
2018-10-27 04:09:39 +08:00
|
|
|
class ITransport(ABC):
|
|
|
|
@abstractmethod
|
2019-09-11 17:13:21 +08:00
|
|
|
async def dial(self, maddr: Multiaddr) -> IRawConnection:
|
2018-10-27 04:09:39 +08:00
|
|
|
"""
|
|
|
|
dial a transport to peer listening on multiaddr
|
|
|
|
:param multiaddr: multiaddr of peer
|
2019-02-25 12:11:54 +08:00
|
|
|
:param self_id: peer_id of the dialer (to send to receiver)
|
2018-10-27 04:09:39 +08:00
|
|
|
:return: list of multiaddrs
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
2019-08-05 10:20:30 +08:00
|
|
|
def create_listener(self, handler_function: THandler) -> IListener:
|
2018-10-27 04:09:39 +08:00
|
|
|
"""
|
|
|
|
create listener on transport
|
|
|
|
: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
|
|
|
|
"""
|