cmd/bootnode: Add support for outputting a node's ID on the command line
This commit is contained in:
parent
f970610c04
commit
91130ea3fc
@ -20,6 +20,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
@ -32,7 +33,8 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
listenAddr = flag.String("addr", ":30301", "listen address")
|
listenAddr = flag.String("addr", ":30301", "listen address")
|
||||||
genKey = flag.String("genkey", "", "generate a node key and quit")
|
genKey = flag.String("genkey", "", "generate a node key")
|
||||||
|
writeAddr = flag.Bool("writeaddress", false, "write out the node's pubkey hash and quit")
|
||||||
nodeKeyFile = flag.String("nodekey", "", "private key filename")
|
nodeKeyFile = flag.String("nodekey", "", "private key filename")
|
||||||
nodeKeyHex = flag.String("nodekeyhex", "", "private key as hex (for testing)")
|
nodeKeyHex = flag.String("nodekeyhex", "", "private key as hex (for testing)")
|
||||||
natdesc = flag.String("nat", "none", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)")
|
natdesc = flag.String("nat", "none", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)")
|
||||||
@ -45,22 +47,19 @@ func main() {
|
|||||||
glog.SetToStderr(true)
|
glog.SetToStderr(true)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *genKey != "" {
|
|
||||||
key, err := crypto.GenerateKey()
|
|
||||||
if err != nil {
|
|
||||||
utils.Fatalf("could not generate key: %v", err)
|
|
||||||
}
|
|
||||||
if err := crypto.SaveECDSA(*genKey, key); err != nil {
|
|
||||||
utils.Fatalf("%v", err)
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
natm, err := nat.Parse(*natdesc)
|
natm, err := nat.Parse(*natdesc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("-nat: %v", err)
|
utils.Fatalf("-nat: %v", err)
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
|
case *genKey != "":
|
||||||
|
nodeKey, err = crypto.GenerateKey()
|
||||||
|
if err != nil {
|
||||||
|
utils.Fatalf("could not generate key: %v", err)
|
||||||
|
}
|
||||||
|
if err = crypto.SaveECDSA(*genKey, nodeKey); err != nil {
|
||||||
|
utils.Fatalf("%v", err)
|
||||||
|
}
|
||||||
case *nodeKeyFile == "" && *nodeKeyHex == "":
|
case *nodeKeyFile == "" && *nodeKeyHex == "":
|
||||||
utils.Fatalf("Use -nodekey or -nodekeyhex to specify a private key")
|
utils.Fatalf("Use -nodekey or -nodekeyhex to specify a private key")
|
||||||
case *nodeKeyFile != "" && *nodeKeyHex != "":
|
case *nodeKeyFile != "" && *nodeKeyHex != "":
|
||||||
@ -75,6 +74,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *writeAddr {
|
||||||
|
fmt.Printf("%v\n", discover.PubkeyID(&nodeKey.PublicKey))
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm, ""); err != nil {
|
if _, err := discover.ListenUDP(nodeKey, *listenAddr, natm, ""); err != nil {
|
||||||
utils.Fatalf("%v", err)
|
utils.Fatalf("%v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user