move stream and connection interfaces to abc
This commit is contained in:
parent
c804f5ad19
commit
9e0a806218
@ -5,7 +5,7 @@ from multiaddr import Multiaddr
|
|||||||
|
|
||||||
from libp2p.peer.id import ID
|
from libp2p.peer.id import ID
|
||||||
from libp2p.peer.peerstore import PeerStore
|
from libp2p.peer.peerstore import PeerStore
|
||||||
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
from libp2p.stream_muxer.abc import IMuxedConn
|
||||||
from libp2p.transport.listener_interface import IListener
|
from libp2p.transport.listener_interface import IListener
|
||||||
|
|
||||||
from .stream.net_stream_interface import INetStream
|
from .stream.net_stream_interface import INetStream
|
||||||
|
@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
|
|||||||
from multiaddr import Multiaddr
|
from multiaddr import Multiaddr
|
||||||
|
|
||||||
from libp2p.network.stream.net_stream_interface import INetStream
|
from libp2p.network.stream.net_stream_interface import INetStream
|
||||||
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
from libp2p.stream_muxer.abc import IMuxedConn
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .network_interface import INetwork
|
from .network_interface import INetwork
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
from libp2p.stream_muxer.abc import IMuxedConn, IMuxedStream
|
||||||
from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream
|
|
||||||
|
|
||||||
from .net_stream_interface import INetStream
|
from .net_stream_interface import INetStream
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
from libp2p.stream_muxer.abc import IMuxedConn
|
||||||
|
|
||||||
|
|
||||||
class INetStream(ABC):
|
class INetStream(ABC):
|
||||||
|
@ -8,8 +8,7 @@ from libp2p.peer.peerstore import PeerStore
|
|||||||
from libp2p.protocol_muxer.multiselect import Multiselect
|
from libp2p.protocol_muxer.multiselect import Multiselect
|
||||||
from libp2p.protocol_muxer.multiselect_client import MultiselectClient
|
from libp2p.protocol_muxer.multiselect_client import MultiselectClient
|
||||||
from libp2p.routing.interfaces import IPeerRouting
|
from libp2p.routing.interfaces import IPeerRouting
|
||||||
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
from libp2p.stream_muxer.abc import IMuxedConn, IMuxedStream
|
||||||
from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream
|
|
||||||
from libp2p.transport.listener_interface import IListener
|
from libp2p.transport.listener_interface import IListener
|
||||||
from libp2p.transport.transport_interface import ITransport
|
from libp2p.transport.transport_interface import ITransport
|
||||||
from libp2p.transport.upgrader import TransportUpgrader
|
from libp2p.transport.upgrader import TransportUpgrader
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import Awaitable, Callable
|
from typing import Awaitable, Callable
|
||||||
from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream
|
from libp2p.stream_muxer.abc import IMuxedStream
|
||||||
|
|
||||||
GenericProtocolHandlerFn = Callable[[IMuxedStream], Awaitable[None]]
|
GenericProtocolHandlerFn = Callable[[IMuxedStream], Awaitable[None]]
|
||||||
|
@ -5,7 +5,7 @@ from multiaddr import Multiaddr
|
|||||||
from libp2p.network.network_interface import INetwork
|
from libp2p.network.network_interface import INetwork
|
||||||
from libp2p.network.notifee_interface import INotifee
|
from libp2p.network.notifee_interface import INotifee
|
||||||
from libp2p.network.stream.net_stream_interface import INetStream
|
from libp2p.network.stream.net_stream_interface import INetStream
|
||||||
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
from libp2p.stream_muxer.abc import IMuxedConn
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import asyncio
|
import asyncio
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
from multiaddr import Multiaddr
|
|
||||||
from libp2p.security.secure_conn_interface import ISecureConn
|
|
||||||
from libp2p.network.typing import GenericProtocolHandlerFn
|
|
||||||
from libp2p.peer.id import ID
|
from libp2p.peer.id import ID
|
||||||
|
from libp2p.security.secure_conn_interface import ISecureConn
|
||||||
from libp2p.stream_muxer.mplex.constants import HeaderTags
|
from libp2p.stream_muxer.mplex.constants import HeaderTags
|
||||||
|
from multiaddr import Multiaddr
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream
|
# Prevent GenericProtocolHandlerFn introducing circular dependencies
|
||||||
|
from libp2p.network.typing import GenericProtocolHandlerFn # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
class IMuxedConn(ABC):
|
class IMuxedConn(ABC):
|
||||||
@ -23,10 +22,7 @@ class IMuxedConn(ABC):
|
|||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self, conn: ISecureConn, generic_protocol_handler: "GenericProtocolHandlerFn", peer_id: ID
|
||||||
conn: ISecureConn,
|
|
||||||
generic_protocol_handler: GenericProtocolHandlerFn,
|
|
||||||
peer_id: ID,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
create a new muxed connection
|
create a new muxed connection
|
||||||
@ -58,9 +54,7 @@ class IMuxedConn(ABC):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def open_stream(
|
async def open_stream(self, protocol_id: str, multi_addr: Multiaddr) -> "IMuxedStream":
|
||||||
self, protocol_id: str, multi_addr: Multiaddr
|
|
||||||
) -> "IMuxedStream":
|
|
||||||
"""
|
"""
|
||||||
creates a new muxed_stream
|
creates a new muxed_stream
|
||||||
:param protocol_id: protocol_id of stream
|
:param protocol_id: protocol_id of stream
|
||||||
@ -82,3 +76,44 @@ class IMuxedConn(ABC):
|
|||||||
:param data: data to send in the message
|
:param data: data to send in the message
|
||||||
:param stream_id: stream the message is in
|
:param stream_id: stream the message is in
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class IMuxedStream(ABC):
|
||||||
|
|
||||||
|
mplex_conn: IMuxedConn
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def read(self) -> bytes:
|
||||||
|
"""
|
||||||
|
reads from the underlying muxed_conn
|
||||||
|
:return: bytes of input
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def write(self, data: bytes) -> int:
|
||||||
|
"""
|
||||||
|
writes to the underlying muxed_conn
|
||||||
|
:return: number of bytes written
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def close(self) -> bool:
|
||||||
|
"""
|
||||||
|
close the underlying muxed_conn
|
||||||
|
:return: true if successful
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def reset(self) -> bool:
|
||||||
|
"""
|
||||||
|
closes both ends of the stream
|
||||||
|
tells this remote side to hang up
|
||||||
|
:return: true if successful
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def set_deadline(self, ttl: float) -> bool:
|
||||||
|
"""
|
||||||
|
set deadline for muxed stream
|
||||||
|
:return: a new stream
|
||||||
|
"""
|
@ -6,8 +6,7 @@ from libp2p.security.secure_conn_interface import ISecureConn
|
|||||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||||
from libp2p.network.typing import GenericProtocolHandlerFn
|
from libp2p.network.typing import GenericProtocolHandlerFn
|
||||||
from libp2p.peer.id import ID
|
from libp2p.peer.id import ID
|
||||||
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
from libp2p.stream_muxer.abc import IMuxedConn, IMuxedStream
|
||||||
from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream
|
|
||||||
|
|
||||||
from .constants import HeaderTags
|
from .constants import HeaderTags
|
||||||
from .utils import encode_uvarint, decode_uvarint_from_stream
|
from .utils import encode_uvarint, decode_uvarint_from_stream
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream
|
from libp2p.stream_muxer.abc import IMuxedStream, IMuxedConn
|
||||||
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
|
||||||
|
|
||||||
|
|
||||||
from .constants import HeaderTags
|
from .constants import HeaderTags
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
from abc import ABC, abstractmethod
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
|
||||||
|
|
||||||
|
|
||||||
class IMuxedStream(ABC):
|
|
||||||
|
|
||||||
mplex_conn: "IMuxedConn"
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def read(self) -> bytes:
|
|
||||||
"""
|
|
||||||
reads from the underlying muxed_conn
|
|
||||||
:return: bytes of input
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def write(self, data: bytes) -> int:
|
|
||||||
"""
|
|
||||||
writes to the underlying muxed_conn
|
|
||||||
:return: number of bytes written
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def close(self) -> bool:
|
|
||||||
"""
|
|
||||||
close the underlying muxed_conn
|
|
||||||
:return: true if successful
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def reset(self) -> bool:
|
|
||||||
"""
|
|
||||||
closes both ends of the stream
|
|
||||||
tells this remote side to hang up
|
|
||||||
:return: true if successful
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def set_deadline(self, ttl: float) -> bool:
|
|
||||||
"""
|
|
||||||
set deadline for muxed stream
|
|
||||||
:return: a new stream
|
|
||||||
"""
|
|
Loading…
x
Reference in New Issue
Block a user