feat:remove unneccessary change

Signed-off-by: Chen Kai <281165273grape@gmail.com>
This commit is contained in:
Chen Kai 2025-03-12 11:06:28 +01:00
parent b26e0a8593
commit d8b9298f35
2 changed files with 12 additions and 50 deletions

View file

@ -695,44 +695,6 @@ func pushNode(list []*tableNode, n *tableNode, max int) ([]*tableNode, *tableNod
return list, removed
}
// waitInit waits until the table is initialized.
func (tab *Table) waitInit() {
<-tab.initDone
}
// nodeList returns all nodes contained in the table.
func (tab *Table) nodeList() []*enode.Node {
if !tab.isInitDone() {
return nil
}
tab.mutex.Lock()
defer tab.mutex.Unlock()
var nodes []*enode.Node
for _, b := range &tab.buckets {
for _, n := range b.entries {
nodes = append(nodes, n.Node)
}
}
return nodes
}
// nodeIds returns the node IDs hex representation in the table.
func (tab *Table) nodeIds() [][]string {
tab.mutex.Lock()
defer tab.mutex.Unlock()
nodes := make([][]string, 0)
for _, b := range &tab.buckets {
bucketNodes := make([]string, 0)
for _, n := range b.entries {
bucketNodes = append(bucketNodes, fmt.Sprintf("0x%s", n.ID().String()))
}
nodes = append(nodes, bucketNodes)
}
return nodes
}
// deleteNode removes a node from the table.
func (tab *Table) deleteNode(n *enode.Node) {
tab.mutex.Lock()

View file

@ -252,15 +252,20 @@ func (t *UDPv5) ResolveNodeId(id enode.ID) *enode.Node {
// AllNodes returns all the nodes stored in the local table.
func (t *UDPv5) AllNodes() []*enode.Node {
return t.tab.nodeList()
t.tab.mutex.Lock()
defer t.tab.mutex.Unlock()
nodes := make([]*enode.Node, 0)
for _, b := range &t.tab.buckets {
for _, n := range b.entries {
nodes = append(nodes, n.Node)
}
}
return nodes
}
// RoutingTableInfo returns the routing table information. Used for Portal discv5 RoutingTableInfo API.
func (t *UDPv5) RoutingTableInfo() [][]string {
return t.tab.nodeIds()
}
// AddKnownNode adds a node to the routing table. Used for Portal discv5 AddEnr API.
// AddKnownNode adds a node to the routing table.
// The function should be used for testing only.
func (t *UDPv5) AddKnownNode(n *enode.Node) bool {
return t.tab.addFoundNode(n, true)
}
@ -270,11 +275,6 @@ func (t *UDPv5) DeleteNode(n *enode.Node) {
t.tab.deleteNode(n)
}
// WaitInit waits for the routing table to be initialized.
func (t *UDPv5) WaitInit() {
t.tab.waitInit()
}
// LocalNode returns the current local Node running the
// protocol.
func (t *UDPv5) LocalNode() *enode.LocalNode {