This repository has been archived by the owner on Mar 21, 2022. It is now read-only.
/
main.go
89 lines (77 loc) · 2.02 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
/*
Parts of this program are taken from yggdrasil-go, located at
https://github.com/yggdrasil-network/yggdrasil-go
See cmd/genkeys/main.go@78b5f88e4bb734d0dd6a138ff08d34ca39dcaea3
*/
import (
"encoding/hex"
"flag"
"log"
"net"
"os"
"regexp"
"runtime"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
)
var version = "v0.1.1"
func main() {
rxflag := flag.String("regex", "::", "regex to match addresses against")
threads := flag.Int("threads", runtime.GOMAXPROCS(0), "how many threads to use for mining")
iterationsPerOutput := flag.Uint("iter", 100000, "per how many iterations to output status")
displayVersion := flag.Bool("version", false, "display version")
origCode := flag.Bool("original", false, "use original Yggdrasil code")
flag.Parse()
if *displayVersion {
println("syg_go", version)
return
}
if *origCode {
log.Println("using unmodified Yggdrasil code")
addrForNodeID = address.AddrForNodeID
} else {
log.Println("using syg_go vendored code")
addrForNodeID = AddrForNodeID
}
regex, err := regexp.Compile(*rxflag)
if err != nil {
log.Printf("%v\n", err)
os.Exit(1)
}
newKeys := make(chan keySet, *threads)
log.Printf("starting mining for %v with %v threads\n", regex, *threads)
for i := 0; i < *threads; i++ {
go doBoxKeys(newKeys)
}
counter := uint64(0)
i := uint64(*iterationsPerOutput)
for {
newKey := <-newKeys
if regex.MatchString(newKey.ip) {
log.Printf("priv: %s | pub: %s | nodeid: %s | ip: %s\n",
hex.EncodeToString(newKey.priv[:]),
hex.EncodeToString(newKey.pub[:]),
hex.EncodeToString(newKey.id[:]),
newKey.ip)
}
counter++
if counter%i == 0 {
log.Printf("reached %v iterations\n", counter)
}
}
}
type keySet struct {
priv []byte
pub []byte
id []byte
ip string
}
func doBoxKeys(out chan<- keySet) {
for {
pub, priv := crypto.NewBoxKeys()
id := crypto.GetNodeID(pub)
ip := net.IP(addrForNodeID(id)[:]).String()
out <- keySet{priv[:], pub[:], id[:], ip}
}
}