Skip to content

Commit

Permalink
Prevent sending messages to banned nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhartnett committed Jan 24, 2025
1 parent dd9962d commit 854f17c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion eth/p2p/discoveryv5/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ proc receive*(d: Protocol, a: Address, packet: openArray[byte]) =
debug "Timed out or unrequested whoareyou packet", address = a
of HandshakeMessage:
if d.isBanned(packet.srcIdHs):
trace "Ignoring received HandshakeMessage from banned node", nodeId = packet.srcId
trace "Ignoring received HandshakeMessage from banned node", nodeId = packet.srcIdHs
return

trace "Received handshake message packet", srcId = packet.srcIdHs,
Expand Down Expand Up @@ -601,6 +601,10 @@ proc ping*(d: Protocol, toNode: Node):
## Send a discovery ping message.
##
## Returns the received pong message or an error.

if d.isBanned(toNode.id):
return err("toNode is banned")

let reqId = d.sendMessage(toNode,
PingMessage(enrSeq: d.localNode.record.seqNum))
let resp = await d.waitMessage(toNode, reqId)
Expand All @@ -624,6 +628,10 @@ proc findNode*(d: Protocol, toNode: Node, distances: seq[uint16]):
##
## Returns the received nodes or an error.
## Received ENRs are already validated and converted to `Node`.

if d.isBanned(toNode.id):
return err("toNode is banned")

let reqId = d.sendMessage(toNode, FindNodeMessage(distances: distances))
let nodes = await d.waitNodes(toNode, reqId)

Expand All @@ -639,6 +647,10 @@ proc talkReq*(d: Protocol, toNode: Node, protocol, request: seq[byte]):
## Send a discovery talkreq message.
##
## Returns the received talkresp message or an error.

if d.isBanned(toNode.id):
return err("toNode is banned")

let reqId = d.sendMessage(toNode,
TalkReqMessage(protocol: protocol, request: request))
let resp = await d.waitMessage(toNode, reqId)
Expand Down

0 comments on commit 854f17c

Please sign in to comment.