Improved the identity hash generation tool. The fastest quantity of goroutines is now identified and used.

This commit is contained in:
Simon Sarasova 2024-06-03 02:42:45 +00:00
parent 35cda50ad7
commit 497f596b3b
No known key found for this signature in database
GPG key ID: EEDA4103C9C36944
4 changed files with 129 additions and 97 deletions

View file

@ -6,6 +6,7 @@ Small and insignificant changes may not be included in this log.
## Unversioned Changes
* Improved the identity hash generation tool. The fastest quantity of goroutines is now identified and used. - *Simon Sarasova*
* Improved the creation procedures, encoding format, and graphical presentation of genetic analyses. Map lists have been replaced by custom objects. - *Simon Sarasova*
* Upgraded Circl to version 1.3.8. - *Simon Sarasova*

View file

@ -9,4 +9,4 @@ Many other people have written code for modules which are imported by Seekia. Th
Name | Date Of First Commit | Number Of Commits
--- | --- | ---
Simon Sarasova | June 13, 2023 | 248
Simon Sarasova | June 13, 2023 | 249

View file

@ -26,6 +26,7 @@ import "math"
import "time"
import "errors"
func setChooseNewIdentityHashPage(window fyne.Window, myIdentityType string, previousPage func(), onceCompletePage func()){
currentPage := func(){ setChooseNewIdentityHashPage(window, myIdentityType, previousPage, onceCompletePage) }
@ -59,7 +60,7 @@ func setChooseNewIdentityHashPage(window fyne.Window, myIdentityType string, pre
}
createCustomIdentityHashButton := getWidgetCentered(widget.NewButtonWithIcon("Create Custom", theme.SearchReplaceIcon(), func(){
setCreateCustomIdentityHashPage(window, myIdentityType, currentPage, submitPageFunction)
setCreateCustomIdentityHashPage(window, myIdentityType, false, 0, 0, currentPage, submitPageFunction)
}))
selectRandomIdentityHashLabel := getLabelCentered("Select a random identity hash:")
@ -253,24 +254,36 @@ func setEnterMyNewSeedPhrasePage(window fyne.Window, myIdentityType string, newS
setPageContent(page, window)
}
//Inputs:
// -fyne.Window
// -string: Identity Type ("Mate"/"Host"/"Moderator")
// -bool: Benchmark is done (is false if we need to perform the benchmark
// -int64: Hashes per second (is 0 if benchmark hasn't been performed)
// -int: Optimal number of goroutines
// -previousPage()
// func(string, func()): submitPage function = func(newSeedPhrase string, previousPage func())
func setCreateCustomIdentityHashPage(window fyne.Window, identityType string, benchmarkIsDone bool, computerHashesPerSecond int64, optimalNumberOfGoroutines int, previousPage func(), submitPage func(string, func()) ){
// submitPage function = func(newSeedPhrase string, previousPage func())
func setCreateCustomIdentityHashPage(window fyne.Window, identityType string, previousPage func(), submitPage func(string, func()) ){
setLoadingScreen(window, "Create Custom Identity Hash", "Loading...")
currentPage := func(){ setCreateCustomIdentityHashPage(window, identityType, previousPage, submitPage) }
if (benchmarkIsDone == false){
setLoadingScreen(window, "Create Custom Identity Hash", "Performing benchmark, this will take 4 seconds...")
// Output:
// -int64: Hashes per second
// -int: Optimal number of goroutines
// -error
getIdentityHashGenerationSpeed := func()(int64, error){
performBenchmark := func()(int64, int, error){
//TODO: Fix to retrieve language from settings
currentLanguage := "English"
currentLanguageWordList, err := wordLists.GetWordListFromLanguage(currentLanguage)
if (err != nil) { return 0, err }
if (err != nil) { return 0, 0, err }
optimalNumberOfGoroutines := 0
optimalNumberOfGoroutinesHashesPerSecond := int64(0)
// We will try 1-8 goroutines to see which is the fastest
for numberOfGoroutines:=1; numberOfGoroutines<=8; numberOfGoroutines++{
// This counter will store the number of hashes we can compute in 1 second
var counterMutex sync.Mutex
@ -337,12 +350,15 @@ func setCreateCustomIdentityHashPage(window fyne.Window, identityType string, pr
generateHashesStatusBool = true
identityHashGenerationWaitgroup.Add(2)
identityHashGenerationWaitgroup.Add(numberOfGoroutines)
for i:=0; i < numberOfGoroutines; i++{
go generateIdentityHashesFunction()
go generateIdentityHashesFunction()
}
time.Sleep(time.Second)
// We run all goroutines for 1/2 of a second
time.Sleep(time.Second/2)
generateHashesStatusBoolMutex.Lock()
generateHashesStatusBool = false
@ -351,18 +367,34 @@ func setCreateCustomIdentityHashPage(window fyne.Window, identityType string, pr
identityHashGenerationWaitgroup.Wait()
if (errorEncountered != nil){
return 0, errorEncountered
return 0, 0, errorEncountered
}
return counter, nil
currentGoroutinesNumberOfHashesPerSecond := counter*2
if (currentGoroutinesNumberOfHashesPerSecond > optimalNumberOfGoroutinesHashesPerSecond){
optimalNumberOfGoroutines = numberOfGoroutines
optimalNumberOfGoroutinesHashesPerSecond = currentGoroutinesNumberOfHashesPerSecond
}
}
hashGenerationSpeed, err := getIdentityHashGenerationSpeed()
return optimalNumberOfGoroutinesHashesPerSecond, optimalNumberOfGoroutines, nil
}
optimalNumberOfGoroutinesHashesPerSecond, optimalNumberOfGoroutines, err := performBenchmark()
if (err != nil){
setErrorEncounteredPage(window, err, previousPage)
return
}
setCreateCustomIdentityHashPage(window, identityType, true, optimalNumberOfGoroutinesHashesPerSecond, optimalNumberOfGoroutines, previousPage, submitPage)
return
}
currentPage := func(){
setCreateCustomIdentityHashPage(window, identityType, true, computerHashesPerSecond, optimalNumberOfGoroutines, previousPage, submitPage)
}
title := getPageTitleCentered("Create Custom Identity Hash")
backButton := getBackButtonCentered(previousPage)
@ -385,7 +417,7 @@ func setCreateCustomIdentityHashPage(window fyne.Window, identityType string, pr
customPrefixEntryOnChangedFunction := func(newPrefix string){
if (newPrefix == ""){
err = estimatedTimeLabelBinding.Set("")
err := estimatedTimeLabelBinding.Set("")
if (err != nil) {
setErrorEncounteredPage(window, err, previousPage)
return
@ -400,7 +432,7 @@ func setCreateCustomIdentityHashPage(window fyne.Window, identityType string, pr
prefixLength := len(newPrefix)
if (prefixLength >= 13){
err = estimatedTimeLabelBinding.Set("Prefix is too long.")
err := estimatedTimeLabelBinding.Set("Prefix is too long.")
if (err != nil) {
setErrorEncounteredPage(window, err, previousPage)
return
@ -415,7 +447,7 @@ func setCreateCustomIdentityHashPage(window fyne.Window, identityType string, pr
isBase32, invalidCharacter := encoding.VerifyStringContainsOnlyBase32Charset(newPrefix)
if (isBase32 == false){
err = estimatedTimeLabelBinding.Set("Invalid character detected: " + invalidCharacter)
err := estimatedTimeLabelBinding.Set("Invalid character detected: " + invalidCharacter)
if (err != nil) {
setErrorEncounteredPage(window, err, previousPage)
return
@ -432,7 +464,7 @@ func setCreateCustomIdentityHashPage(window fyne.Window, identityType string, pr
numberOfBits := float64(numberOfCharacters * 5)
numberOfRequiredHashes := math.Pow(2, numberOfBits)
estimatedTimeToGenerateInSeconds := numberOfRequiredHashes / float64(hashGenerationSpeed)
estimatedTimeToGenerateInSeconds := numberOfRequiredHashes / float64(computerHashesPerSecond)
estimatedTimeUnitsTranslated, err := helpers.ConvertUnixTimeDurationToUnitsTimeTranslated(int64(estimatedTimeToGenerateInSeconds), false)
if (err != nil) {
@ -489,7 +521,7 @@ func setCreateCustomIdentityHashPage(window fyne.Window, identityType string, pr
}
emptyList := make([]string, 0)
setRunCustomIdentityHashGenerationPage(window, identityType, prefix, estimatedTimeUnitsTranslated, hashGenerationSpeed, emptyList, currentPage, submitPage)
setRunCustomIdentityHashGenerationPage(window, identityType, prefix, estimatedTimeUnitsTranslated, optimalNumberOfGoroutines, computerHashesPerSecond, emptyList, currentPage, submitPage)
}))
customPrefixEntrySection := getContainerCentered(container.NewGridWithColumns(1, enterDesiredPrefixText, customPrefixEntry, startGeneratingHashesButton))
@ -499,13 +531,11 @@ func setCreateCustomIdentityHashPage(window fyne.Window, identityType string, pr
setPageContent(page, window)
}
//TODO: Update the estimated time every ~10 seconds
//TODO: Figure out optimal number of goroutines to use for maximum speed
func setRunCustomIdentityHashGenerationPage(window fyne.Window, identityType string, desiredPrefix string, estimatedTimeRequired string, initialHashesPerSecond int64, seedPhrasesFoundList []string, previousPage func(), submitPage func(string, func()) ){
func setRunCustomIdentityHashGenerationPage(window fyne.Window, identityType string, desiredPrefix string, estimatedTimeRequired string, numberOfGoroutines int, initialHashesPerSecond int64, seedPhrasesFoundList []string, previousPage func(), submitPage func(string, func()) ){
currentPage := func(){setRunCustomIdentityHashGenerationPage(window, identityType, desiredPrefix, estimatedTimeRequired, initialHashesPerSecond, seedPhrasesFoundList, previousPage, submitPage)}
currentPage := func(){setRunCustomIdentityHashGenerationPage(window, identityType, desiredPrefix, estimatedTimeRequired, numberOfGoroutines, initialHashesPerSecond, seedPhrasesFoundList, previousPage, submitPage)}
appMemory.SetMemoryEntry("CurrentViewedPage", "RunCustomIdentityHashGeneration")
@ -627,7 +657,7 @@ func setRunCustomIdentityHashGenerationPage(window fyne.Window, identityType str
retryButton := getWidgetCentered(widget.NewButtonWithIcon("Retry", theme.ViewRefreshIcon(), func(){
emptyList := make([]string, 0)
setRunCustomIdentityHashGenerationPage(window, identityType, desiredPrefix, estimatedTimeRequired, initialHashesPerSecond, emptyList, previousPage, submitPage)
setRunCustomIdentityHashGenerationPage(window, identityType, desiredPrefix, estimatedTimeRequired, numberOfGoroutines, initialHashesPerSecond, emptyList, previousPage, submitPage)
}))
page := container.NewVBox(title, backButton, widget.NewSeparator(), doneDescription1, doneDescription2, widget.NewSeparator(), foundHashesGrid, retryButton)
@ -801,10 +831,11 @@ func setRunCustomIdentityHashGenerationPage(window fyne.Window, identityType str
setGenerateHashesStatusBool(true)
generateHashesWaitgroup.Add(2)
generateHashesWaitgroup.Add(numberOfGoroutines)
for i:=0; i < numberOfGoroutines; i++{
go generateIdentityHashesFunction()
go generateIdentityHashesFunction()
}
numberOfSecondsElapsed := 0
@ -882,7 +913,7 @@ func setRunCustomIdentityHashGenerationPage(window fyne.Window, identityType str
// We wait for all loops to exit
generateHashesWaitgroup.Wait()
setRunCustomIdentityHashGenerationPage(window, identityType, desiredPrefix, estimatedTimeRequired, currentHashesPerSecond, seedPhrasesFoundList, previousPage, submitPage)
setRunCustomIdentityHashGenerationPage(window, identityType, desiredPrefix, estimatedTimeRequired, numberOfGoroutines, currentHashesPerSecond, seedPhrasesFoundList, previousPage, submitPage)
return
}

View file

@ -93,7 +93,7 @@ func setChooseIdentityTypeForNewIdentityHashPage(window fyne.Window, previousPag
}
chooseIdentityTypeButton := widget.NewButton(identityType, func(){
setCreateCustomIdentityHashPage(window, identityType, currentPage, submitPage)
setCreateCustomIdentityHashPage(window, identityType, false, 0, 0, currentPage, submitPage)
})
buttonWithIcon := container.NewGridWithColumns(1, identityTypeIcon, chooseIdentityTypeButton)