diff --git a/db/store.go b/db/store.go index 88500f4..2a6c22f 100644 --- a/db/store.go +++ b/db/store.go @@ -26,8 +26,6 @@ func New(pool *pgxpool.Pool) *Store { return &Store{q: sqlc.New(pool)} } -// ResolvePathHashes returns a map of hex-encoded path hash → matching node entries for -// the given IATA. Hash size is inferred from the length of the first element in hashes. func (s *Store) ResolvePathHashes(ctx context.Context, iata string, hashes [][]byte) (map[string][]api.ResolvedPathEntry, error) { if len(hashes) == 0 { return nil, nil @@ -99,8 +97,9 @@ func toChannelMessage(id int64, packetHashHex string, channelHash []byte, sender // Returns nil if the payload cannot be parsed or contains no path hashes. func (s *Store) resolveTraceRoute(ctx context.Context, parsedPayload []byte, iatas []string) []api.ResolvedHop { var tracePayload struct { - PathHashes []string `json:"pathHashes"` - Flags byte `json:"flags"` + PathHashes []string `json:"pathHashes"` + Flags byte `json:"flags"` + SNRValues []float32 `json:"snrValues"` } if err := json.Unmarshal(parsedPayload, &tracePayload); err != nil || len(tracePayload.PathHashes) == 0 { return nil @@ -145,11 +144,15 @@ func (s *Store) resolveTraceRoute(ctx context.Context, parsedPayload []byte, iat } } route := make([]api.ResolvedHop, 0, len(hashes)) - for _, hr := range merged { + for i, hr := range merged { hop := api.ResolvedHop{ Confidence: hr.confidence, Nodes: make([]api.ResolvedNode, 0, len(hr.entries)), } + if i < len(tracePayload.SNRValues) { + snr := tracePayload.SNRValues[i] + hop.SNR = &snr + } for _, e := range hr.entries { hop.Nodes = append(hop.Nodes, api.ResolvedNode{ ID: e.NodeID, diff --git a/internal/api/packets.go b/internal/api/packets.go index ae5b076..eada9da 100644 --- a/internal/api/packets.go +++ b/internal/api/packets.go @@ -68,7 +68,8 @@ type PacketRadio struct { // Confidence is "high" (exactly one match), "ambiguous" (multiple matches), or "none" (no match). type ResolvedHop struct { Confidence string `json:"confidence"` // "high", "ambiguous", or "none" - Nodes []ResolvedNode `json:"nodes"` // empty for "none", one for "high", multiple for "ambiguous" + SNR *float32 `json:"snr,omitempty"` + Nodes []ResolvedNode `json:"nodes"` // empty for "none", one for "high", multiple for "ambiguous" } // ResolvedNode is a node reference within a resolved path hop.