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:
Khwahish Patel
2025-02-22 04:31:45 +05:30
committed by GitHub
parent 4e64347f1e
commit d7eab27564
77 changed files with 1338 additions and 1883 deletions

View File

@ -1,85 +0,0 @@
from abc import (
ABC,
abstractmethod,
)
import trio
from libp2p.io.abc import (
ReadWriteCloser,
)
from libp2p.peer.id import (
ID,
)
from libp2p.security.secure_conn_interface import (
ISecureConn,
)
class IMuxedConn(ABC):
"""
reference: https://github.com/libp2p/go-stream-muxer/blob/master/muxer.go
"""
peer_id: ID
event_started: trio.Event
@abstractmethod
def __init__(self, conn: ISecureConn, peer_id: ID) -> None:
"""
Create a new muxed connection.
:param conn: an instance of secured connection
for new muxed streams
:param peer_id: peer_id of peer the connection is to
"""
@property
@abstractmethod
def is_initiator(self) -> bool:
"""If this connection is the initiator."""
@abstractmethod
async def start(self) -> None:
"""Start the multiplexer."""
@abstractmethod
async def close(self) -> None:
"""Close connection."""
@property
@abstractmethod
def is_closed(self) -> bool:
"""
Check connection is fully closed.
:return: true if successful
"""
@abstractmethod
async def open_stream(self) -> "IMuxedStream":
"""
Create a new muxed_stream.
:return: a new ``IMuxedStream`` stream
"""
@abstractmethod
async def accept_stream(self) -> "IMuxedStream":
"""Accept a muxed stream opened by the other end."""
class IMuxedStream(ReadWriteCloser):
muxed_conn: IMuxedConn
@abstractmethod
async def reset(self) -> None:
"""Close both ends of the stream tells this remote side to hang up."""
@abstractmethod
def set_deadline(self, ttl: int) -> bool:
"""
Set deadline for muxed stream.
:return: a new stream
"""

View File

@ -5,6 +5,11 @@ from typing import (
import trio
from libp2p.abc import (
IMuxedConn,
IMuxedStream,
ISecureConn,
)
from libp2p.custom_types import (
TProtocol,
)
@ -20,13 +25,6 @@ from libp2p.network.connection.exceptions import (
from libp2p.peer.id import (
ID,
)
from libp2p.security.secure_conn_interface import (
ISecureConn,
)
from libp2p.stream_muxer.abc import (
IMuxedConn,
IMuxedStream,
)
from libp2p.utils import (
decode_uvarint_from_stream,
encode_uvarint,

View File

@ -4,7 +4,7 @@ from typing import (
import trio
from libp2p.stream_muxer.abc import (
from libp2p.abc import (
IMuxedStream,
)
from libp2p.stream_muxer.exceptions import (

View File

@ -2,11 +2,15 @@ from collections import (
OrderedDict,
)
from libp2p.custom_types import (
TProtocol,
)
from libp2p.network.connection.raw_connection_interface import (
from libp2p.abc import (
IMuxedConn,
IRawConnection,
ISecureConn,
)
from libp2p.custom_types import (
TMuxerClass,
TMuxerOptions,
TProtocol,
)
from libp2p.peer.id import (
ID,
@ -20,17 +24,6 @@ from libp2p.protocol_muxer.multiselect_client import (
from libp2p.protocol_muxer.multiselect_communicator import (
MultiselectCommunicator,
)
from libp2p.security.secure_conn_interface import (
ISecureConn,
)
from libp2p.transport.typing import (
TMuxerClass,
TMuxerOptions,
)
from .abc import (
IMuxedConn,
)
# FIXME: add negotiate timeout to `MuxerMultistream`
DEFAULT_NEGOTIATE_TIMEOUT = 60