aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorjae beller <foss@jae.zone>2025-03-29 23:38:12 -0400
committerGitHub <noreply@github.com>2025-03-29 23:38:12 -0400
commit5237291072c19a8f07b47162b7a9a86a1d1a21b2 (patch)
treedd8d0eb724dbc4e642cc9ca79ab83c33b7fd1b35 /cmd
parent0f41388bd78668ceae6d5c12b05868bd0ca8fd1f (diff)
downloadanubis-5237291072c19a8f07b47162b7a9a86a1d1a21b2.tar.xz
anubis-5237291072c19a8f07b47162b7a9a86a1d1a21b2.zip
Debug tool for benchmarking proof-of-work algorithms (#155)
* cmd/anubis: add a debug option for benchmarking hashrate Having the ability to benchmark different proof-of-work implementations is useful for extending Anubis. This adds a flag `--debug-benchmark-js` (and its associated environment variable `DEBUG_BENCHMARK_JS`) for serving a tool to do so. Internally, a there is a new policy action, "DEBUG_BENCHMARK", which serves the benchmarking tool instead of a challenge. The flag then replaces all bot rules with a special rule matching every request to that action. The benchmark page makes heavy use of inline styles, because currently all global styles are shared across all pages. This could be fixed, but I wanted to avoid major changes to the templates. * web/js: add signal for aborting an active proof-of-work algorithm Both proof-of-work algorithms now take an optional `AbortSignal`, which immediately terminates all workers and returns `false` if aborted before the challenge is complete. * web/js: add algorithm comparison to the benchmark page "Compare:" is added to the benchmark page for testing the relative performance between two algorithms. Since benchmark runs generally have high variance, it may take a while for the averages to converge on a stable difference. --------- Signed-off-by: Xe Iaso <me@xeiaso.net> Co-authored-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/anubis/main.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/cmd/anubis/main.go b/cmd/anubis/main.go
index 4cee20c..8ab370d 100644
--- a/cmd/anubis/main.go
+++ b/cmd/anubis/main.go
@@ -15,6 +15,7 @@ import (
"net/url"
"os"
"os/signal"
+ "regexp"
"strconv"
"sync"
"syscall"
@@ -23,6 +24,7 @@ import (
"github.com/TecharoHQ/anubis"
"github.com/TecharoHQ/anubis/internal"
libanubis "github.com/TecharoHQ/anubis/lib"
+ botPolicy "github.com/TecharoHQ/anubis/lib/policy"
"github.com/TecharoHQ/anubis/lib/policy/config"
"github.com/facebookgo/flagenv"
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -44,6 +46,7 @@ var (
target = flag.String("target", "http://localhost:3923", "target to reverse proxy to")
healthcheck = flag.Bool("healthcheck", false, "run a health check against Anubis")
useRemoteAddress = flag.Bool("use-remote-address", false, "read the client's IP address from the network request, useful for debugging and running Anubis on bare metal")
+ debugBenchmarkJS = flag.Bool("debug-benchmark-js", false, "respond to every request with a challenge for benchmarking hashrate")
)
func keyFromHex(value string) (ed25519.PrivateKey, error) {
@@ -187,6 +190,16 @@ func main() {
}
fmt.Println()
+ // replace the bot policy rules with a single rule that always benchmarks
+ if *debugBenchmarkJS {
+ userAgent := regexp.MustCompile(".")
+ policy.Bots = []botPolicy.Bot{{
+ Name: "",
+ UserAgent: userAgent,
+ Action: config.RuleBenchmark,
+ }}
+ }
+
var priv ed25519.PrivateKey
if *ed25519PrivateKeyHex == "" {
_, priv, err = ed25519.GenerateKey(rand.Reader)
@@ -241,6 +254,7 @@ func main() {
"target", *target,
"version", anubis.Version,
"use-remote-address", *useRemoteAddress,
+ "debug-benchmark-js", *debugBenchmarkJS,
)
go func() {