aboutsummaryrefslogtreecommitdiffstats
path: root/p2p
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2019-06-07 21:29:16 +0800
committerGitHub <noreply@github.com>2019-06-07 21:29:16 +0800
commit896322bf88f40329b400d691cbdce9275739310e (patch)
tree74861599b527202c9d3b2aa551fcd41abe74bf74 /p2p
parent1b15c6da33bac1f8c79415a66f22463511ac15a8 (diff)
downloadgo-tangerine-896322bf88f40329b400d691cbdce9275739310e.tar
go-tangerine-896322bf88f40329b400d691cbdce9275739310e.tar.gz
go-tangerine-896322bf88f40329b400d691cbdce9275739310e.tar.bz2
go-tangerine-896322bf88f40329b400d691cbdce9275739310e.tar.lz
go-tangerine-896322bf88f40329b400d691cbdce9275739310e.tar.xz
go-tangerine-896322bf88f40329b400d691cbdce9275739310e.tar.zst
go-tangerine-896322bf88f40329b400d691cbdce9275739310e.zip
cmd/devp2p: add devp2p debug tool (#19657)
* p2p/discover: export Ping and RequestENR These two are useful for checking the status of a node. * cmd/devp2p: add devp2p debug tool This is a new tool for debugging p2p issues. It supports a few basic tasks for now, but many more things can and will be added in the near future. devp2p enrdump -- prints ENRs readably devp2p discv4 ping -- checks if a node is up devp2p discv4 requestenr -- gets a node's record devp2p discv4 resolve -- finds a node through the DHT
Diffstat (limited to 'p2p')
-rw-r--r--p2p/discover/table.go4
-rw-r--r--p2p/discover/table_util_test.go2
-rw-r--r--p2p/discover/v4_udp.go16
3 files changed, 14 insertions, 8 deletions
diff --git a/p2p/discover/table.go b/p2p/discover/table.go
index 3460e8377..e0a46792b 100644
--- a/p2p/discover/table.go
+++ b/p2p/discover/table.go
@@ -85,10 +85,10 @@ type Table struct {
// transport is implemented by the UDP transports.
type transport interface {
Self() *enode.Node
+ RequestENR(*enode.Node) (*enode.Node, error)
lookupRandom() []*enode.Node
lookupSelf() []*enode.Node
ping(*enode.Node) (seq uint64, err error)
- requestENR(*enode.Node) (*enode.Node, error)
}
// bucket contains nodes, ordered by their last activity. the entry
@@ -344,7 +344,7 @@ func (tab *Table) doRevalidate(done chan<- struct{}) {
// Also fetch record if the node replied and returned a higher sequence number.
if last.Seq() < remoteSeq {
- n, err := tab.net.requestENR(unwrapNode(last))
+ n, err := tab.net.RequestENR(unwrapNode(last))
if err != nil {
tab.log.Debug("ENR request failed", "id", last.ID(), "addr", last.addr(), "err", err)
} else {
diff --git a/p2p/discover/table_util_test.go b/p2p/discover/table_util_test.go
index 3075c4340..8e5fc7374 100644
--- a/p2p/discover/table_util_test.go
+++ b/p2p/discover/table_util_test.go
@@ -145,7 +145,7 @@ func (t *pingRecorder) ping(n *enode.Node) (seq uint64, err error) {
}
// requestENR simulates an ENR request.
-func (t *pingRecorder) requestENR(n *enode.Node) (*enode.Node, error) {
+func (t *pingRecorder) RequestENR(n *enode.Node) (*enode.Node, error) {
t.mu.Lock()
defer t.mu.Unlock()
diff --git a/p2p/discover/v4_udp.go b/p2p/discover/v4_udp.go
index b3569b671..b2a5d85cf 100644
--- a/p2p/discover/v4_udp.go
+++ b/p2p/discover/v4_udp.go
@@ -415,13 +415,13 @@ func (t *UDPv4) lookupWorker(n *node, targetKey encPubkey, reply chan<- []*node)
// version of the node record for it. It returns n if the node could not be resolved.
func (t *UDPv4) Resolve(n *enode.Node) *enode.Node {
// Try asking directly. This works if the node is still responding on the endpoint we have.
- if rn, err := t.requestENR(n); err == nil {
+ if rn, err := t.RequestENR(n); err == nil {
return rn
}
// Check table for the ID, we might have a newer version there.
if intable := t.tab.getNode(n.ID()); intable != nil && intable.Seq() > n.Seq() {
n = intable
- if rn, err := t.requestENR(n); err == nil {
+ if rn, err := t.RequestENR(n); err == nil {
return rn
}
}
@@ -433,7 +433,7 @@ func (t *UDPv4) Resolve(n *enode.Node) *enode.Node {
result := t.LookupPubkey((*ecdsa.PublicKey)(&key))
for _, rn := range result {
if rn.ID() == n.ID() {
- if rn, err := t.requestENR(rn); err == nil {
+ if rn, err := t.RequestENR(rn); err == nil {
return rn
}
}
@@ -447,6 +447,12 @@ func (t *UDPv4) ourEndpoint() rpcEndpoint {
return makeEndpoint(a, uint16(n.TCP()))
}
+// Ping sends a ping message to the given node.
+func (t *UDPv4) Ping(n *enode.Node) error {
+ _, err := t.ping(n)
+ return err
+}
+
// ping sends a ping message to the given node and waits for a reply.
func (t *UDPv4) ping(n *enode.Node) (seq uint64, err error) {
rm := t.sendPing(n.ID(), &net.UDPAddr{IP: n.IP(), Port: n.UDP()}, nil)
@@ -521,8 +527,8 @@ func (t *UDPv4) findnode(toid enode.ID, toaddr *net.UDPAddr, target encPubkey) (
return nodes, <-rm.errc
}
-// requestENR sends enrRequest to the given node and waits for a response.
-func (t *UDPv4) requestENR(n *enode.Node) (*enode.Node, error) {
+// RequestENR sends enrRequest to the given node and waits for a response.
+func (t *UDPv4) RequestENR(n *enode.Node) (*enode.Node, error) {
addr := &net.UDPAddr{IP: n.IP(), Port: n.UDP()}
t.ensureBond(n.ID(), addr)