diff options
| author | 2025-05-26 11:57:50 +0200 | |
|---|---|---|
| committer | 2025-05-26 11:57:50 +0200 | |
| commit | 326e04283a2536d64a7055bfef184f5817b691d6 (patch) | |
| tree | af3f86c2ce3a0ce430825a84f653f8a1e2c40b03 /internal/config | |
| parent | [chore] update dependencies (#4188) (diff) | |
| download | gotosocial-326e04283a2536d64a7055bfef184f5817b691d6.tar.xz | |
[feature] update proof-of-work to allow setting required rounds (#4186)
# Description
This updates our proof-of-work middleware, NoLLaMas, to work on a more easily configurable algorithm (thank you f0x for bringing this to my attention!). Instead of requiring that a solution with pre-determined number of '0' chars be found, it now pre-computes a result with a pre-determined nonce value that it expects the client to iterate up-to. (though with some level of jitter applied, to prevent it being too-easily gamed). This allows the user to configure roughly how many hash-encode rounds they want their clients to have to complete.
## Checklist
- [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md).
- [x] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
- [x] I/we have not leveraged AI to create the proposed changes.
- [x] I/we have performed a self-review of added code.
- [x] I/we have written code that is legible and maintainable by others.
- [x] I/we have commented the added code, particularly in hard-to-understand areas.
- [x] I/we have made any necessary changes to documentation.
- [ ] I/we have added tests that cover new code.
- [x] I/we have run tests and they pass locally with the changes.
- [x] I/we have run `go fmt ./...` and `golangci-lint run`.
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4186
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 4 | ||||
| -rw-r--r-- | internal/config/defaults.go | 2 | ||||
| -rw-r--r-- | internal/config/helpers.gen.go | 14 |
3 files changed, 10 insertions, 10 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 5b8da9703..f051ab005 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -280,6 +280,6 @@ type ThrottlingConfig struct { } type ScraperDeterrenceConfig struct { - Enabled bool `name:"enabled" usage:"Enable proof-of-work based scraper deterrence on profile / status pages"` - Difficulty uint8 `name:"difficulty" usage:"The proof-of-work difficulty, which determines how many leading zeros to try solve in hash solutions."` + Enabled bool `name:"enabled" usage:"Enable proof-of-work based scraper deterrence on profile / status pages"` + Difficulty uint32 `name:"difficulty" usage:"The proof-of-work difficulty, which determines roughly how many hash-encode rounds required of each client."` } diff --git a/internal/config/defaults.go b/internal/config/defaults.go index 8372e4b00..ad124e90f 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -149,7 +149,7 @@ var Defaults = Configuration{ ScraperDeterrence: ScraperDeterrenceConfig{ Enabled: false, - Difficulty: 4, + Difficulty: 100000, }, }, diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go index 269aa7abc..38f33c67e 100644 --- a/internal/config/helpers.gen.go +++ b/internal/config/helpers.gen.go @@ -144,7 +144,7 @@ func (cfg *Configuration) RegisterFlags(flags *pflag.FlagSet) { flags.Int("advanced-throttling-multiplier", cfg.Advanced.Throttling.Multiplier, "Multiplier to use per cpu for http request throttling. 0 or less turns throttling off.") flags.Duration("advanced-throttling-retry-after", cfg.Advanced.Throttling.RetryAfter, "Retry-After duration response to send for throttled requests.") flags.Bool("advanced-scraper-deterrence-enabled", cfg.Advanced.ScraperDeterrence.Enabled, "Enable proof-of-work based scraper deterrence on profile / status pages") - flags.Uint8("advanced-scraper-deterrence-difficulty", cfg.Advanced.ScraperDeterrence.Difficulty, "The proof-of-work difficulty, which determines how many leading zeros to try solve in hash solutions.") + flags.Uint32("advanced-scraper-deterrence-difficulty", cfg.Advanced.ScraperDeterrence.Difficulty, "The proof-of-work difficulty, which determines how many leading zeros to try solve in hash solutions.") flags.StringSlice("http-client-allow-ips", cfg.HTTPClient.AllowIPs, "") flags.StringSlice("http-client-block-ips", cfg.HTTPClient.BlockIPs, "") flags.Duration("http-client-timeout", cfg.HTTPClient.Timeout, "") @@ -1356,9 +1356,9 @@ func (cfg *Configuration) UnmarshalMap(cfgmap map[string]any) error { if ival, ok := cfgmap["advanced-scraper-deterrence-difficulty"]; ok { var err error - cfg.Advanced.ScraperDeterrence.Difficulty, err = cast.ToUint8E(ival) + cfg.Advanced.ScraperDeterrence.Difficulty, err = cast.ToUint32E(ival) if err != nil { - return fmt.Errorf("error casting %#v -> uint8 for 'advanced-scraper-deterrence-difficulty': %w", ival, err) + return fmt.Errorf("error casting %#v -> uint32 for 'advanced-scraper-deterrence-difficulty': %w", ival, err) } } @@ -4799,7 +4799,7 @@ func AdvancedScraperDeterrenceDifficultyFlag() string { } // GetAdvancedScraperDeterrenceDifficulty safely fetches the Configuration value for state's 'Advanced.ScraperDeterrence.Difficulty' field -func (st *ConfigState) GetAdvancedScraperDeterrenceDifficulty() (v uint8) { +func (st *ConfigState) GetAdvancedScraperDeterrenceDifficulty() (v uint32) { st.mutex.RLock() v = st.config.Advanced.ScraperDeterrence.Difficulty st.mutex.RUnlock() @@ -4807,7 +4807,7 @@ func (st *ConfigState) GetAdvancedScraperDeterrenceDifficulty() (v uint8) { } // SetAdvancedScraperDeterrenceDifficulty safely sets the Configuration value for state's 'Advanced.ScraperDeterrence.Difficulty' field -func (st *ConfigState) SetAdvancedScraperDeterrenceDifficulty(v uint8) { +func (st *ConfigState) SetAdvancedScraperDeterrenceDifficulty(v uint32) { st.mutex.Lock() defer st.mutex.Unlock() st.config.Advanced.ScraperDeterrence.Difficulty = v @@ -4815,12 +4815,12 @@ func (st *ConfigState) SetAdvancedScraperDeterrenceDifficulty(v uint8) { } // GetAdvancedScraperDeterrenceDifficulty safely fetches the value for global configuration 'Advanced.ScraperDeterrence.Difficulty' field -func GetAdvancedScraperDeterrenceDifficulty() uint8 { +func GetAdvancedScraperDeterrenceDifficulty() uint32 { return global.GetAdvancedScraperDeterrenceDifficulty() } // SetAdvancedScraperDeterrenceDifficulty safely sets the value for global configuration 'Advanced.ScraperDeterrence.Difficulty' field -func SetAdvancedScraperDeterrenceDifficulty(v uint8) { +func SetAdvancedScraperDeterrenceDifficulty(v uint32) { global.SetAdvancedScraperDeterrenceDifficulty(v) } |
