Skip to content

Commit

Permalink
chore: add isClosedRemotely public bool attribute in lpstream (#1242)
Browse files Browse the repository at this point in the history
Also adds the gcsafe to getStreams method so that we can invoke it from async procs
  • Loading branch information
Ivansete-status authored Feb 6, 2025
1 parent c5aa373 commit a4f0a63
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libp2p/muxers/mplex/mplex.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion libp2p/muxers/muxer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
3 changes: 2 additions & 1 deletion libp2p/muxers/yamux/yamux.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions libp2p/stream/lpstream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type
oid*: Oid
dir*: Direction
closedWithEOF: bool # prevent concurrent calls
isClosedRemotely*: bool

LPStreamError* = object of LPError
LPStreamIncompleteError* = object of LPStreamError
Expand Down

0 comments on commit a4f0a63

Please sign in to comment.