Skip to content

Commit

Permalink
fix(yamux): doesn't work in a Relayv2 connection (#979)
Browse files Browse the repository at this point in the history
Co-authored-by: Ludovic Chenut <[email protected]>
  • Loading branch information
2 people authored and romanzac committed Dec 13, 2023
1 parent 3958660 commit 7ce2afb
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 298 deletions.
3 changes: 3 additions & 0 deletions libp2p/muxers/yamux/yamux.nim
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ proc remoteClosed(channel: YamuxChannel) {.async.} =
method closeImpl*(channel: YamuxChannel) {.async, gcsafe.} =
if not channel.closedLocally:
channel.closedLocally = true
channel.isEof = true

if channel.isReset == false and channel.sendQueue.len == 0:
await channel.conn.write(YamuxHeader.data(channel.id, 0, {Fin}))
Expand Down Expand Up @@ -249,6 +250,7 @@ method readOnce*(
await channel.closedRemotely or channel.receivedData.wait()
if channel.closedRemotely.done() and channel.recvQueue.len == 0:
channel.returnedEof = true
channel.isEof = true
return 0

let toRead = min(channel.recvQueue.len, nbytes)
Expand Down Expand Up @@ -454,6 +456,7 @@ method handle*(m: Yamux) {.async, gcsafe.} =
if header.streamId in m.flushed:
m.flushed.del(header.streamId)
if header.streamId mod 2 == m.currentId mod 2:
debug "Peer used our reserved stream id, skipping", id=header.streamId, currentId=m.currentId, peerId=m.connection.peerId
raise newException(YamuxError, "Peer used our reserved stream id")
let newStream = m.createStream(header.streamId, false)
if m.channels.len >= m.maxChannCount:
Expand Down
1 change: 1 addition & 0 deletions libp2p/protocols/connectivity/relay/rconn.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ proc new*(
limitDuration: uint32,
limitData: uint64): T =
let rc = T(conn: conn, limitDuration: limitDuration, limitData: limitData)
rc.dir = conn.dir
rc.initStream()
if limitDuration > 0:
proc checkDurationConnection() {.async.} =
Expand Down
Loading

0 comments on commit 7ce2afb

Please sign in to comment.