add NegotiableTransport type
This commit is contained in:
parent
9851ee01fb
commit
dbb702548f
|
@ -1,7 +1,6 @@
|
|||
from typing import Dict, Tuple
|
||||
|
||||
from libp2p.stream_muxer.abc import IMuxedStream
|
||||
from libp2p.typing import StreamHandlerFn, TProtocol
|
||||
from libp2p.typing import NegotiableTransport, StreamHandlerFn, TProtocol
|
||||
|
||||
from .multiselect_communicator import MultiselectCommunicator
|
||||
from .multiselect_communicator_interface import IMultiselectCommunicator
|
||||
|
@ -31,7 +30,7 @@ class Multiselect(IMultiselectMuxer):
|
|||
"""
|
||||
self.handlers[protocol] = handler
|
||||
|
||||
async def negotiate(self, stream: IMuxedStream) -> Tuple[TProtocol, StreamHandlerFn]:
|
||||
async def negotiate(self, stream: NegotiableTransport) -> Tuple[TProtocol, StreamHandlerFn]:
|
||||
"""
|
||||
Negotiate performs protocol selection
|
||||
:param stream: stream to negotiate on
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from typing import Sequence
|
||||
|
||||
from libp2p.stream_muxer.abc import IMuxedStream
|
||||
from libp2p.typing import TProtocol
|
||||
from libp2p.typing import NegotiableTransport, TProtocol
|
||||
|
||||
from .multiselect_client_interface import IMultiselectClient
|
||||
from .multiselect_communicator import MultiselectCommunicator
|
||||
|
@ -59,7 +59,7 @@ class MultiselectClient(IMultiselectClient):
|
|||
return selected_protocol
|
||||
|
||||
async def select_one_of(
|
||||
self, protocols: Sequence[TProtocol], stream: IMuxedStream
|
||||
self, protocols: Sequence[TProtocol], stream: NegotiableTransport
|
||||
) -> TProtocol:
|
||||
"""
|
||||
For each protocol, send message to multiselect selecting protocol
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from libp2p.stream_muxer.abc import IMuxedStream
|
||||
from libp2p.typing import NegotiableTransport
|
||||
|
||||
from .multiselect_communicator_interface import IMultiselectCommunicator
|
||||
|
||||
|
@ -10,9 +10,9 @@ class MultiselectCommunicator(IMultiselectCommunicator):
|
|||
which is necessary for them to work
|
||||
"""
|
||||
|
||||
reader_writer: IMuxedStream
|
||||
reader_writer: NegotiableTransport
|
||||
|
||||
def __init__(self, reader_writer: IMuxedStream) -> None:
|
||||
def __init__(self, reader_writer: NegotiableTransport) -> None:
|
||||
"""
|
||||
MultistreamCommunicator expects a reader_writer object that has
|
||||
an async read and an async write function (this could be a stream,
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from typing import Dict, Tuple
|
||||
|
||||
from libp2p.stream_muxer.abc import IMuxedStream
|
||||
from libp2p.typing import StreamHandlerFn, TProtocol
|
||||
from libp2p.typing import NegotiableTransport, StreamHandlerFn, TProtocol
|
||||
|
||||
|
||||
class IMultiselectMuxer(ABC):
|
||||
|
@ -23,7 +22,7 @@ class IMultiselectMuxer(ABC):
|
|||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def negotiate(self, stream: IMuxedStream) -> Tuple[TProtocol, StreamHandlerFn]:
|
||||
async def negotiate(self, stream: NegotiableTransport) -> Tuple[TProtocol, StreamHandlerFn]:
|
||||
"""
|
||||
Negotiate performs protocol selection
|
||||
:param stream: stream to negotiate on
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
from typing import Awaitable, Callable, NewType
|
||||
from typing import Awaitable, Callable, NewType, Union
|
||||
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.network.stream.net_stream_interface import INetStream
|
||||
from libp2p.stream_muxer.abc import IMuxedStream
|
||||
|
||||
TProtocol = NewType("TProtocol", str)
|
||||
StreamHandlerFn = Callable[[INetStream], Awaitable[None]]
|
||||
|
||||
|
||||
NegotiableTransport = Union[IMuxedStream, IRawConnection]
|
||||
|
|
Loading…
Reference in New Issue
Block a user