mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-10 15:10:54 +00:00
Use ReadWriteCloser for conns and streams
This commit is contained in:
@ -44,13 +44,12 @@ class NetStream(INetStream):
|
||||
"""
|
||||
return await self.muxed_stream.write(data)
|
||||
|
||||
async def close(self) -> bool:
|
||||
async def close(self) -> None:
|
||||
"""
|
||||
close stream
|
||||
:return: true if successful
|
||||
"""
|
||||
await self.muxed_stream.close()
|
||||
return True
|
||||
|
||||
async def reset(self) -> bool:
|
||||
return await self.muxed_stream.reset()
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from abc import abstractmethod
|
||||
|
||||
from libp2p.io.abc import ReadWriteCloser
|
||||
from libp2p.stream_muxer.abc import IMuxedConn
|
||||
from libp2p.typing import TProtocol
|
||||
|
||||
|
||||
class INetStream(ABC):
|
||||
class INetStream(ReadWriteCloser):
|
||||
|
||||
mplex_conn: IMuxedConn
|
||||
|
||||
@ -21,28 +22,6 @@ class INetStream(ABC):
|
||||
:return: true if successful
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def read(self, n: int = -1) -> bytes:
|
||||
"""
|
||||
reads from the underlying muxed_stream
|
||||
:param n: number of bytes to read
|
||||
:return: bytes of input
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def write(self, data: bytes) -> int:
|
||||
"""
|
||||
write to the underlying muxed_stream
|
||||
:return: number of bytes written
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def close(self) -> bool:
|
||||
"""
|
||||
close the underlying muxed stream
|
||||
:return: true if successful
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def reset(self) -> bool:
|
||||
"""
|
||||
|
||||
@ -8,7 +8,7 @@ from libp2p.peer.peerstore import PeerStoreError
|
||||
from libp2p.peer.peerstore_interface import IPeerStore
|
||||
from libp2p.protocol_muxer.multiselect import Multiselect
|
||||
from libp2p.protocol_muxer.multiselect_client import MultiselectClient
|
||||
from libp2p.protocol_muxer.multiselect_communicator import StreamCommunicator
|
||||
from libp2p.protocol_muxer.multiselect_communicator import MultiselectCommunicator
|
||||
from libp2p.routing.interfaces import IPeerRouting
|
||||
from libp2p.stream_muxer.abc import IMuxedConn, IMuxedStream
|
||||
from libp2p.transport.exceptions import MuxerUpgradeFailure, SecurityUpgradeFailure
|
||||
@ -161,7 +161,7 @@ class Swarm(INetwork):
|
||||
|
||||
# Perform protocol muxing to determine protocol to use
|
||||
selected_protocol = await self.multiselect_client.select_one_of(
|
||||
list(protocol_ids), StreamCommunicator(muxed_stream)
|
||||
list(protocol_ids), MultiselectCommunicator(muxed_stream)
|
||||
)
|
||||
|
||||
# Create a net stream with the selected protocol
|
||||
@ -294,7 +294,7 @@ def create_generic_protocol_handler(swarm: Swarm) -> GenericProtocolHandlerFn:
|
||||
async def generic_protocol_handler(muxed_stream: IMuxedStream) -> None:
|
||||
# Perform protocol muxing to determine protocol to use
|
||||
protocol, handler = await multiselect.negotiate(
|
||||
StreamCommunicator(muxed_stream)
|
||||
MultiselectCommunicator(muxed_stream)
|
||||
)
|
||||
|
||||
net_stream = NetStream(muxed_stream)
|
||||
|
||||
Reference in New Issue
Block a user