reports!!!! and PoW!!!!!!!

this has taken quite a while (8 ish hours) but reports and proof of work challenges are completely implemented

the proof of work challenges are bit iffy and could be gpu accelerated which is bad, so i plan to eventually switch to something memory hard like argon2id

references used for pow:
https://dev.to/ratmd/simple-proof-of-work-in-javascript-3kgm
https://anubis.techaro.lol/docs/design/how-anubis-works
https://anubis.techaro.lol/docs/design/why-proof-of-work

as well as some other posts or repos found when searching
This commit is contained in:
2026-11-20 21:31:37 -05:00
parent ee03411154
commit 5c2427b096
14 changed files with 470 additions and 15 deletions
+37
View File
@@ -1,6 +1,7 @@
package main
import (
"encoding/hex"
"errors"
"html/template"
"log"
@@ -41,6 +42,22 @@ func staticPage(pages *Pages, name string) http.HandlerFunc {
}
}
func resultPage(pages *Pages, title string, message string, statusCode ...int) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
code := 200
if len(statusCode) > 0 {
code = statusCode[0]
}
w.WriteHeader(code)
render(pages, w, "result.html", map[string]any{
"Qt": getRandomQt(pages.Qts),
"Title": title,
"Message": message,
})
}
}
func getRandomQt(qts []string) string {
if len(qts) > 0 {
return qts[rand.IntN(len(qts))]
@@ -115,3 +132,23 @@ func faqHandler(pages *Pages, cfg Config) http.HandlerFunc {
})
}
}
func reportPageHandler(pages *Pages, store *ChallengeStore, cfg Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
id, challenge, err := store.Issue(cfg.PoWDifficulty)
if err != nil {
http.Error(w, "failed to generate PoW challenge", http.StatusInternalServerError)
return
}
render(pages, w, "report.html", map[string]any{
"Qt": getRandomQt(pages.Qts),
"Challenge": map[string]any{
"Data": hex.EncodeToString(challenge.Data),
"Difficulty": challenge.Difficulty,
"ExpiresAt": challenge.ExpiresAt,
"Id": id,
},
"ReportOptions": cfg.ReportOptions,
})
}
}