2018-11-29 02:51:50 +08:00
|
|
|
from abc import ABC, abstractmethod
|
2019-08-07 18:02:30 +08:00
|
|
|
from typing import Sequence
|
|
|
|
|
2019-08-15 23:31:26 +08:00
|
|
|
from libp2p.protocol_muxer.multiselect_communicator_interface import (
|
|
|
|
IMultiselectCommunicator,
|
|
|
|
)
|
2019-08-07 18:02:30 +08:00
|
|
|
from libp2p.typing import TProtocol
|
2018-11-29 02:51:50 +08:00
|
|
|
|
2019-01-10 02:38:56 +08:00
|
|
|
|
2018-11-29 02:51:50 +08:00
|
|
|
class IMultiselectClient(ABC):
|
|
|
|
"""
|
|
|
|
Client for communicating with receiver's multiselect
|
|
|
|
module in order to select a protocol id to communicate over
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
2019-08-14 05:36:42 +08:00
|
|
|
async def select_protocol_or_fail(
|
2019-08-15 23:31:26 +08:00
|
|
|
self, protocol: TProtocol, communicator: IMultiselectCommunicator
|
2019-08-14 05:36:42 +08:00
|
|
|
) -> TProtocol:
|
2018-11-29 02:51:50 +08:00
|
|
|
"""
|
|
|
|
Send message to multiselect selecting protocol
|
|
|
|
and fail if multiselect does not return same protocol
|
|
|
|
:param protocol: protocol to select
|
|
|
|
:param stream: stream to communicate with multiselect over
|
|
|
|
:return: selected protocol
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
2019-08-07 18:02:30 +08:00
|
|
|
async def select_one_of(
|
2019-08-15 23:31:26 +08:00
|
|
|
self, protocols: Sequence[TProtocol], communicator: IMultiselectCommunicator
|
2019-08-07 18:02:30 +08:00
|
|
|
) -> TProtocol:
|
2018-11-29 02:51:50 +08:00
|
|
|
"""
|
|
|
|
For each protocol, send message to multiselect selecting protocol
|
|
|
|
and fail if multiselect does not return same protocol. Returns first
|
|
|
|
protocol that multiselect agrees on (i.e. that multiselect selects)
|
|
|
|
:param protocol: protocol to select
|
|
|
|
:param stream: stream to communicate with multiselect over
|
|
|
|
:return: selected protocol
|
|
|
|
"""
|