Every time in UTC, and every day as YYYY-MM-DD (closes #313)
check / check (push) Successful in 3m20s

AbuseIPDB's daily count keeps its day as a civil.Date, taken from the UTC
clock and written to reputation.json as "YYYY-MM-DD"; it was a time.Time
at midnight. Every time read from a state file is converted to UTC, so a
time an admin writes with an offset is written back in UTC.
TestMainRunsDiscriminator runs sww discriminator with TZ 14 hours ahead
of UTC and checks that the process line, the request line and
clients.json are in UTC. SPEC.md states the rule near its start;
AGENTS.md makes it an iron rule.

Model: opus-5-5
This commit is contained in:
sneak committed 2026-11-11 01:20:44 +00:00
1 parent ad36dd1775
commit 2bdecf2f34
11 files changed
+256 -22

No files matched your search

+7 -8
View File
@@ -14,6 +14,7 @@ import (
"sync"
"time"
"cloud.google.com/go/civil"
"github.com/hashicorp/golang-lru/v2/simplelru"
"sneak.berlin/go/smallwebwaf/internal/alerts"
)
@@ -27,8 +28,6 @@ const (
AbuseIPDBSource = "abuseipdb"
// maxAnswerBytes is the most of an answer of AbuseIPDB that is read.
maxAnswerBytes = 64 << 10
// day is the length of the day the checks are counted in, in UTC.
day = 24 * time.Hour
)
var (
@@ -50,9 +49,9 @@ type Score struct {
// AbuseIPDB: the day, in UTC, of the checks Spent counts, zero before the
// first, and the scores still in use.
type Checks struct {
Day time.Time `json:"day,omitzero"`
Spent int `json:"spent"`
Scores []Score `json:"scores"`
Day civil.Date `json:"day,omitzero"`
Spent int `json:"spent"`
Scores []Score `json:"scores"`
}
// AbuseIPDBParams are what NewAbuseIPDB needs.
@@ -93,7 +92,7 @@ type AbuseIPDB struct {
// checking are the clients whose check is under way.
checking map[netip.Prefix]bool
// day is the day, in UTC, of the checks spent counts.
day time.Time
day civil.Date
spent int
// checks and failures count the checks made and those that failed,
// and retryAt is when a client may be checked again after the last
@@ -143,7 +142,7 @@ func (a *AbuseIPDB) Hit(
return kept.Score, kept.Score >= a.params.MinScore
}
if today := now.Truncate(day); !a.day.Equal(today) {
if today := civil.DateOf(now.UTC()); a.day != today {
a.day, a.spent = today, 0
}
@@ -190,7 +189,7 @@ func (a *AbuseIPDB) BudgetLeft() int {
a.mu.Lock()
defer a.mu.Unlock()
if !a.day.Equal(a.params.Now().Truncate(day)) {
if a.day != civil.DateOf(a.params.Now().UTC()) {
return a.params.DailyBudget
}