From a4f0a638e718f05ecec01ae3a6ad2838714e7e40 Mon Sep 17 00:00:00 2001 From: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> Date: Thu, 6 Feb 2025 14:54:00 +0100 Subject: [PATCH] chore: add isClosedRemotely public bool attribute in lpstream (#1242) Also adds the gcsafe to getStreams method so that we can invoke it from async procs --- libp2p/muxers/mplex/mplex.nim | 2 +- libp2p/muxers/muxer.nim | 2 +- libp2p/muxers/yamux/yamux.nim | 3 ++- libp2p/stream/lpstream.nim | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libp2p/muxers/mplex/mplex.nim b/libp2p/muxers/mplex/mplex.nim index c53921b6b3..08c027ba57 100644 --- a/libp2p/muxers/mplex/mplex.nim +++ b/libp2p/muxers/mplex/mplex.nim @@ -247,7 +247,7 @@ method close*(m: Mplex) {.async: (raises: []).} = trace "Closed mplex", m -method getStreams*(m: Mplex): seq[Connection] = +method getStreams*(m: Mplex): seq[Connection] {.gcsafe.} = for c in m.channels[false].values: result.add(c) for c in m.channels[true].values: diff --git a/libp2p/muxers/muxer.nim b/libp2p/muxers/muxer.nim index 9929ba3dab..46d2dccf21 100644 --- a/libp2p/muxers/muxer.nim +++ b/libp2p/muxers/muxer.nim @@ -67,5 +67,5 @@ proc new*( let muxerProvider = T(newMuxer: creator, codec: codec) muxerProvider -method getStreams*(m: Muxer): seq[Connection] {.base.} = +method getStreams*(m: Muxer): seq[Connection] {.base, gcsafe.} = raiseAssert("Not implemented!") diff --git a/libp2p/muxers/yamux/yamux.nim b/libp2p/muxers/yamux/yamux.nim index 57965f9981..daa552db71 100644 --- a/libp2p/muxers/yamux/yamux.nim +++ b/libp2p/muxers/yamux/yamux.nim @@ -205,6 +205,7 @@ proc remoteClosed(channel: YamuxChannel) {.async: (raises: []).} = if not channel.closedRemotely.isSet(): channel.closedRemotely.fire() await channel.actuallyClose() + channel.isClosedRemotely = true method closeImpl*(channel: YamuxChannel) {.async: (raises: []).} = if not channel.closedLocally: @@ -632,7 +633,7 @@ method handle*(m: Yamux) {.async: (raises: []).} = await m.close() trace "Stopped yamux handler" -method getStreams*(m: Yamux): seq[Connection] = +method getStreams*(m: Yamux): seq[Connection] {.gcsafe.} = for c in m.channels.values: result.add(c) diff --git a/libp2p/stream/lpstream.nim b/libp2p/stream/lpstream.nim index bfa842e417..27e002bf65 100644 --- a/libp2p/stream/lpstream.nim +++ b/libp2p/stream/lpstream.nim @@ -43,6 +43,7 @@ type oid*: Oid dir*: Direction closedWithEOF: bool # prevent concurrent calls + isClosedRemotely*: bool LPStreamError* = object of LPError LPStreamIncompleteError* = object of LPStreamError