Make msgId fixed int32

This commit is contained in:
kdeme 2019-10-22 17:00:19 +02:00 committed by zah
parent 5850186ca0
commit 98be627bcc
3 changed files with 11 additions and 5 deletions

View File

@ -429,8 +429,9 @@ proc recvMsg*(peer: Peer): Future[tuple[msgId: int, msgData: Rlp]] {.async.} =
var rlp = rlpFromBytes(decryptedBytes.toRange)
try:
let msgid = rlp.read(int)
return (msgId, rlp)
# int32 as this seems more than big enough for the amount of msgIds
let msgId = rlp.read(int32)
return (msgId.int, rlp)
except RlpError:
await peer.disconnectAndRaise(BreachOfProtocol,
"Cannot read RLPx message id")

View File

@ -46,5 +46,5 @@ template sourceDir*: string = currentSourcePath.rsplit(DirSep, 1)[0]
proc recvMsgMock*(msg: openArray[byte]): tuple[msgId: int, msgData: Rlp] =
var rlp = rlpFromBytes(@msg.toRange)
let msgid = rlp.read(int)
return (msgId, rlp)
let msgId = rlp.read(int32)
return (msgId.int, rlp)

View File

@ -9,8 +9,13 @@
"error": "UnsupportedMessageError",
"description": "This is a message id not used by devp2p, eth or whisper"
},
"Message id that is negative": {
"Message id that is bigger than int32": {
"payload": "888888888888888888",
"error": "RlpTypeMismatch",
"description": "This payload will result in too large int for a message id"
},
"Message id that is negative": {
"payload": "8488888888",
"error": "UnsupportedMessageError",
"description": "This payload will result in a negative number as message id"
},