feat: add audit/window.go

This commit is contained in:
2026-09-25 11:57:14 +08:00
parent 9d99288b43
commit 64dfafaa1e

23
audit/window.go Normal file
View File

@@ -0,0 +1,23 @@
package audit
type Window struct {
Last uint16
HasLast bool
Summary Summary
}
func (w *Window) Observe(sequence uint16) string {
if !w.HasLast {
w.Last, w.HasLast = sequence, true
w.Summary.Accepted++
w.Summary.Latest = sequence
return "accepted"
}
delta := uint16(sequence - w.Last)
if delta == 0 { w.Summary.Duplicate++; return "duplicate" }
if delta > 32767 { w.Summary.Reordered++; return "reordered" }
if delta > 1 { w.Summary.Lost += uint64(delta - 1) }
w.Last, w.Summary.Latest = sequence, sequence
w.Summary.Accepted++
return "accepted"
}