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

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

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