mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-09 14:40:53 +00:00
refactored and moved all interfaces to abc.py (#504)
* refactored : host_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored : network_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored : notifee_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored : net_connection_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored: raw_connection_interface, secure_conn_interface and stream_muxer abc.py * refactored: addrbook_interface * refactored :peerdata_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :peermetadata_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :multiselect_client_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :multiselect_communicator_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :multiselect_muxer_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :interfaces Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :security_transport_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :listener_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * moved all interfaces and typing files Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * fixed documentation and moved pubsub abc.py Co-authored-by: Khwahish Patel <khwahish.p1@ahduni.edu.in> * added exclude-members in custom_types docs * added : newsfragment for moving all interfaces to libp2p.abc --------- Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> Co-authored-by: Mystical <125946525+mystical-prog@users.noreply.github.com>
This commit is contained in:
@ -1,32 +0,0 @@
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
|
||||
from multiaddr import (
|
||||
Multiaddr,
|
||||
)
|
||||
import trio
|
||||
|
||||
|
||||
class IListener(ABC):
|
||||
@abstractmethod
|
||||
async def listen(self, maddr: Multiaddr, nursery: trio.Nursery) -> bool:
|
||||
"""
|
||||
Put listener in listening mode and wait for incoming connections.
|
||||
|
||||
:param maddr: multiaddr of peer
|
||||
:return: return True if successful
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_addrs(self) -> tuple[Multiaddr, ...]:
|
||||
"""
|
||||
Retrieve list of addresses the listener is listening on.
|
||||
|
||||
:return: return list of addrs
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def close(self) -> None:
|
||||
...
|
||||
@ -15,27 +15,23 @@ from trio_typing import (
|
||||
TaskStatus,
|
||||
)
|
||||
|
||||
from libp2p.abc import (
|
||||
IListener,
|
||||
IRawConnection,
|
||||
ITransport,
|
||||
)
|
||||
from libp2p.custom_types import (
|
||||
THandler,
|
||||
)
|
||||
from libp2p.io.trio import (
|
||||
TrioTCPStream,
|
||||
)
|
||||
from libp2p.network.connection.raw_connection import (
|
||||
RawConnection,
|
||||
)
|
||||
from libp2p.network.connection.raw_connection_interface import (
|
||||
IRawConnection,
|
||||
)
|
||||
from libp2p.transport.exceptions import (
|
||||
OpenConnectionError,
|
||||
)
|
||||
from libp2p.transport.listener_interface import (
|
||||
IListener,
|
||||
)
|
||||
from libp2p.transport.transport_interface import (
|
||||
ITransport,
|
||||
)
|
||||
from libp2p.transport.typing import (
|
||||
THandler,
|
||||
)
|
||||
|
||||
logger = logging.getLogger("libp2p.transport.tcp")
|
||||
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
|
||||
from multiaddr import (
|
||||
Multiaddr,
|
||||
)
|
||||
|
||||
from libp2p.network.connection.raw_connection_interface import (
|
||||
IRawConnection,
|
||||
)
|
||||
|
||||
from .listener_interface import (
|
||||
IListener,
|
||||
)
|
||||
from .typing import (
|
||||
THandler,
|
||||
)
|
||||
|
||||
|
||||
class ITransport(ABC):
|
||||
@abstractmethod
|
||||
async def dial(self, maddr: Multiaddr) -> IRawConnection:
|
||||
"""
|
||||
Dial a transport to peer listening on multiaddr.
|
||||
|
||||
:param multiaddr: multiaddr of peer
|
||||
:param self_id: peer_id of the dialer (to send to receiver)
|
||||
:return: list of multiaddrs
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def create_listener(self, handler_function: THandler) -> IListener:
|
||||
"""
|
||||
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
|
||||
"""
|
||||
@ -1,25 +0,0 @@
|
||||
from collections.abc import (
|
||||
Awaitable,
|
||||
Mapping,
|
||||
)
|
||||
from typing import (
|
||||
Callable,
|
||||
)
|
||||
|
||||
from libp2p.custom_types import (
|
||||
TProtocol,
|
||||
)
|
||||
from libp2p.io.abc import (
|
||||
ReadWriteCloser,
|
||||
)
|
||||
from libp2p.security.secure_transport_interface import (
|
||||
ISecureTransport,
|
||||
)
|
||||
from libp2p.stream_muxer.abc import (
|
||||
IMuxedConn,
|
||||
)
|
||||
|
||||
THandler = Callable[[ReadWriteCloser], Awaitable[None]]
|
||||
TSecurityOptions = Mapping[TProtocol, ISecureTransport]
|
||||
TMuxerClass = type[IMuxedConn]
|
||||
TMuxerOptions = Mapping[TProtocol, TMuxerClass]
|
||||
@ -1,5 +1,13 @@
|
||||
from libp2p.network.connection.raw_connection_interface import (
|
||||
from libp2p.abc import (
|
||||
IListener,
|
||||
IMuxedConn,
|
||||
IRawConnection,
|
||||
ISecureConn,
|
||||
ITransport,
|
||||
)
|
||||
from libp2p.custom_types import (
|
||||
TMuxerOptions,
|
||||
TSecurityOptions,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
@ -11,15 +19,9 @@ from libp2p.protocol_muxer.exceptions import (
|
||||
from libp2p.security.exceptions import (
|
||||
HandshakeFailure,
|
||||
)
|
||||
from libp2p.security.secure_conn_interface import (
|
||||
ISecureConn,
|
||||
)
|
||||
from libp2p.security.security_multistream import (
|
||||
SecurityMultistream,
|
||||
)
|
||||
from libp2p.stream_muxer.abc import (
|
||||
IMuxedConn,
|
||||
)
|
||||
from libp2p.stream_muxer.muxer_multistream import (
|
||||
MuxerMultistream,
|
||||
)
|
||||
@ -27,17 +29,6 @@ from libp2p.transport.exceptions import (
|
||||
MuxerUpgradeFailure,
|
||||
SecurityUpgradeFailure,
|
||||
)
|
||||
from libp2p.transport.typing import (
|
||||
TMuxerOptions,
|
||||
TSecurityOptions,
|
||||
)
|
||||
|
||||
from .listener_interface import (
|
||||
IListener,
|
||||
)
|
||||
from .transport_interface import (
|
||||
ITransport,
|
||||
)
|
||||
|
||||
|
||||
class TransportUpgrader:
|
||||
|
||||
Reference in New Issue
Block a user