Files
beacon-server/internal/api/routes.go
T
MrAlders0n 9bbf8efee5 release: v2.0.4 (#217)
* perf(routes): batch cross-IATA and hash route search (#216)

One search fired a /routes/cross request per IATA pair (138k on 2026-10-08). Route search now takes an optional iatas list and runs a fixed number of index-backed queries. /info advertises built-in minimum client versions.

* chore: bump version to 2.0.4
2026-10-09 22:17:23 -04:00

60 lines
2.2 KiB
Go

// Copyright 2026 Beacon Contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
package api
import (
"errors"
"github.com/google/uuid"
)
// ErrRouteSearchTooBroad means an endpoint hash matches too widely to search.
var ErrRouteSearchTooBroad = errors.New("hash matches too many areas; use a longer hash or fewer iatas")
// CrossRouteSearch finds routes from FromHash (resolved in FromIATAs) to ToHash
// (resolved in ToIATAs) that cross between two different IATAs. Empty lists mean every IATA.
type CrossRouteSearch struct {
FromHash string
ToHash string
FromIATAs []string
ToIATAs []string
}
// RouteHop is a single resolved hop in a known route.
type RouteHop struct {
NodeID uuid.UUID `json:"nodeId"`
HashBytes string `json:"hashBytes"` // hex-encoded hash prefix
Node *ResolvedNode `json:"node,omitempty"` // populated when node details are available
}
// KnownRoute is a fully resolved path through the mesh where all hops
// have been confirmed as high confidence.
type KnownRoute struct {
ID int64 `json:"id"`
PathKey string `json:"pathKey,omitempty"` // stable identity within this IATA; use for route evidence links
IATA string `json:"iata"`
HopCount int32 `json:"hopCount"`
Hops []RouteHop `json:"hops"`
FirstSeen int64 `json:"firstSeen"` // epoch ms
LastSeen int64 `json:"lastSeen"` // epoch ms
ObservationCount int64 `json:"observationCount"`
}
// CrossIATAHop represents the boundary hop between two IATAs in a cross-IATA route.
type CrossIATAHop struct {
FromNode ResolvedNode `json:"fromNode"` // last node in source IATA
ToNode ResolvedNode `json:"toNode"` // first node in target IATA
FromIATA string `json:"fromIata"`
ToIATA string `json:"toIata"`
LastSeen int64 `json:"lastSeen"` // epoch ms
}
// CrossIATARoute is a route that crosses IATA boundaries.
type CrossIATARoute struct {
SourceSegment []RouteHop `json:"sourceSegment"` // route segment in source IATA
CrossHop CrossIATAHop `json:"crossHop"` // the boundary hop
TargetSegment []RouteHop `json:"targetSegment"` // route segment in target IATA
TotalHops int `json:"totalHops"`
}