mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-02-12 09:51:50 +00:00
genkeys print the number of generated keys (#1217)
It is good to know how many resources have we carelessly wasted. :-)
This commit is contained in:
parent
9c73bacab9
commit
22bc9c44e2
1 changed files with 10 additions and 2 deletions
|
@ -26,6 +26,7 @@ import (
|
|||
type keySet struct {
|
||||
priv ed25519.PrivateKey
|
||||
pub ed25519.PublicKey
|
||||
count uint64
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -36,6 +37,8 @@ func main() {
|
|||
threads := runtime.GOMAXPROCS(0)
|
||||
fmt.Println("Threads:", threads)
|
||||
start := time.Now()
|
||||
var totalKeys uint64
|
||||
totalKeys = 0
|
||||
var currentBest ed25519.PublicKey
|
||||
newKeys := make(chan keySet, threads)
|
||||
for i := 0; i < threads; i++ {
|
||||
|
@ -44,8 +47,9 @@ func main() {
|
|||
for {
|
||||
newKey := <-newKeys
|
||||
if isBetter(currentBest, newKey.pub) || len(currentBest) == 0 {
|
||||
totalKeys += newKey.count
|
||||
currentBest = newKey.pub
|
||||
fmt.Println("-----", time.Since(start))
|
||||
fmt.Println("-----", time.Since(start), "---", totalKeys, "keys tried")
|
||||
fmt.Println("Priv:", hex.EncodeToString(newKey.priv))
|
||||
fmt.Println("Pub:", hex.EncodeToString(newKey.pub))
|
||||
addr := address.AddrForKey(newKey.pub)
|
||||
|
@ -68,11 +72,14 @@ func isBetter(oldPub, newPub ed25519.PublicKey) bool {
|
|||
|
||||
func doKeys(out chan<- keySet) {
|
||||
bestKey := make(ed25519.PublicKey, ed25519.PublicKeySize)
|
||||
var count uint64
|
||||
count = 0
|
||||
for idx := range bestKey {
|
||||
bestKey[idx] = 0xff
|
||||
}
|
||||
for {
|
||||
pub, priv, err := ed25519.GenerateKey(nil)
|
||||
count++
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -80,6 +87,7 @@ func doKeys(out chan<- keySet) {
|
|||
continue
|
||||
}
|
||||
bestKey = pub
|
||||
out <- keySet{priv, pub}
|
||||
out <- keySet{priv, pub, count}
|
||||
count = 0
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue