Page through the received routes, on the status page and in the API

/api/routes/received now returns one page: {routes, next_after,
prev_before}. Pages are in prefix order and begin at a prefix (after= or
before=), not at a count, so a table that changes between two pages does
not make them overlap or leave a gap. A page holds whole prefixes, about
`limit` routes' worth.

The table keeps prefixes in no order, so a page is found by looking at
every prefix once and keeping the nearest few; the routes of the others
are not touched (RibTable::for_each_prefix).

The status page shows about 100 routes with first / previous / next
links; the place is kept in the page's address with the lookup.

The response of /api/routes/received was an array before: this changes
its shape.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Rayhaan JaufeerallyandClaude Fable 5.1 committed 2026-10-02 14:33:38 +02:00
1 parent f9ef781d51
commit 1f84235e87
10 files changed
+536 -67

No files matched your search

+32
View File
@@ -215,6 +215,23 @@ impl Row {
}
}
/// A prefix in the table with its routes, looked at in place.
#[derive(Clone, Copy)]
pub struct PrefixRef<'a> {
row: &'a Row,
}
impl<'a> PrefixRef<'a> {
pub fn prefix(&self) -> &'a IpPrefix {
&self.row.prefix
}
/// The routes there are for the prefix: at least one.
pub fn routes(&self) -> impl Iterator<Item = RouteRef<'a>> + use<'a> {
self.row.routes()
}
}
/// A route in the table, looked at in place.
#[derive(Debug, Clone, Copy)]
pub struct RouteRef<'a> {
@@ -556,6 +573,21 @@ impl RibTable {
routes
}
/// Calls `visit` with every prefix that has routes, in no particular
/// order. As [`RibTable::for_each_best`]: the table is not stopped,
/// and `visit` must not call into it.
///
/// The prefix's routes are there to be looked at, and cost nothing if
/// they are not: this is how to pick a few prefixes out of a table
/// with a great many routes for each.
pub fn for_each_prefix(&self, mut visit: impl FnMut(PrefixRef<'_>)) {
for shard in &self.shards {
for row in &read(shard).rows {
visit(PrefixRef { row });
}
}
}
/// Calls `visit` with every route in the table. As
/// [`RibTable::for_each_best`]: the table is not stopped, and `visit`
/// must not call into it.