mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Protocol muxing (#82)
* Implement protocol muxing * Integrate protocol muxing into new stream and listen's conn handler * Fix bugs in protocol muxing * Remove blank line * Add comments and fix linting issues * Fix order of parameters to select_one_of to match interface * Use array of protocol ids in new stream instead of protocol id * Add basic protocol muxer tests * Add todo * Modify new stream to take in protocol ids * Add check to all tests to ensure protocol id is saved to net stream properly * Lint tests * Fix lint issues * Add todo * Modify port numbers in tests * Fix linting issues * Add more documentation to functions * Add docs describing classes and fix indent error
This commit is contained in:
28
protocol_muxer/multiselect_client_interface.py
Normal file
28
protocol_muxer/multiselect_client_interface.py
Normal file
@ -0,0 +1,28 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
class IMultiselectClient(ABC):
|
||||
"""
|
||||
Client for communicating with receiver's multiselect
|
||||
module in order to select a protocol id to communicate over
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def select_protocol_or_fail(self, protocol, stream):
|
||||
"""
|
||||
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
|
||||
def select_one_of(self, protocols, stream):
|
||||
"""
|
||||
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
|
||||
"""
|
||||
Reference in New Issue
Block a user