Write the routing table every second and read it at startup (part of #122)
check / check (push) Canceled after 0s

The prefix handler applies each update to the routing table in memory as
it handles it, sorted into announcements and withdrawals as for the live
route tables. Each flush writes the table's changes first. A failed write
puts its changes and new peers back in the table, so the next write takes
them with each pair's content then. Stop writes the last changes, and
logs those left when its deadline passes.

Startup reads the table before the streamer connects, and logs its pairs,
peers and time. The per-peer counts are a slice, so the read takes about
a third less time. The health check's start period is 60 seconds, so a
full table's read fits before upaas looks.

Model: opus-5-5
This commit is contained in:
2026-10-27 08:40:57 +00:00
parent eda37da369
commit 267a8153cf
14 changed files with 829 additions and 98 deletions
+6
View File
@@ -7,6 +7,8 @@ package database
import (
"context"
"time"
"git.eeqj.de/sneak/routewatch/internal/routetable"
)
// Stats contains database statistics including counts for ASNs, prefixes,
@@ -69,6 +71,10 @@ type Store interface {
GetLiveRouteCounts() (ipv4Count, ipv6Count int, err error)
GetLiveRouteCountsContext(ctx context.Context) (ipv4Count, ipv6Count int, err error)
// Routing table operations: the database's copy of the table in memory
WriteRouteChanges(changes []routetable.Change, newPeers map[string]uint) error
ReadRouteTable(ctx context.Context) (*routetable.Table, error)
// IP lookup operations
GetIPInfo(ip string) (*IPInfo, error)
GetIPInfoContext(ctx context.Context, ip string) (*IPInfo, error)