mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Fix Mplex and Swarm
This commit is contained in:
@ -50,8 +50,11 @@ class SwarmConn(INetConn, Service):
|
||||
await self._notify_disconnected()
|
||||
|
||||
async def _handle_new_streams(self) -> None:
|
||||
while True:
|
||||
while self.manager.is_running:
|
||||
try:
|
||||
print(
|
||||
f"!@# SwarmConn._handle_new_streams: {self.muxed_conn._id}: waiting for new streams"
|
||||
)
|
||||
stream = await self.muxed_conn.accept_stream()
|
||||
except MuxedConnUnavailable:
|
||||
# If there is anything wrong in the MuxedConn,
|
||||
@ -60,6 +63,9 @@ class SwarmConn(INetConn, Service):
|
||||
# Asynchronously handle the accepted stream, to avoid blocking the next stream.
|
||||
self.manager.run_task(self._handle_muxed_stream, stream)
|
||||
|
||||
print(
|
||||
f"!@# SwarmConn._handle_new_streams: {self.muxed_conn._id}: out of the loop"
|
||||
)
|
||||
await self.close()
|
||||
|
||||
async def _call_stream_handler(self, net_stream: NetStream) -> None:
|
||||
|
||||
@ -206,8 +206,7 @@ class Swarm(INetwork, Service):
|
||||
logger.debug("successfully opened connection to peer %s", peer_id)
|
||||
# FIXME: This is a intentional barrier to prevent from the handler exiting and
|
||||
# closing the connection.
|
||||
event = trio.Event()
|
||||
await event.wait()
|
||||
await trio.sleep_forever()
|
||||
|
||||
try:
|
||||
# Success
|
||||
@ -240,7 +239,7 @@ class Swarm(INetwork, Service):
|
||||
# await asyncio.gather(
|
||||
# *[connection.close() for connection in self.connections.values()]
|
||||
# )
|
||||
self.manager.stop()
|
||||
await self.manager.stop()
|
||||
await self.manager.wait_finished()
|
||||
logger.debug("swarm successfully closed")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user