-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p2p/discover: fix ENR filtering #2770
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,13 +337,13 @@ func (tab *Table) addFoundNode(n *enode.Node, forceSetLive bool) bool { | |
// repeatedly. | ||
// | ||
// The caller must not hold tab.mutex. | ||
func (tab *Table) addInboundNode(n *enode.Node) bool { | ||
func (tab *Table) addInboundNode(n *enode.Node) { | ||
op := addNodeOp{node: n, isInbound: true} | ||
select { | ||
case tab.addNodeCh <- op: | ||
return <-tab.addNodeHandled | ||
return | ||
case <-tab.closeReq: | ||
return false | ||
return | ||
} | ||
} | ||
|
||
|
@@ -387,10 +387,9 @@ loop: | |
tab.revalidation.handleResponse(tab, r) | ||
|
||
case op := <-tab.addNodeCh: | ||
tab.mutex.Lock() | ||
ok := tab.handleAddNode(op) | ||
tab.mutex.Unlock() | ||
tab.addNodeHandled <- ok | ||
go func() { | ||
tab.addNodeHandled <- tab.handleAddNode(op) | ||
}() | ||
|
||
case op := <-tab.trackRequestCh: | ||
tab.handleTrackRequest(op) | ||
|
@@ -468,9 +467,7 @@ func (tab *Table) loadSeedNodes() { | |
addr, _ := seed.UDPEndpoint() | ||
tab.log.Trace("Found seed node in database", "id", seed.ID(), "addr", addr, "age", age) | ||
} | ||
tab.mutex.Lock() | ||
tab.handleAddNode(addNodeOp{node: seed, isInbound: false}) | ||
tab.mutex.Unlock() | ||
go tab.handleAddNode(addNodeOp{node: seed, isInbound: false}) | ||
zzzckck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
|
@@ -493,15 +490,15 @@ func (tab *Table) bucketAtDistance(d int) *bucket { | |
} | ||
|
||
//nolint:unused | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove //nolint:unused There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
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 | ||
|
@@ -541,6 +538,13 @@ func (tab *Table) handleAddNode(req addNodeOp) bool { | |
return false | ||
} | ||
|
||
if tab.filterNode(req.node) { | ||
return false | ||
} | ||
|
||
tab.mutex.Lock() | ||
defer tab.mutex.Unlock() | ||
|
||
// For nodes from inbound contact, there is an additional safety measure: if the table | ||
// is still initializing the node is not added. | ||
if req.isInbound && !tab.isInitDone() { | ||
|
@@ -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) | ||
|
@@ -705,8 +704,6 @@ func (tab *Table) handleTrackRequest(op trackRequestOp) { | |
} | ||
|
||
tab.mutex.Lock() | ||
defer tab.mutex.Unlock() | ||
|
||
b := tab.bucket(op.node.ID()) | ||
// Remove the node from the local table if it fails to return anything useful too | ||
// many times, but only if there are enough other nodes in the bucket. This latter | ||
|
@@ -715,10 +712,11 @@ func (tab *Table) handleTrackRequest(op trackRequestOp) { | |
if fails >= maxFindnodeFailures && len(b.entries) >= bucketSize/4 { | ||
tab.deleteInBucket(b, op.node.ID()) | ||
} | ||
tab.mutex.Unlock() | ||
|
||
// Add found nodes. | ||
for _, n := range op.foundNodes { | ||
tab.handleAddNode(addNodeOp{n, false, false}) | ||
go tab.handleAddNode(addNodeOp{n, false, false}) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't it be blocked? as there is no consumer for this channel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed