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

@ -2,6 +2,9 @@ from typing import (
Optional,
)
from libp2p.abc import (
ISecureConn,
)
from libp2p.crypto.keys import (
PrivateKey,
PublicKey,
@ -9,9 +12,6 @@ from libp2p.crypto.keys import (
from libp2p.peer.id import (
ID,
)
from libp2p.security.secure_conn_interface import (
ISecureConn,
)
class BaseSession(ISecureConn):

View File

@ -3,15 +3,15 @@ from typing import (
Callable,
)
from libp2p.abc import (
ISecureTransport,
)
from libp2p.crypto.keys import (
KeyPair,
)
from libp2p.peer.id import (
ID,
)
from libp2p.security.secure_transport_interface import (
ISecureTransport,
)
def default_secure_bytes_provider(n: int) -> bytes:

View File

@ -1,3 +1,7 @@
from libp2p.abc import (
IRawConnection,
ISecureConn,
)
from libp2p.crypto.exceptions import (
MissingDeserializerError,
)
@ -23,9 +27,6 @@ from libp2p.io.msgio import (
from libp2p.network.connection.exceptions import (
RawConnError,
)
from libp2p.network.connection.raw_connection_interface import (
IRawConnection,
)
from libp2p.peer.id import (
ID,
)
@ -38,9 +39,6 @@ from libp2p.security.base_transport import (
from libp2p.security.exceptions import (
HandshakeFailure,
)
from libp2p.security.secure_conn_interface import (
ISecureConn,
)
from .pb import (
plaintext_pb2,

View File

@ -4,6 +4,9 @@ from typing import (
from noise.connection import NoiseConnection as NoiseState
from libp2p.abc import (
IRawConnection,
)
from libp2p.io.abc import (
EncryptedMsgReadWriter,
MsgReadWriteCloser,
@ -12,9 +15,6 @@ from libp2p.io.abc import (
from libp2p.io.msgio import (
FixedSizeLenMsgReadWriter,
)
from libp2p.network.connection.raw_connection_interface import (
IRawConnection,
)
SIZE_NOISE_MESSAGE_LEN = 2
MAX_NOISE_MESSAGE_LEN = 2 ** (8 * SIZE_NOISE_MESSAGE_LEN) - 1

View File

@ -10,6 +10,10 @@ from noise.backends.default.keypairs import KeyPair as NoiseKeyPair
from noise.connection import Keypair as NoiseKeypairEnum
from noise.connection import NoiseConnection as NoiseState
from libp2p.abc import (
IRawConnection,
ISecureConn,
)
from libp2p.crypto.ed25519 import (
Ed25519PublicKey,
)
@ -17,15 +21,9 @@ from libp2p.crypto.keys import (
PrivateKey,
PublicKey,
)
from libp2p.network.connection.raw_connection_interface import (
IRawConnection,
)
from libp2p.peer.id import (
ID,
)
from libp2p.security.secure_conn_interface import (
ISecureConn,
)
from libp2p.security.secure_session import (
SecureSession,
)

View File

@ -1,3 +1,8 @@
from libp2p.abc import (
IRawConnection,
ISecureConn,
ISecureTransport,
)
from libp2p.crypto.keys import (
KeyPair,
PrivateKey,
@ -5,18 +10,9 @@ from libp2p.crypto.keys import (
from libp2p.custom_types import (
TProtocol,
)
from libp2p.network.connection.raw_connection_interface import (
IRawConnection,
)
from libp2p.peer.id import (
ID,
)
from libp2p.security.secure_conn_interface import (
ISecureConn,
)
from libp2p.security.secure_transport_interface import (
ISecureTransport,
)
from .patterns import (
IPattern,

View File

@ -8,6 +8,10 @@ from typing import (
import multihash
from libp2p.abc import (
IRawConnection,
ISecureConn,
)
from libp2p.crypto.authenticated_encryption import (
EncryptionParameters as AuthenticatedEncryptionParameters,
)
@ -47,16 +51,10 @@ from libp2p.io.exceptions import (
from libp2p.io.msgio import (
FixedSizeLenMsgReadWriter,
)
from libp2p.network.connection.raw_connection_interface import (
IRawConnection,
)
from libp2p.peer.id import ID as PeerID
from libp2p.security.base_transport import (
BaseSecureTransport,
)
from libp2p.security.secure_conn_interface import (
ISecureConn,
)
from libp2p.security.secure_session import (
SecureSession,
)

View File

@ -1,44 +0,0 @@
from abc import (
ABC,
abstractmethod,
)
from libp2p.crypto.keys import (
PrivateKey,
PublicKey,
)
from libp2p.network.connection.raw_connection_interface import (
IRawConnection,
)
from libp2p.peer.id import (
ID,
)
"""
Represents a secured connection object, which includes a connection and details about
the security involved in the secured connection
Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interface.go
"""
class AbstractSecureConn(ABC):
@abstractmethod
def get_local_peer(self) -> ID:
pass
@abstractmethod
def get_local_private_key(self) -> PrivateKey:
pass
@abstractmethod
def get_remote_peer(self) -> ID:
pass
@abstractmethod
def get_remote_public_key(self) -> PublicKey:
pass
class ISecureConn(AbstractSecureConn, IRawConnection):
pass

View File

@ -1,42 +0,0 @@
from abc import (
ABC,
abstractmethod,
)
from libp2p.network.connection.raw_connection_interface import (
IRawConnection,
)
from libp2p.peer.id import (
ID,
)
from libp2p.security.secure_conn_interface import (
ISecureConn,
)
"""
Transport that is used to secure a connection. This transport is
chosen by a security transport multistream module.
Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interface.go
"""
class ISecureTransport(ABC):
@abstractmethod
async def secure_inbound(self, conn: IRawConnection) -> ISecureConn:
"""
Secure the connection, either locally or by communicating with opposing
node via conn, for an inbound connection (i.e. we are not the
initiator)
:return: secure connection object (that implements secure_conn_interface)
"""
@abstractmethod
async def secure_outbound(self, conn: IRawConnection, peer_id: ID) -> ISecureConn:
"""
Secure the connection, either locally or by communicating with opposing
node via conn, for an inbound connection (i.e. we are the initiator)
:return: secure connection object (that implements secure_conn_interface)
"""

View File

@ -5,11 +5,14 @@ from collections import (
OrderedDict,
)
from libp2p.abc import (
IRawConnection,
ISecureConn,
ISecureTransport,
)
from libp2p.custom_types import (
TProtocol,
)
from libp2p.network.connection.raw_connection_interface import (
IRawConnection,
TSecurityOptions,
)
from libp2p.peer.id import (
ID,
@ -23,15 +26,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.security.secure_transport_interface import (
ISecureTransport,
)
from libp2p.transport.typing import (
TSecurityOptions,
)
"""
Represents a secured connection object, which includes a connection and details about