Documentation
¶
Overview ¶
Package engine turns per-source signal counts into a ban list. It is a pure decision package: Step reads its inputs and returns what it would do, and the engine changes only when Commit is called after the caller has recorded the new bans.
Index ¶
Constants ¶
const ( SourceScorer = "scorer" SourceManual = "manual" )
Entry sources.
const ( SuppressedByAllowlist = "allowlist" SuppressedByLift = "lift" )
What suppressed an entry.
const ( DeferHourCap = "hour_cap" DeferFeederCap = "feeder_cap" DeferMaxEntries = "max_entries" DeferCoverage = "coverage" DeferGenerationCap = "generation_cap" )
Deferral reasons.
Variables ¶
var DeferReasons = []string{DeferHourCap, DeferFeederCap, DeferMaxEntries, DeferCoverage, DeferGenerationCap}
DeferReasons lists every deferral reason.
Functions ¶
This section is empty.
Types ¶
type Ban ¶
type Ban struct {
Unit netip.Prefix
Issued time.Time
Expires time.Time
Points float64
// Number is 1 for a first ban, 2 for the next within the repeat
// window, and so on.
Number int
Feeders []string
Signals map[string]float64
Reason string
}
Ban is one scored ban.
type Caps ¶
type Caps struct {
MaxEntries int `json:"maxEntries"`
MaxAddedPerGeneration int `json:"maxAddedPerGeneration"`
MaxNewPerHour int `json:"maxNewPerHour"`
MaxNewPerFeederPerHour int `json:"maxNewPerFeederPerHour"`
MaxIPv4Addresses uint64 `json:"maxIPv4Addresses"`
MaxIPv6Networks uint64 `json:"maxIPv6Networks"`
}
Caps bound what one step may publish and ban.
type Config ¶
type Config struct {
Threshold float64
Window time.Duration
IPv6Prefix int
BanBase time.Duration
BanMax time.Duration
RepeatWindow time.Duration
Caps Caps
Signals []Signal
}
Config is the scoring policy.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine holds the bans issued so far.
func (*Engine) Commit ¶
Commit applies a step's new bans and manual entries after the caller has recorded them, and forgets what has aged out.
func (*Engine) Published ¶
Published tells the engine what consumers now hold, for the next step's generation cap.
type Entry ¶
type Entry struct {
CIDR string `json:"cidr"`
Expires int64 `json:"expires"`
Source string `json:"source"`
Reason string `json:"reason"`
Commit string `json:"commit"`
}
Entry is one published prefix.
type Inputs ¶
type Inputs struct {
Now time.Time
Mode Mode
// Tallies are the signals' rows, by signal name. A signal without one
// gives no points.
Tallies map[string]*Tally
Allow *netaddr.Set
Manual []manual.Entry
// NoNewDecisions issues no bans and reports no newly seen manual
// entries, for a step whose decisions cannot be recorded. Its list still
// drops what has expired, been lifted or been allowed.
NoNewDecisions bool
}
Inputs is everything one step reads.
type Result ¶
type Result struct {
Now time.Time
NewBans []Ban
NewManual []manual.Entry
Entries []Entry
// Suppressed are sources over the threshold, bans in force and manual
// bans that the allowlist or a lift keeps off the list.
Suppressed []Suppression
// Deferred are entries a cap holds back, by reason. They are considered
// again at the next step.
Deferred map[string][]netip.Prefix
// WouldBan are sources a shadow signal would have banned, by signal.
WouldBan map[string][]netip.Prefix
// Scored counts sources with any points from counting signals.
Scored int
// Invalid counts rows that could not be scored: their address did not
// parse, or their attempts were not a count.
Invalid int
// ActiveManual counts manual entries in force, by action.
ActiveManual map[string]int
}
Result is what one step would do.
type Row ¶
Row is one signal's count for one address and feeder over the window. The feeder is whoever reported the attempts, such as a host; caps on new bans are kept per feeder.
type Signal ¶
Signal weighs one kind of evidence. Points from a signal are Weight per attempt, at most Cap per source over the window (0 means no cap). A shadow signal is scored and reported but never counts toward a ban.
type Suppression ¶
type Suppression struct {
Prefix netip.Prefix
Points float64
// By is SuppressedByAllowlist or SuppressedByLift.
By string
Manual bool
}
Suppression is a source, a ban in force or a manual ban kept off the list.