mirror of https://github.com/vacp2p/nim-libp2p.git
connection should raise on invalid varint
This commit is contained in:
parent
15bae7bec5
commit
bc46a76029
|
@ -23,6 +23,11 @@ type
|
|||
stream*: LPStream
|
||||
observedAddrs*: Multiaddress
|
||||
|
||||
InvalidVarintException = object of LPStreamError
|
||||
|
||||
proc newInvalidVarintException*(): ref InvalidVarintException =
|
||||
result = newException(InvalidVarintException, "unable to prase varint")
|
||||
|
||||
proc newConnection*(stream: LPStream): Connection =
|
||||
## create a new Connection for the specified async reader/writer
|
||||
new result
|
||||
|
@ -92,7 +97,7 @@ proc readLp*(s: Connection): Future[seq[byte]] {.async, gcsafe.} =
|
|||
if res == VarintStatus.Success:
|
||||
break
|
||||
if res != VarintStatus.Success or size > DefaultReadSize:
|
||||
return
|
||||
raise newInvalidVarintException()
|
||||
result.setLen(size)
|
||||
if size > 0.uint:
|
||||
await s.readExactly(addr result[0], int(size))
|
||||
|
|
|
@ -19,8 +19,8 @@ logScope:
|
|||
topic = "mplex-coder"
|
||||
|
||||
type
|
||||
Msg* = tuple
|
||||
id: uint
|
||||
Msg* = tuple
|
||||
id: uint
|
||||
msgType: MessageType
|
||||
data: seq[byte]
|
||||
|
||||
|
@ -38,7 +38,7 @@ proc readMplexVarint(conn: Connection): Future[Option[uint]] {.async, gcsafe.} =
|
|||
if res == VarintStatus.Success:
|
||||
return some(varint)
|
||||
if res != VarintStatus.Success:
|
||||
return
|
||||
raise newInvalidVarintException()
|
||||
except LPStreamIncompleteError:
|
||||
trace "unable to read varint", exc = getCurrentExceptionMsg()
|
||||
|
||||
|
|
Loading…
Reference in New Issue