bastion 0.60.0
ci / personal-data (push) Successful in 4s
ci / test (push) Successful in 3m36s
ci / fuzz (push) Successful in 3m35s

This commit is contained in:
Privatae
2026-11-02 00:10:58 +00:00
parent 4a5c310482
commit 4f8285ef18
100 changed files with 11537 additions and 840 deletions
+39 -31
View File
@@ -137,41 +137,49 @@ func noteRefusal(pairing, op, why string, write bool, now time.Time) {
e = &quarantineEntry{}
f.Pairing[pairing] = e
}
// A refusal DURING a hold is the hold working, not a new strike: the
// quarantine refusal itself comes through here, and counting it would
// re-arm the hold the moment it lapsed.
if quarantinedAt(e, now) {
_ = quarantineSave(f)
return
}
// Recent write refusals only — the window slides.
kept := e.Refusals[:0]
for _, ts := range e.Refusals {
if t, err := time.Parse(time.RFC3339, ts); err == nil && now.Sub(t) < quarantineWindow {
kept = append(kept, ts)
}
}
e.Refusals = append(kept, now.UTC().Format(time.RFC3339))
if len(e.Refusals) >= quarantineStrikes && !quarantinedAt(e, now) {
if t, err := time.Parse(time.RFC3339, e.LastHold); err == nil && now.Sub(t) > quarantineForgive {
e.Strikes = 0
}
hold := quarantineBase
for i := 0; i < e.Strikes && hold < quarantineMaxHold; i++ {
hold *= 2
}
if hold > quarantineMaxHold {
hold = quarantineMaxHold
}
e.Strikes++
e.Until = now.Add(hold).UTC().Format(time.RFC3339)
e.LastHold = e.Until
e.Refusals = nil
}
e.strike(now)
}
_ = quarantineSave(f)
}
// strike counts one refusal against e and starts a hold at the
// quarantineStrikes-th inside the window. Reports whether a hold started.
// Shared with the local askers' holds (askquarantine.go).
func (e *quarantineEntry) strike(now time.Time) bool {
// A refusal DURING a hold is the hold working, not a new strike: the
// quarantine refusal itself comes through here, and counting it would
// re-arm the hold the moment it lapsed.
if quarantinedAt(e, now) {
return false
}
// Recent refusals only — the window slides.
kept := e.Refusals[:0]
for _, ts := range e.Refusals {
if t, err := time.Parse(time.RFC3339, ts); err == nil && now.Sub(t) < quarantineWindow {
kept = append(kept, ts)
}
}
e.Refusals = append(kept, now.UTC().Format(time.RFC3339))
if len(e.Refusals) < quarantineStrikes {
return false
}
if t, err := time.Parse(time.RFC3339, e.LastHold); err == nil && now.Sub(t) > quarantineForgive {
e.Strikes = 0
}
hold := quarantineBase
for i := 0; i < e.Strikes && hold < quarantineMaxHold; i++ {
hold *= 2
}
if hold > quarantineMaxHold {
hold = quarantineMaxHold
}
e.Strikes++
e.Until = now.Add(hold).UTC().Format(time.RFC3339)
e.LastHold = e.Until
e.Refusals = nil
return true
}
func quarantinedAt(e *quarantineEntry, now time.Time) bool {
if e == nil || e.Until == "" {
return false