From 4fb7d8f4d46f297170960d147be0dfbad6466990 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 5 Aug 2015 02:38:02 +1000 Subject: [PATCH] cmd/dht-secure-id --- cmd/dht-secure-id/main.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 cmd/dht-secure-id/main.go diff --git a/cmd/dht-secure-id/main.go b/cmd/dht-secure-id/main.go new file mode 100644 index 00000000..cf6c3a08 --- /dev/null +++ b/cmd/dht-secure-id/main.go @@ -0,0 +1,34 @@ +package main + +import ( + "encoding/hex" + "fmt" + "net" + "os" + + "github.com/docopt/docopt-go" + + "github.com/anacrolix/torrent/dht" +) + +func main() { + args, _ := docopt.Parse(`dht-secure-id outputs the node ID secured with the IP. + +Usage: dht-secure-id `, nil, true, "", false) + id, err := hex.DecodeString(args[""].(string)) + if err != nil { + fmt.Fprintf(os.Stderr, "bad id: %s\n", err) + os.Exit(2) + } + if len(id) != 20 { + fmt.Fprintf(os.Stderr, "bad id: wrong length\n") + os.Exit(2) + } + ip := net.ParseIP(args[""].(string)) + if ip == nil { + fmt.Fprintf(os.Stderr, "bad ip\n") + os.Exit(2) + } + dht.SecureNodeId(id, ip) + fmt.Printf("%x\n", id) +} -- 2.48.1