Skip to content

Commit

Permalink
p2p/discover: fix ENR filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusKysel committed Nov 25, 2024
1 parent db357bf commit bc1e429
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ var (
Aliases: []string{"discv5"},
Usage: "Enables the V5 discovery mechanism",
Category: flags.NetworkingCategory,
Value: true,
Value: false,
}
NetrestrictFlag = &cli.StringFlag{
Name: "netrestrict",
Expand Down
17 changes: 8 additions & 9 deletions p2p/discover/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,15 @@ func (tab *Table) bucketAtDistance(d int) *bucket {
}

//nolint:unused
func (tab *Table) filterNode(n *tableNode) bool {
func (tab *Table) filterNode(n *enode.Node) bool {
if tab.enrFilter == nil {
return false
}
if node, err := tab.net.RequestENR(n.Node); err != nil {
tab.log.Debug("ENR request failed", "id", n.ID(), "addr", n.addr(), "err", err)
if node, err := tab.net.RequestENR(n); err != nil {
tab.log.Debug("ENR request failed", "id", n.ID(), "ipAddr", n.IPAddr(), "updPort", n.UDP(), "err", err)
return false
} else if !tab.enrFilter(node.Record()) {
tab.log.Trace("ENR record filter out", "id", n.ID(), "addr", n.addr())
tab.log.Trace("ENR record filter out", "id", n.ID(), "ipAddr", n.IPAddr(), "updPort", n.UDP())
return true
}
return false
Expand Down Expand Up @@ -547,6 +547,10 @@ func (tab *Table) handleAddNode(req addNodeOp) bool {
return false
}

if tab.filterNode(req.node) {
return false
}

b := tab.bucket(req.node.ID())
n, _ := tab.bumpInBucket(b, req.node, req.isInbound)
if n != nil {
Expand All @@ -570,11 +574,6 @@ func (tab *Table) handleAddNode(req addNodeOp) bool {
wn.isValidatedLive = true
}

// TODO(Matus): fix the filterNode feature
// if tab.filterNode(wn) {
// return false
// }

b.entries = append(b.entries, wn)
b.replacements = deleteNode(b.replacements, wn.ID())
tab.nodeAdded(b, wn)
Expand Down

0 comments on commit bc1e429

Please sign in to comment.