Skip to content

Commit

Permalink
add log
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod authored and GrapeBaBa committed Jul 17, 2024
1 parent 3816cc9 commit 8de928c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion p2p/discover/portal_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ func (p *PortalProtocol) AddEnr(n *enode.Node) {
// immediately add the node to the routing table
p.table.mutex.Lock()
defer p.table.mutex.Unlock()
p.table.handleAddNode(addNodeOp{node: n, isInbound: true, forceSetLive: true})
added := p.table.handleAddNode(addNodeOp{node: n, isInbound: true, forceSetLive: true})
if !added {
p.Log.Warn("add node failed", "id", n.ID())
return
}
id := n.ID().String()
p.radiusCache.Set([]byte(id), MaxDistance)
}
Expand Down Expand Up @@ -1433,11 +1437,13 @@ func (p *PortalProtocol) Resolve(n *enode.Node) *enode.Node {
// It returns nil if the nodeId could not be resolved.
func (p *PortalProtocol) ResolveNodeId(id enode.ID) *enode.Node {
if id == p.Self().ID() {
p.Log.Debug("Resolve Self Id", "id", id.String())
return p.Self()
}

n := p.table.getNode(id)
if n != nil {
p.Log.Debug("found Id in table and will request enr from the node", "id", id.String())
// Try asking directly. This works if the Node is still responding on the endpoint we have.
if resp, err := p.RequestENR(n); err == nil {
return resp
Expand Down
5 changes: 5 additions & 0 deletions p2p/discover/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,27 +525,32 @@ func (tab *Table) removeIP(b *bucket, ip netip.Addr) {
// The caller must hold tab.mutex.
func (tab *Table) handleAddNode(req addNodeOp) bool {
if req.node.ID() == tab.self().ID() {
tab.log.Debug("this node is already in table", "id", req.node.ID())
return false
}
// 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() {
tab.log.Debug("table is not ready")
return false
}

b := tab.bucket(req.node.ID())
n, _ := tab.bumpInBucket(b, req.node, req.isInbound)
if n != nil {
// Already in bucket.
tab.log.Debug("the node is already in table", "id", req.node.ID())
return false
}
if len(b.entries) >= bucketSize {
// Bucket full, maybe add as replacement.
tab.log.Debug("the bucket is full and will add in replacement", "id", req.node.ID())
tab.addReplacement(b, req.node)
return false
}
if !tab.addIP(b, req.node.IPAddr()) {
// Can't add: IP limit reached.
tab.log.Debug("IP limit reached", "id", req.node.ID())
return false
}

Expand Down

0 comments on commit 8de928c

Please sign in to comment.