No reraise on RlpTypeMismatch in processClient

This commit is contained in:
kdeme 2019-05-05 14:34:06 +02:00 committed by zah
parent bb79902399
commit 69691f56d2
1 changed files with 4 additions and 0 deletions

View File

@ -215,11 +215,13 @@ proc recvFindNode(d: DiscoveryProtocol, node: Node, payload: Bytes) {.inline, gc
d.kademlia.recvFindNode(node, nodeId) d.kademlia.recvFindNode(node, nodeId)
proc expirationValid(rlpEncodedPayload: seq[byte]): bool {.inline.} = proc expirationValid(rlpEncodedPayload: seq[byte]): bool {.inline.} =
## Can raise RlpTypeMismatch
let rlp = rlpFromBytes(rlpEncodedPayload.toRange) let rlp = rlpFromBytes(rlpEncodedPayload.toRange)
let expiration = rlp.listElem(rlp.listLen - 1).toInt(uint32) let expiration = rlp.listElem(rlp.listLen - 1).toInt(uint32)
result = epochTime() <= expiration.float result = epochTime() <= expiration.float
proc receive(d: DiscoveryProtocol, a: Address, msg: Bytes) {.gcsafe.} = proc receive(d: DiscoveryProtocol, a: Address, msg: Bytes) {.gcsafe.} =
## Can raise RlpTypeMismatch
var msgHash: MDigest[256] var msgHash: MDigest[256]
if validateMsgHash(msg, msgHash): if validateMsgHash(msg, msgHash):
var remotePubkey: PublicKey var remotePubkey: PublicKey
@ -256,6 +258,8 @@ proc processClient(transp: DatagramTransport,
var buf = transp.getMessage() var buf = transp.getMessage()
let a = Address(ip: raddr.address, udpPort: raddr.port, tcpPort: raddr.port) let a = Address(ip: raddr.address, udpPort: raddr.port, tcpPort: raddr.port)
proto.receive(a, buf) proto.receive(a, buf)
except RlpTypeMismatch:
debug "Receive failed", err = getCurrentExceptionMsg()
except: except:
debug "Receive failed", err = getCurrentExceptionMsg() debug "Receive failed", err = getCurrentExceptionMsg()
raise raise