mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
p2p/discover: add debug API
This commit is contained in:
parent
bc62df2223
commit
8f4c72c579
3 changed files with 20 additions and 9 deletions
|
|
@ -29,6 +29,12 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type BucketNode struct {
|
||||||
|
Node *enode.Node `json:"node"`
|
||||||
|
AddedAt time.Time `json:"added"`
|
||||||
|
Checks int `json:"checks"`
|
||||||
|
}
|
||||||
|
|
||||||
// node represents a host on the network.
|
// node represents a host on the network.
|
||||||
// The fields of Node may not be modified.
|
// The fields of Node may not be modified.
|
||||||
type node struct {
|
type node struct {
|
||||||
|
|
|
||||||
|
|
@ -150,18 +150,19 @@ func newMeteredTable(t transport, db *enode.DB, cfg Config) (*Table, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nodes returns all nodes contained in the table.
|
// Nodes returns all nodes contained in the table.
|
||||||
func (tab *Table) Nodes() []*enode.Node {
|
func (tab *Table) Nodes() [][]BucketNode {
|
||||||
if !tab.isInitDone() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
tab.mutex.Lock()
|
tab.mutex.Lock()
|
||||||
defer tab.mutex.Unlock()
|
defer tab.mutex.Unlock()
|
||||||
|
|
||||||
var nodes []*enode.Node
|
nodes := make([][]BucketNode, len(tab.buckets))
|
||||||
for _, b := range &tab.buckets {
|
for i, b := range &tab.buckets {
|
||||||
for _, n := range b.entries {
|
nodes[i] = make([]BucketNode, len(b.entries))
|
||||||
nodes = append(nodes, unwrapNode(n))
|
for j, n := range b.entries {
|
||||||
|
nodes[i][j] = BucketNode{
|
||||||
|
Node: &n.Node,
|
||||||
|
Checks: int(n.livenessChecks),
|
||||||
|
AddedAt: n.addedAt,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nodes
|
return nodes
|
||||||
|
|
|
||||||
|
|
@ -375,6 +375,10 @@ func (t *UDPv4) RequestENR(n *enode.Node) (*enode.Node, error) {
|
||||||
return respN, nil
|
return respN, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *UDPv4) TableBuckets() [][]BucketNode {
|
||||||
|
return t.tab.Nodes()
|
||||||
|
}
|
||||||
|
|
||||||
// pending adds a reply matcher to the pending reply queue.
|
// pending adds a reply matcher to the pending reply queue.
|
||||||
// see the documentation of type replyMatcher for a detailed explanation.
|
// see the documentation of type replyMatcher for a detailed explanation.
|
||||||
func (t *UDPv4) pending(id enode.ID, ip net.IP, ptype byte, callback replyMatchFunc) *replyMatcher {
|
func (t *UDPv4) pending(id enode.ID, ip net.IP, ptype byte, callback replyMatchFunc) *replyMatcher {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue