Cosmetic improvements

This commit is contained in:
Zahary Karadjov 2020-05-07 12:20:00 +03:00 committed by zah
parent e8a15aa0ce
commit 15f0153441
3 changed files with 7 additions and 7 deletions

View File

@ -306,14 +306,14 @@ proc disconnectAndRaise(peer: Peer,
await peer.disconnect(r)
raisePeerDisconnected(msg, r)
proc readSizePrefix(s: AsyncInputStream): Future[int] {.async.} =
proc readSizePrefix(s: AsyncInputStream, maxSize: uint64): Future[int] {.async.} =
trace "about to read msg size prefix"
var parser: VarintParser[uint64, ProtoBuf]
while s.readable:
case parser.feedByte(s.read)
of Done:
let res = parser.getResult
if res > uint64(MAX_CHUNK_SIZE):
if res > maxSize:
trace "size prefix outside of range", res
return -1
else:
@ -326,10 +326,10 @@ proc readSizePrefix(s: AsyncInputStream): Future[int] {.async.} =
continue
proc readSszValue(s: AsyncInputStream, MsgType: type): Future[MsgType] {.async.} =
let size = await s.readSizePrefix
let size = await s.readSizePrefix(uint64(MAX_CHUNK_SIZE))
if size > 0 and s.readable(size):
s.nonBlockingReads(ss):
return ss.readValue(SSZ, MsgType)
s.withReadableRange(size, r):
return r.readValue(SSZ, MsgType)
else:
raise newException(CatchableError,
"Failed to read an incoming message size prefix")

@ -1 +1 @@
Subproject commit af184ae47e20672b68d20e7cacd3b726533548e1
Subproject commit bb2b58881004481a7d790f4d349d35b29cdbcac9

@ -1 +1 @@
Subproject commit 8b863f7798f7e1a6a9266b88e7bca5aa0cb5ed8a
Subproject commit dd63bbfd1cea26e9ca830a3a8fd70e5d3a0d1306