mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-26 13:15:16 +00:00
Cosmetic improvements
This commit is contained in:
parent
e8a15aa0ce
commit
15f0153441
@ -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")
|
||||||
|
2
vendor/nim-chronicles
vendored
2
vendor/nim-chronicles
vendored
@ -1 +1 @@
|
|||||||
Subproject commit af184ae47e20672b68d20e7cacd3b726533548e1
|
Subproject commit bb2b58881004481a7d790f4d349d35b29cdbcac9
|
2
vendor/nim-faststreams
vendored
2
vendor/nim-faststreams
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 8b863f7798f7e1a6a9266b88e7bca5aa0cb5ed8a
|
Subproject commit dd63bbfd1cea26e9ca830a3a8fd70e5d3a0d1306
|
Loading…
x
Reference in New Issue
Block a user