2019-06-07 16:29:16 +03: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 19:22:36 +03:00
|
|
|
"github.com/ethereum/go-ethereum/internal/flags"
|
2019-09-25 12:38:13 +03:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2022-06-27 19:22:36 +03:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-06-07 16:29:16 +03:00
|
|
|
)
|
|
|
|
|
2022-09-23 15:08:25 +03:00
|
|
|
var app = flags.NewApp("go-ethereum devp2p tool")
|
2019-06-07 16:29:16 +03:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
app.Flags = append(app.Flags, debug.Flags...)
|
|
|
|
app.Before = func(ctx *cli.Context) error {
|
2022-06-27 19:22:36 +03:00
|
|
|
flags.MigrateGlobalFlags(ctx)
|
2020-01-21 15:57:33 +03:00
|
|
|
return debug.Setup(ctx)
|
2019-06-07 16:29:16 +03: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 15:08:25 +03:00
|
|
|
|
2019-06-07 16:29:16 +03:00
|
|
|
// Add subcommands.
|
2022-06-27 19:22:36 +03:00
|
|
|
app.Commands = []*cli.Command{
|
2019-06-07 16:29:16 +03:00
|
|
|
enrdumpCommand,
|
2020-06-24 11:41:53 +03:00
|
|
|
keyCommand,
|
2019-06-07 16:29:16 +03:00
|
|
|
discv4Command,
|
2020-04-08 10:57:23 +03:00
|
|
|
discv5Command,
|
2019-09-25 12:38:13 +03:00
|
|
|
dnsCommand,
|
2019-10-29 18:08:57 +03:00
|
|
|
nodesetCommand,
|
2020-09-22 11:17:39 +03:00
|
|
|
rlpxCommand,
|
2019-06-07 16:29:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2019-09-25 12:38:13 +03: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 19:22:36 +03: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 12:38:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// getNodeArg handles the common case of a single node descriptor argument.
|
|
|
|
func getNodeArg(ctx *cli.Context) *enode.Node {
|
2020-09-23 16:18:17 +03:00
|
|
|
if ctx.NArg() < 1 {
|
2019-09-25 12:38:13 +03:00
|
|
|
exit("missing node as command-line argument")
|
|
|
|
}
|
2022-06-27 19:22:36 +03:00
|
|
|
n, err := parseNode(ctx.Args().First())
|
2019-09-25 12:38:13 +03:00
|
|
|
if err != nil {
|
|
|
|
exit(err)
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
func exit(err interface{}) {
|
|
|
|
if err == nil {
|
|
|
|
os.Exit(0)
|
2019-06-07 16:29:16 +03:00
|
|
|
}
|
2019-09-25 12:38:13 +03:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
2019-06-07 16:29:16 +03:00
|
|
|
}
|