2019-06-07 15:29:16 +02:00
|
|
|
// Copyright 2019 The go-ethereum Authors
|
|
|
|
// This file is part of go-ethereum.
|
|
|
|
//
|
|
|
|
// go-ethereum is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// go-ethereum is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/internal/debug"
|
2022-06-27 18:22:36 +02:00
|
|
|
"github.com/ethereum/go-ethereum/internal/flags"
|
2019-09-25 11:38:13 +02:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2022-06-27 18:22:36 +02:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-06-07 15:29:16 +02:00
|
|
|
)
|
|
|
|
|
2022-09-23 14:08:25 +02:00
|
|
|
var app = flags.NewApp("go-ethereum devp2p tool")
|
2019-06-07 15:29:16 +02:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
app.Flags = append(app.Flags, debug.Flags...)
|
|
|
|
app.Before = func(ctx *cli.Context) error {
|
2022-06-27 18:22:36 +02:00
|
|
|
flags.MigrateGlobalFlags(ctx)
|
2020-01-21 13:57:33 +01:00
|
|
|
return debug.Setup(ctx)
|
2019-06-07 15:29:16 +02:00
|
|
|
}
|
|
|
|
app.After = func(ctx *cli.Context) error {
|
|
|
|
debug.Exit()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
app.CommandNotFound = func(ctx *cli.Context, cmd string) {
|
|
|
|
fmt.Fprintf(os.Stderr, "No such command: %s\n", cmd)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2022-09-23 14:08:25 +02:00
|
|
|
|
2019-06-07 15:29:16 +02:00
|
|
|
// Add subcommands.
|
2022-06-27 18:22:36 +02:00
|
|
|
app.Commands = []*cli.Command{
|
2019-06-07 15:29:16 +02:00
|
|
|
enrdumpCommand,
|
2020-06-24 10:41:53 +02:00
|
|
|
keyCommand,
|
2019-06-07 15:29:16 +02:00
|
|
|
discv4Command,
|
2020-04-08 09:57:23 +02:00
|
|
|
discv5Command,
|
2019-09-25 11:38:13 +02:00
|
|
|
dnsCommand,
|
2019-10-29 16:08:57 +01:00
|
|
|
nodesetCommand,
|
2020-09-22 10:17:39 +02:00
|
|
|
rlpxCommand,
|
2019-06-07 15:29:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2019-09-25 11:38:13 +02:00
|
|
|
exit(app.Run(os.Args))
|
|
|
|
}
|
|
|
|
|
|
|
|
// commandHasFlag returns true if the current command supports the given flag.
|
|
|
|
func commandHasFlag(ctx *cli.Context, flag cli.Flag) bool {
|
2022-06-27 18:22:36 +02:00
|
|
|
names := flag.Names()
|
|
|
|
set := make(map[string]struct{}, len(names))
|
|
|
|
for _, name := range names {
|
|
|
|
set[name] = struct{}{}
|
|
|
|
}
|
|
|
|
for _, fn := range ctx.FlagNames() {
|
|
|
|
if _, ok := set[fn]; ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2019-09-25 11:38:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// getNodeArg handles the common case of a single node descriptor argument.
|
|
|
|
func getNodeArg(ctx *cli.Context) *enode.Node {
|
2020-09-23 15:18:17 +02:00
|
|
|
if ctx.NArg() < 1 {
|
2019-09-25 11:38:13 +02:00
|
|
|
exit("missing node as command-line argument")
|
|
|
|
}
|
2022-06-27 18:22:36 +02:00
|
|
|
n, err := parseNode(ctx.Args().First())
|
2019-09-25 11:38:13 +02:00
|
|
|
if err != nil {
|
|
|
|
exit(err)
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
func exit(err interface{}) {
|
|
|
|
if err == nil {
|
|
|
|
os.Exit(0)
|
2019-06-07 15:29:16 +02:00
|
|
|
}
|
2019-09-25 11:38:13 +02:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
2019-06-07 15:29:16 +02:00
|
|
|
}
|