From bf97e221bd9b8441d6560b54efa9b1df466a3f59 Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Tue, 13 Oct 2020 23:47:03 +0500 Subject: [PATCH 1/5] Redirect status output to stderr --- main.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 8e2f929..7978b9c 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,15 @@ import ( "github.com/yggdrasil-network/yggdrasil-go/src/crypto" ) -var version = "v0.1.3" +var ( + programName = "syg_go" + version = "v0.1.3" +) + +var ( + stdout = log.New(os.Stdout, "", log.Flags()) + stderr = log.New(os.Stderr, "", log.Flags()) +) func main() { rxflag := flag.String("regex", "::", "regex to match addresses against") @@ -31,21 +39,22 @@ func main() { highAddressMode := flag.Bool("highaddr", false, "high address mining mode, excludes regex") flag.Parse() if *displayVersion { - println("syg_go", version) + println(programName, version) + // TODO: add license and author information return } if *origCode { - log.Println("using unmodified Yggdrasil code") + stdout.Println("using unmodified Yggdrasil code") addrForNodeID = address.AddrForNodeID } else { - log.Println("using syg_go vendored code") + stdout.Println("using syg_go vendored code") addrForNodeID = AddrForNodeID } regex, err := regexp.Compile(*rxflag) if err != nil { - log.Printf("%v\n", err) + stderr.Printf("%v\n", err) os.Exit(1) } @@ -53,9 +62,9 @@ func main() { var currentBest []byte if !*highAddressMode { - log.Printf("starting mining for %v with %v threads\n", regex, *threads) + stdout.Printf("starting mining for %v with %v threads\n", regex, *threads) } else { - log.Printf("starting mining higher addresses with %v threads\n", *threads) + stdout.Printf("starting mining higher addresses with %v threads\n", *threads) } for i := 0; i < *threads; i++ { go doBoxKeys(newKeys) @@ -71,7 +80,7 @@ func main() { } counter++ if counter%i == 0 { - log.Printf("reached %v iterations\n", counter) + stderr.Printf("reached %v iterations\n", counter) } } } else { @@ -83,7 +92,7 @@ func main() { } counter++ if counter%i == 0 { - log.Printf("reached %v iterations\n", counter) + stderr.Printf("reached %v iterations\n", counter) } } } @@ -97,7 +106,7 @@ type keySet struct { } func (k *keySet) print() { - log.Printf("priv: %s | pub: %s | nodeid: %s | ip: %s\n", + stdout.Printf("priv: %s | pub: %s | nodeid: %s | ip: %s\n", hex.EncodeToString(k.priv[:]), hex.EncodeToString(k.pub[:]), hex.EncodeToString(k.id[:]), From 3a087559c41b9333fea7f6a890f837e03f9c4818 Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Tue, 13 Oct 2020 23:47:41 +0500 Subject: [PATCH 2/5] Update README on cmdline flags meaning and usage --- README.md | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 14c10ec..ea0738a 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,39 @@ If you're an Arch Linux user, you can install it from `% yay -S syg_go` +### Features + +* regex-based key mining (see `-regex`) +* bruteforce-resistant keys mining mode (see `-highaddr`) +* multithreaded key mining (see `-threads`) + +### Usage + +``` +% syg_go -help +Usage of syg_go: + -highaddr + high address mining mode, excludes regex + -iter uint + per how many iterations to output status (default 100000) + -original + use original Yggdrasil code + -regex string + regex to match addresses against (default "::") + -threads int + how many threads to use for mining (default 16) + -version + display version +``` + +This program outputs keys found to stdout and iterations numbers reached +to stderr so that users can redirect the (possibly) irrelevant status +output to /dev/null. To redirect status output to /dev/null, run: + +``` +% syg_go ...flags... 2>/dev/null +``` + ### History [SimpleYggGen](https://notabug.org/acetone/SimpleYggGen-Bash) is originally a @@ -50,25 +83,6 @@ This program contains some modded code from Yggdrasil that aims to improve performance. If you prefer to use original Yggdrasil code, set `-original` flag. -### Usage - -``` -% syg_go -help -Usage of syg_go: - -highaddr - high address mining mode, excludes regex - -iter uint - per how many iterations to output status (default 100000) - -original - use original Yggdrasil code - -regex string - regex to match addresses against (default "::") - -threads int - how many threads to use for mining (default 16) - -version - display version -``` - ### Development `go tool pprof` support is available when building with `-tags debug`. The From e063c8522bbec60fa2d918e912aabd809185852e Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Tue, 13 Oct 2020 23:51:50 +0500 Subject: [PATCH 3/5] Add copyright information to -version --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 7978b9c..ab7bfec 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ import ( var ( programName = "syg_go" version = "v0.1.3" + copyright = "Copyright (c) 2020 Timur Demin" ) var ( @@ -40,7 +41,7 @@ func main() { flag.Parse() if *displayVersion { println(programName, version) - // TODO: add license and author information + println(copyright) return } From f60619bddd4fcb2b6dc184ed0d1182e09a16a75e Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Tue, 13 Oct 2020 23:52:17 +0500 Subject: [PATCH 4/5] Use custom logger when debugging --- debug.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/debug.go b/debug.go index f10ac30..7d2f07c 100644 --- a/debug.go +++ b/debug.go @@ -3,7 +3,6 @@ package main import ( - "log" "net/http" _ "net/http/pprof" "os" @@ -14,10 +13,10 @@ func init() { if listen == "" { listen = "[::]:8082" } - log.Printf("profiling is enabled, HTTP server is attached to %s\n", listen) + stdout.Printf("profiling is enabled, HTTP server is attached to %s\n", listen) go func() { if err := http.ListenAndServe(listen, nil); err != nil { - log.Fatalf("http failed: %v\n", err) + stderr.Fatalf("http failed: %v\n", err) } }() } From 56bd4a771791776c07d1508ae1ca21951e4a8383 Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Tue, 13 Oct 2020 23:54:43 +0500 Subject: [PATCH 5/5] Bump v0.1.4 --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index ab7bfec..24a6eda 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,7 @@ import ( var ( programName = "syg_go" - version = "v0.1.3" + version = "v0.1.4" copyright = "Copyright (c) 2020 Timur Demin" )