avoid triple lookup in `m.flushed` yamux table (#1045)

This commit is contained in:
Etan Kissling 2024-03-04 00:27:13 +01:00 committed by GitHub
parent 18e00a741b
commit 8cccd54125
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 10 deletions

View File

@ -516,16 +516,20 @@ method handle*(m: Yamux) {.async.} =
await newStream.open() await newStream.open()
asyncSpawn m.handleStream(newStream) asyncSpawn m.handleStream(newStream)
elif header.streamId notin m.channels: elif header.streamId notin m.channels:
if header.streamId notin m.flushed:
raise newException(YamuxError, "Unknown stream ID: " & $header.streamId)
elif header.msgType == Data:
# Flush the data # Flush the data
m.flushed[header.streamId].dec(int(header.length)) m.flushed.withValue(header.streamId, flushed):
if m.flushed[header.streamId] < 0: if header.msgType == Data:
raise newException(YamuxError, "Peer exhausted the recvWindow after reset") flushed[].dec(int(header.length))
if flushed[] < 0:
raise newException(YamuxError,
"Peer exhausted the recvWindow after reset")
do:
raise newException(YamuxError,
"Unknown stream ID: " & $header.streamId)
if header.length > 0: if header.length > 0:
var buffer = newSeqUninitialized[byte](header.length) var buffer = newSeqUninitialized[byte](header.length)
await m.connection.readExactly(addr buffer[0], int(header.length)) await m.connection.readExactly(
addr buffer[0], int(header.length))
continue continue
let channel = let channel =