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) var rlp = rlpFromBytes(decryptedBytes.toRange)
try: try:
let msgid = rlp.read(int) # int32 as this seems more than big enough for the amount of msgIds
return (msgId, rlp) let msgId = rlp.read(int32)
return (msgId.int, rlp)
except RlpError: except RlpError:
await peer.disconnectAndRaise(BreachOfProtocol, await peer.disconnectAndRaise(BreachOfProtocol,
"Cannot read RLPx message id") "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] = proc recvMsgMock*(msg: openArray[byte]): tuple[msgId: int, msgData: Rlp] =
var rlp = rlpFromBytes(@msg.toRange) var rlp = rlpFromBytes(@msg.toRange)
let msgid = rlp.read(int) let msgId = rlp.read(int32)
return (msgId, rlp) return (msgId.int, rlp)

View File

@ -9,8 +9,13 @@
"error": "UnsupportedMessageError", "error": "UnsupportedMessageError",
"description": "This is a message id not used by devp2p, eth or whisper" "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", "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", "error": "UnsupportedMessageError",
"description": "This payload will result in a negative number as message id" "description": "This payload will result in a negative number as message id"
}, },