2026-08-21 07:34:45 +03:00
|
|
|
package db
|
|
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
|
|
// Validator and IP lifecycle states. Kept as typed string constants rather
|
|
|
|
|
// than a Go enum type so they round-trip through SQLite TEXT columns and
|
|
|
|
|
// JSON without conversion.
|
|
|
|
|
const (
|
|
|
|
|
ValidatorUnregistered = "unregistered"
|
|
|
|
|
ValidatorIdle = "idle"
|
|
|
|
|
ValidatorAssigned = "assigned"
|
|
|
|
|
ValidatorChecking = "checking"
|
|
|
|
|
ValidatorUnreachable = "unreachable"
|
|
|
|
|
|
2026-08-26 20:47:54 +03:00
|
|
|
// Site (prober) availability states — no assigned/checking equivalent,
|
|
|
|
|
// since a prober isn't bound to one IP at a time.
|
|
|
|
|
SiteUnregistered = "unregistered"
|
|
|
|
|
SiteIdle = "idle"
|
|
|
|
|
SiteUnreachable = "unreachable"
|
|
|
|
|
|
2026-08-21 07:34:45 +03:00
|
|
|
IPQueued = "queued"
|
|
|
|
|
IPAssigningFIP = "assigning_fip"
|
|
|
|
|
IPAwaitingSelfCheck = "awaiting_self_check"
|
|
|
|
|
IPChecking = "checking"
|
|
|
|
|
IPAggregating = "aggregating"
|
|
|
|
|
IPDone = "done"
|
|
|
|
|
IPFailed = "failed"
|
|
|
|
|
|
2026-08-23 20:39:22 +03:00
|
|
|
ResultPass = "pass"
|
|
|
|
|
ResultPartial = "partial"
|
|
|
|
|
ResultFail = "fail"
|
|
|
|
|
ResultCancelled = "cancelled"
|
2026-08-21 07:34:45 +03:00
|
|
|
|
|
|
|
|
SourceEgress = "egress"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// InboundSource returns the checks.source value for the given prober site
|
|
|
|
|
// index (1-based), e.g. InboundSource(1) == "inbound-site-1".
|
|
|
|
|
func InboundSource(siteIndex int) string {
|
|
|
|
|
return "inbound-site-" + itoa(siteIndex)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func itoa(n int) string {
|
|
|
|
|
if n == 0 {
|
|
|
|
|
return "0"
|
|
|
|
|
}
|
|
|
|
|
neg := n < 0
|
|
|
|
|
if neg {
|
|
|
|
|
n = -n
|
|
|
|
|
}
|
|
|
|
|
var buf [20]byte
|
|
|
|
|
i := len(buf)
|
|
|
|
|
for n > 0 {
|
|
|
|
|
i--
|
|
|
|
|
buf[i] = byte('0' + n%10)
|
|
|
|
|
n /= 10
|
|
|
|
|
}
|
|
|
|
|
if neg {
|
|
|
|
|
i--
|
|
|
|
|
buf[i] = '-'
|
|
|
|
|
}
|
|
|
|
|
return string(buf[i:])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Validator struct {
|
|
|
|
|
ValidatorID string
|
|
|
|
|
Hostname string
|
|
|
|
|
OSPortID string
|
|
|
|
|
State string
|
|
|
|
|
CurrentIPID *int64
|
|
|
|
|
AgentVersion string
|
|
|
|
|
LastHeartbeatAt *time.Time
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type IPQueueItem struct {
|
|
|
|
|
ID int64
|
|
|
|
|
IPAddress string
|
|
|
|
|
Sequence int
|
|
|
|
|
State string
|
|
|
|
|
OwnerValidatorID *string
|
|
|
|
|
FIPID string
|
|
|
|
|
AttemptNumber int
|
|
|
|
|
RetryCount int
|
|
|
|
|
LeaseExpiresAt *time.Time
|
|
|
|
|
EgressComplete bool
|
|
|
|
|
OverallResult string
|
|
|
|
|
AssignedAt *time.Time
|
2026-08-24 10:29:08 +03:00
|
|
|
FIPAssociatedAt *time.Time
|
2026-08-21 07:34:45 +03:00
|
|
|
AggregatedAt *time.Time
|
|
|
|
|
FIPReleasedAt *time.Time
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Check struct {
|
|
|
|
|
ID int64
|
|
|
|
|
IPID int64
|
|
|
|
|
IPAddress string
|
|
|
|
|
AttemptNumber int
|
|
|
|
|
ValidatorID string
|
|
|
|
|
Source string
|
|
|
|
|
CheckType string
|
|
|
|
|
Target string
|
|
|
|
|
Success bool
|
|
|
|
|
LatencyMS int64
|
|
|
|
|
Detail string
|
|
|
|
|
CheckedAt time.Time
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Event struct {
|
|
|
|
|
ID int64
|
|
|
|
|
SourceType string
|
|
|
|
|
SourceID string
|
|
|
|
|
IPID *int64
|
|
|
|
|
EventType string
|
|
|
|
|
Payload string
|
|
|
|
|
OccurredAt time.Time
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
}
|
2026-08-23 20:39:22 +03:00
|
|
|
|
|
|
|
|
type Site struct {
|
2026-08-26 20:47:54 +03:00
|
|
|
Index int
|
|
|
|
|
SiteID string
|
|
|
|
|
Hostname string
|
|
|
|
|
State string
|
|
|
|
|
LastHeartbeatAt *time.Time
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
UpdatedAt time.Time
|
2026-08-23 20:39:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TargetGroup struct {
|
|
|
|
|
Name string
|
|
|
|
|
Targets []string
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CheckType struct {
|
|
|
|
|
Name string
|
|
|
|
|
Enabled bool
|
|
|
|
|
TargetGroups []string
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ResolvedCheckType is a check type with its target groups already expanded
|
|
|
|
|
// into a flat target list — what AssignmentForValidator hands to an agent.
|
|
|
|
|
type ResolvedCheckType struct {
|
|
|
|
|
Type string
|
|
|
|
|
Targets []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SubmitIPsResult categorizes how each address in a SubmitIPs call was
|
|
|
|
|
// handled.
|
|
|
|
|
type SubmitIPsResult struct {
|
|
|
|
|
Added []string
|
|
|
|
|
Requeued []string
|
|
|
|
|
Reordered []string
|
|
|
|
|
SkippedInProgress []string
|
|
|
|
|
}
|
2026-08-23 22:24:55 +03:00
|
|
|
|
|
|
|
|
// DeleteIPsResult categorizes how each address in a DeleteIPs call (or a
|
|
|
|
|
// ClearQueue call, which is DeleteIPs given every currently queued address)
|
|
|
|
|
// was handled.
|
|
|
|
|
type DeleteIPsResult struct {
|
|
|
|
|
Deleted []string
|
|
|
|
|
NotFound []string
|
|
|
|
|
}
|
2026-08-24 10:29:08 +03:00
|
|
|
|
|
|
|
|
// Settings is the singleton row of orchestrator-wide scalar knobs that are
|
|
|
|
|
// admin-configurable at runtime (see queries_settings.go).
|
|
|
|
|
type Settings struct {
|
|
|
|
|
FIPSettleSeconds int
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
}
|
2026-08-26 19:45:48 +03:00
|
|
|
|
|
|
|
|
// InboundChecksSettings is the singleton row describing what the prober
|
|
|
|
|
// checks on every site for every in-flight IP (TCP ports + optional ICMP).
|
|
|
|
|
// Admin-configurable at runtime (see queries_inbound.go).
|
|
|
|
|
type InboundChecksSettings struct {
|
|
|
|
|
Ports []int
|
|
|
|
|
ICMP bool
|
|
|
|
|
CreatedAt time.Time
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
}
|