Show the prefix page's origin names from the prefix query (closes #67)
check / check (push) Waiting to run
check / check (push) Waiting to run
The prefix page looked up each origin AS's details only to show its handle and description, and that lookup reads every live route the AS originates. `GetPrefixDetailsContext` already selected the handle and description and dropped them; it now returns them keyed by AS number, and the page uses them. The origin list now also shows the description after the handle, which it never rendered. The JSON prefix answer is unchanged. The test serves the page from a store whose AS lookup always fails. Model: opus-5-5
This commit was merged in pull request #84.
This commit is contained in:
@@ -1632,16 +1632,17 @@ func (d *Database) GetASPeersContext(ctx context.Context, asn int) ([]ASPeer, er
|
||||
}
|
||||
|
||||
// GetPrefixDetails returns detailed information about a prefix
|
||||
func (d *Database) GetPrefixDetails(prefix string) ([]LiveRoute, error) {
|
||||
func (d *Database) GetPrefixDetails(prefix string) ([]LiveRoute, map[int]ASN, error) {
|
||||
return d.GetPrefixDetailsContext(context.Background(), prefix)
|
||||
}
|
||||
|
||||
// GetPrefixDetailsContext returns detailed information about a prefix with context support
|
||||
func (d *Database) GetPrefixDetailsContext(ctx context.Context, prefix string) ([]LiveRoute, error) {
|
||||
// GetPrefixDetailsContext returns the live routes for a prefix and, keyed by
|
||||
// AS number, the handle and description of each AS that originates it.
|
||||
func (d *Database) GetPrefixDetailsContext(ctx context.Context, prefix string) ([]LiveRoute, map[int]ASN, error) {
|
||||
// Determine if it's IPv4 or IPv6 by parsing the prefix
|
||||
_, ipnet, err := net.ParseCIDR(prefix)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid prefix format: %w", err)
|
||||
return nil, nil, fmt.Errorf("invalid prefix format: %w", err)
|
||||
}
|
||||
|
||||
tableName := "live_routes_v4"
|
||||
@@ -1663,11 +1664,12 @@ func (d *Database) GetPrefixDetailsContext(ctx context.Context, prefix string) (
|
||||
|
||||
rows, err := d.db.QueryContext(ctx, query, prefix)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to query prefix details: %w", err)
|
||||
return nil, nil, fmt.Errorf("failed to query prefix details: %w", err)
|
||||
}
|
||||
defer func() { _ = rows.Close() }()
|
||||
|
||||
var routes []LiveRoute
|
||||
origins := make(map[int]ASN)
|
||||
for rows.Next() {
|
||||
var route LiveRoute
|
||||
var pathJSON string
|
||||
@@ -1690,13 +1692,18 @@ func (d *Database) GetPrefixDetailsContext(ctx context.Context, prefix string) (
|
||||
route.IPVersion = ipVersion
|
||||
route.MaskLength, _ = ipnet.Mask.Size()
|
||||
routes = append(routes, route)
|
||||
origins[route.OriginASN] = ASN{
|
||||
ASN: route.OriginASN,
|
||||
Handle: handle.String,
|
||||
Description: description.String,
|
||||
}
|
||||
}
|
||||
|
||||
if len(routes) == 0 {
|
||||
return nil, fmt.Errorf("%w: %s", ErrNoRoute, prefix)
|
||||
return nil, nil, fmt.Errorf("%w: %s", ErrNoRoute, prefix)
|
||||
}
|
||||
|
||||
return routes, nil
|
||||
return routes, origins, nil
|
||||
}
|
||||
|
||||
// GetRandomPrefixesByLength returns a random sample of prefixes with the specified mask length
|
||||
|
||||
Reference in New Issue
Block a user