add still needed TYPE_CHECK
This commit is contained in:
parent
87ef2e4618
commit
29091266fc
|
@ -19,6 +19,7 @@ from .network_interface import INetwork
|
|||
from .notifee_interface import INotifee
|
||||
from .stream.net_stream import NetStream
|
||||
from .stream.net_stream_interface import INetStream
|
||||
from .typing import GenericProtocolHandlerFn
|
||||
|
||||
StreamHandlerFn = Callable[[INetStream], Awaitable[None]]
|
||||
|
||||
|
@ -248,9 +249,6 @@ class Swarm(INetwork):
|
|||
# TODO: `disconnect`?
|
||||
|
||||
|
||||
GenericProtocolHandlerFn = Callable[[IMuxedStream], Awaitable[None]]
|
||||
|
||||
|
||||
def create_generic_protocol_handler(swarm: Swarm) -> GenericProtocolHandlerFn:
|
||||
"""
|
||||
Create a generic protocol handler from the given swarm. We use swarm
|
||||
|
|
4
libp2p/network/typing.py
Normal file
4
libp2p/network/typing.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
from typing import Awaitable, Callable
|
||||
from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream
|
||||
|
||||
GenericProtocolHandlerFn = Callable[[IMuxedStream], Awaitable[None]]
|
|
@ -4,7 +4,7 @@ from typing import Tuple, Dict
|
|||
from multiaddr import Multiaddr
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.network.swarm import GenericProtocolHandlerFn
|
||||
from libp2p.network.typing import GenericProtocolHandlerFn
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
||||
from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream
|
||||
|
@ -24,8 +24,8 @@ class Mplex(IMuxedConn):
|
|||
initiator: bool
|
||||
generic_protocol_handler = None
|
||||
peer_id: ID
|
||||
buffers: Dict[int, asyncio.Queue[bytes]]
|
||||
stream_queue: asyncio.Queue[int]
|
||||
buffers: Dict[int, "asyncio.Queue[bytes]"]
|
||||
stream_queue: "asyncio.Queue[int]"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
|
|
@ -2,11 +2,16 @@ from abc import ABC, abstractmethod
|
|||
|
||||
from multiaddr import Multiaddr
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from libp2p.network.swarm import GenericProtocolHandlerFn
|
||||
from libp2p.network.typing import GenericProtocolHandlerFn
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream
|
||||
from libp2p.stream_muxer.mplex.constants import HeaderTags
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream
|
||||
|
||||
|
||||
|
||||
class IMuxedConn(ABC):
|
||||
"""
|
||||
|
@ -55,7 +60,7 @@ class IMuxedConn(ABC):
|
|||
@abstractmethod
|
||||
async def open_stream(
|
||||
self, protocol_id: str, multi_addr: Multiaddr
|
||||
) -> IMuxedStream:
|
||||
) -> "IMuxedStream":
|
||||
"""
|
||||
creates a new muxed_stream
|
||||
:param protocol_id: protocol_id of stream
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
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
|
||||
mplex_conn: "IMuxedConn"
|
||||
|
||||
@abstractmethod
|
||||
async def read(self) -> bytes:
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import Dict, Sequence
|
|||
from libp2p.stream_muxer.mplex.mplex import Mplex
|
||||
from libp2p.security.security_multistream import SecurityMultistream, TProtocol
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.network.swarm import GenericProtocolHandlerFn
|
||||
from libp2p.network.typing import GenericProtocolHandlerFn
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from libp2p.security.secure_transport_interface import ISecureTransport
|
||||
|
|
Loading…
Reference in New Issue
Block a user