Show figures of the routing table on the home page (closes #154)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The home page gets cards for the newest and oldest kept route, the newest and oldest updated AS, the AS with the most prefixes, the ASes with a single prefix and fifteen well-known networks. Two more cards count the bogon announcements and the prefixes with several origin ASes. They link to the new pages /bogons and /multiple-origins, which list up to 1,000 entries each. The new package internal/bogon tells reserved prefixes and AS numbers, from the IANA special-purpose and address space registries. Table.Overview walks the table and lets the read lock go every 10,000 prefixes. The server works the cards out once a minute and serves that copy. A new index on asns(last_seen) finds the newest and oldest updated AS. Model: opus-5-5
This commit was merged in pull request #196.
This commit is contained in:
@@ -972,6 +972,34 @@ func (d *Database) GetAS(ctx context.Context, asn int) (*ASN, bool, error) {
|
||||
return &asnInfo, true, nil
|
||||
}
|
||||
|
||||
// The queries of GetLastSeenASes. The index on last_seen answers each without
|
||||
// reading the whole table.
|
||||
const (
|
||||
newestLastSeenASQuery = `
|
||||
SELECT asn, handle, description, first_seen, last_seen
|
||||
FROM asns ORDER BY last_seen DESC LIMIT 1`
|
||||
oldestLastSeenASQuery = `
|
||||
SELECT asn, handle, description, first_seen, last_seen
|
||||
FROM asns ORDER BY last_seen ASC LIMIT 1`
|
||||
)
|
||||
|
||||
// GetLastSeenASes returns two ASes of the asns table, with their handles,
|
||||
// descriptions and seen times: the one last seen most recently, and the one
|
||||
// last seen longest ago. Both are nil when the table holds no AS.
|
||||
func (d *Database) GetLastSeenASes(ctx context.Context) (*ASN, *ASN, error) {
|
||||
newest, found, err := d.readOneAS(ctx, newestLastSeenASQuery)
|
||||
if err != nil || !found {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
oldest, _, err := d.readOneAS(ctx, oldestLastSeenASQuery)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return newest, oldest, nil
|
||||
}
|
||||
|
||||
// asWHOISQuery reads the handle, description and WHOIS details of one AS, and
|
||||
// when the WHOIS details were fetched.
|
||||
const asWHOISQuery = `
|
||||
@@ -1379,6 +1407,29 @@ func (d *Database) Ping(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// readOneAS returns the AS that query reads, and whether it read one.
|
||||
func (d *Database) readOneAS(ctx context.Context, query string) (*ASN, bool, error) {
|
||||
var (
|
||||
asnInfo ASN
|
||||
handle, description sql.NullString
|
||||
)
|
||||
|
||||
err := d.db.QueryRowContext(ctx, query).Scan(&asnInfo.ASN, &handle,
|
||||
&description, &asnInfo.FirstSeen, &asnInfo.LastSeen)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("failed to query AS by last seen: %w", err)
|
||||
}
|
||||
|
||||
asnInfo.Handle = handle.String
|
||||
asnInfo.Description = description.String
|
||||
|
||||
return &asnInfo, true, nil
|
||||
}
|
||||
|
||||
// truncateWAL runs the TRUNCATE checkpoint of Checkpoint on a WAL file of
|
||||
// walBytes, with the writing connection's busy timeout lowered to
|
||||
// truncateBusyTimeoutMs for it, and logs how long it took. The caller holds the
|
||||
|
||||
Reference in New Issue
Block a user