Resolve without altering Rlp API

This commit is contained in:
kdeme 2019-05-24 10:14:05 +02:00 committed by zah
parent 6b5af745a2
commit dfe7d43d19
2 changed files with 3 additions and 3 deletions

View File

@ -229,13 +229,13 @@ proc recvFindNode(d: DiscoveryProtocol, node: Node, payload: Bytes) {.inline, gc
proc expirationValid(cmdId: CommandId, rlpEncodedPayload: seq[byte]):
bool {.inline, raises:[DiscProtocolError, RlpError].} =
## Can only raise `DiscProtocolError` and all of `RlpError`
# Check if there is a payload, TODO: perhaps this should be an RLP error?
# Check if there is a payload
if rlpEncodedPayload.len <= 0:
raise newException(DiscProtocolError, "RLP stream is empty")
let rlp = rlpFromBytes(rlpEncodedPayload.toRange)
# Check payload is an RLP list and if the list has the minimum items required
# for this packet type
if rlp.listLen >= MinListLen[cmdId]:
if rlp.isList and rlp.listLen >= MinListLen[cmdId]:
# Expiration is always the last mandatory item of the list
let expiration = rlp.listElem(MinListLen[cmdId] - 1).toInt(uint32)
result = epochTime() <= expiration.float

View File

@ -275,7 +275,7 @@ proc listElem*(self: Rlp, i: int): Rlp =
proc listLen*(self: Rlp): int =
if not isList():
raise newException(RlpTypeMismatch, "List expected, but the source RLP is not a list.")
return 0
var rlp = self
for elem in rlp: