Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Commit

Permalink
Remove extraneous optimizations from genkeys
Browse files Browse the repository at this point in the history
cmd/genkeys tries to save time on converting IPs to strings, but this
time appears to be lost on doing Go scheduling stuff instead. We remove
the optimization.
  • Loading branch information
tdemin committed Aug 30, 2020
1 parent c3b2905 commit 6a0dacd
Showing 1 changed file with 9 additions and 37 deletions.
46 changes: 9 additions & 37 deletions main.go
Expand Up @@ -50,21 +50,15 @@ func main() {
}

newKeys := make(chan keySet, *threads)
var (
threadChannels []chan []byte
currentBest []byte
)
var currentBest []byte

if !*highAddressMode {
log.Printf("starting mining for %v with %v threads\n", regex, *threads)
for i := 0; i < *threads; i++ {
go doBoxKeys(newKeys)
}
} else {
log.Printf("starting mining higher addresses with %v threads\n", *threads)
for i := 0; i < *threads; i++ {
threadChannels = append(threadChannels, make(chan []byte, *threads))
go doBoxKeysHighAddr(newKeys, threadChannels[i])
}
}
for i := 0; i < *threads; i++ {
go doBoxKeys(newKeys)
}

counter := uint64(0)
Expand All @@ -85,13 +79,12 @@ func main() {
newKey := <-newKeys
if isBetter(currentBest[:], newKey.id) || len(currentBest) == 0 {
currentBest = newKey.id
for _, channel := range threadChannels {
select {
case channel <- newKey.id:
}
}
newKey.print()
}
counter++
if counter%i == 0 {
log.Printf("reached %v iterations\n", counter)
}
}
}
}
Expand Down Expand Up @@ -131,24 +124,3 @@ func isBetter(oldID, newID []byte) bool {
}
return false
}

func doBoxKeysHighAddr(out chan<- keySet, in <-chan []byte) {
var bestID crypto.NodeID
for {
select {
case newBestID := <-in:
if isBetter(bestID[:], newBestID) {
copy(bestID[:], newBestID)
}
default:
pub, priv := crypto.NewBoxKeys()
id := crypto.GetNodeID(pub)
if !isBetter(bestID[:], id[:]) {
continue
}
bestID = *id
ip := net.IP(address.AddrForNodeID(id)[:]).String()
out <- keySet{priv[:], pub[:], id[:], ip}
}
}
}

0 comments on commit 6a0dacd

Please sign in to comment.