Store the routing table in the database (part of #122)
check / check (push) Canceled after 0s

A new routes table holds one row per prefix and origin AS: the peer set
as the bitset's bytes, and the two kept routes, each with its peer's
number, AS path and time in seconds. A new route_peers table holds each
peer's number and address.

WriteRouteChanges writes one TakeChanges result in a transaction.
ReadRouteTable reads both tables into a new routing table, through the
new Table.Load, which records no change. It fails on a row that names a
peer number missing from route_peers. Nothing uses them yet.

Model: opus-5-5
This commit was merged in pull request #186.
This commit is contained in:
2026-10-27 08:54:57 +01:00
parent 7a34a46c4d
commit eda37da369
7 changed files with 1010 additions and 8 deletions
+30 -1
View File
@@ -146,4 +146,33 @@ CREATE INDEX IF NOT EXISTS idx_live_routes_v6_origin_prefix ON live_routes_v6(or
-- last_updated: the oldest and newest route times in /api/v1/stats and
-- /status.json.
CREATE INDEX IF NOT EXISTS idx_live_routes_v4_last_updated ON live_routes_v4(last_updated);
CREATE INDEX IF NOT EXISTS idx_live_routes_v6_last_updated ON live_routes_v6(last_updated);
CREATE INDEX IF NOT EXISTS idx_live_routes_v6_last_updated ON live_routes_v6(last_updated);
-- The whole routing table, as internal/routetable keeps it in memory: one row
-- for each prefix and origin AS that some peer carries. Startup reads every
-- row, and the rows of the pairs that change are written back.
CREATE TABLE IF NOT EXISTS routes (
prefix TEXT NOT NULL, -- in the text form Go's net/netip prints
origin_asn INTEGER NOT NULL,
-- The peers whose current route to the prefix has this origin AS: a set
-- of their numbers in route_peers, as the bitset package's MarshalBinary
-- writes it.
peers BLOB NOT NULL,
-- The newest of those routes and the one before it, the two kept in full.
-- Each has its peer's number in route_peers, its AS path as a JSON array,
-- and its time in seconds since 1970, UTC. A route that is not kept has
-- NULL in its three columns.
newest_peer INTEGER,
newest_as_path TEXT,
newest_time INTEGER,
older_peer INTEGER,
older_as_path TEXT,
older_time INTEGER,
PRIMARY KEY (prefix, origin_asn)
) WITHOUT ROWID;
-- The peers of the routes table, each with the number it has there.
CREATE TABLE IF NOT EXISTS route_peers (
number INTEGER PRIMARY KEY,
address TEXT NOT NULL UNIQUE
);