mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/devp2p: add disc4 randomwalk command
This commit is contained in:
parent
61c4079496
commit
aeffde1dc4
1 changed files with 23 additions and 0 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -38,6 +39,7 @@ var (
|
||||||
discv4PingCommand,
|
discv4PingCommand,
|
||||||
discv4RequestRecordCommand,
|
discv4RequestRecordCommand,
|
||||||
discv4ResolveCommand,
|
discv4ResolveCommand,
|
||||||
|
discv4RandomWalkCommand,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
discv4PingCommand = cli.Command{
|
discv4PingCommand = cli.Command{
|
||||||
|
|
@ -56,6 +58,12 @@ var (
|
||||||
Action: discv4Resolve,
|
Action: discv4Resolve,
|
||||||
Flags: []cli.Flag{bootnodesFlag},
|
Flags: []cli.Flag{bootnodesFlag},
|
||||||
}
|
}
|
||||||
|
discv4RandomWalkCommand = cli.Command{
|
||||||
|
Name: "randomwalk",
|
||||||
|
Usage: "Prints random nodes found in the DHT",
|
||||||
|
Action: discv4RandomNodes,
|
||||||
|
Flags: []cli.Flag{bootnodesFlag},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var bootnodesFlag = cli.StringFlag{
|
var bootnodesFlag = cli.StringFlag{
|
||||||
|
|
@ -104,6 +112,21 @@ func discv4Resolve(ctx *cli.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func discv4RandomNodes(ctx *cli.Context) error {
|
||||||
|
bootnodes, err := parseBootnodes(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
disc, err := startV4(bootnodes)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
iter := disc.RandomNodes()
|
||||||
|
for {
|
||||||
|
fmt.Println(iter.NextNode(context.Background()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getNodeArgAndStartV4(ctx *cli.Context) (*enode.Node, *discover.UDPv4, error) {
|
func getNodeArgAndStartV4(ctx *cli.Context) (*enode.Node, *discover.UDPv4, error) {
|
||||||
if ctx.NArg() != 1 {
|
if ctx.NArg() != 1 {
|
||||||
return nil, nil, fmt.Errorf("missing node as command-line argument")
|
return nil, nil, fmt.Errorf("missing node as command-line argument")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue