py-libp2p/libp2p/transport/listener_interface.py

30 lines
783 B
Python
Raw Normal View History

2018-10-27 04:16:24 +08:00
from abc import ABC, abstractmethod
from typing import List
from multiaddr import Multiaddr
2019-08-02 16:32:33 +08:00
2018-11-13 02:02:49 +08:00
2018-10-27 04:16:24 +08:00
class IListener(ABC):
2018-10-27 06:06:56 +08:00
@abstractmethod
async def listen(self, maddr: Multiaddr) -> bool:
2018-10-27 04:16:24 +08:00
"""
put listener in listening mode and wait for incoming connections
:param maddr: multiaddr of peer
2018-10-27 04:16:24 +08:00
:return: return True if successful
"""
@abstractmethod
def get_addrs(self) -> List[Multiaddr]:
2018-10-27 04:16:24 +08:00
"""
retrieve list of addresses the listener is listening on
:return: return list of addrs
"""
@abstractmethod
2019-08-02 16:32:33 +08:00
def close(self) -> bool:
2018-10-27 04:16:24 +08:00
"""
close the listener such that no more connections
can be open on this transport instance
:return: return True if successful
"""