mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-10-22 10:12:25 +00:00
feat(topology): serve bounded route links and identify decoded Public traffic
This commit is contained in:
1 parent
53f2467864
commit
84ac3c8781
19 files changed
+486
No files matched your search
@@ -1137,6 +1137,21 @@ func (mr *MockQuerierMockRecorder) GetTopNodes(ctx, arg any) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTopNodes", reflect.TypeOf((*MockQuerier)(nil).GetTopNodes), ctx, arg)
|
||||
}
|
||||
|
||||
// GetTopologyLinks mocks base method.
|
||||
func (m *MockQuerier) GetTopologyLinks(ctx context.Context, arg db.GetTopologyLinksParams) ([]db.GetTopologyLinksRow, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetTopologyLinks", ctx, arg)
|
||||
ret0, _ := ret[0].([]db.GetTopologyLinksRow)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetTopologyLinks indicates an expected call of GetTopologyLinks.
|
||||
func (mr *MockQuerierMockRecorder) GetTopologyLinks(ctx, arg any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTopologyLinks", reflect.TypeOf((*MockQuerier)(nil).GetTopologyLinks), ctx, arg)
|
||||
}
|
||||
|
||||
// GetTransportScopeByName mocks base method.
|
||||
func (m *MockQuerier) GetTransportScopeByName(ctx context.Context, name string) (int32, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
@@ -156,6 +156,8 @@ type Querier interface {
|
||||
// Nodes by ADVERT hearings since the given hour. Live names win over the rolled snapshot;
|
||||
// node_id is NULL once the node row is gone. iata is a representative one.
|
||||
GetTopNodes(ctx context.Context, arg GetTopNodesParams) ([]GetTopNodesRow, error)
|
||||
// Reduce route history to unique adjacent pairs before transferring it to a browser.
|
||||
GetTopologyLinks(ctx context.Context, arg GetTopologyLinksParams) ([]GetTopologyLinksRow, error)
|
||||
GetTransportScopeByName(ctx context.Context, name string) (int32, error)
|
||||
GetTransportScopes(ctx context.Context) ([]GetTransportScopesRow, error)
|
||||
// ============================================================
|
||||
|
||||
@@ -2237,6 +2237,59 @@ func (q *Queries) GetTopNodes(ctx context.Context, arg GetTopNodesParams) ([]Get
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getTopologyLinks = `-- name: GetTopologyLinks :many
|
||||
WITH pairs AS (
|
||||
SELECT h.node_id AS a, r.node_ids[(h.ord+1)::int] AS b
|
||||
FROM known_routes r CROSS JOIN LATERAL unnest(r.node_ids) WITH ORDINALITY h(node_id,ord)
|
||||
WHERE r.last_seen >= $2::timestamptz AND r.last_seen < $3::timestamptz
|
||||
AND (COALESCE(cardinality($4::bpchar[]),0)=0 OR r.iata=ANY($4::bpchar[]))
|
||||
AND h.ord < cardinality(r.node_ids)
|
||||
)
|
||||
SELECT LEAST(a,b)::uuid AS from_id, GREATEST(a,b)::uuid AS to_id
|
||||
FROM pairs WHERE a IS NOT NULL AND b IS NOT NULL AND a<>b
|
||||
GROUP BY LEAST(a,b), GREATEST(a,b)
|
||||
ORDER BY LEAST(a,b), GREATEST(a,b)
|
||||
LIMIT $1::int
|
||||
`
|
||||
|
||||
type GetTopologyLinksParams struct {
|
||||
LinkLimit int32 `json:"link_limit"`
|
||||
Since pgtype.Timestamptz `json:"since"`
|
||||
Until pgtype.Timestamptz `json:"until"`
|
||||
Iatas []string `json:"iatas"`
|
||||
}
|
||||
|
||||
type GetTopologyLinksRow struct {
|
||||
FromID uuid.UUID `json:"from_id"`
|
||||
ToID uuid.UUID `json:"to_id"`
|
||||
}
|
||||
|
||||
// Reduce route history to unique adjacent pairs before transferring it to a browser.
|
||||
func (q *Queries) GetTopologyLinks(ctx context.Context, arg GetTopologyLinksParams) ([]GetTopologyLinksRow, error) {
|
||||
rows, err := q.db.Query(ctx, getTopologyLinks,
|
||||
arg.LinkLimit,
|
||||
arg.Since,
|
||||
arg.Until,
|
||||
arg.Iatas,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []GetTopologyLinksRow{}
|
||||
for rows.Next() {
|
||||
var i GetTopologyLinksRow
|
||||
if err := rows.Scan(&i.FromID, &i.ToID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getTransportScopeByName = `-- name: GetTransportScopeByName :one
|
||||
SELECT id FROM transport_scopes WHERE name = $1
|
||||
`
|
||||
|
||||
Reference in new issue
Block a user