Fix observer location for hop disambiguation

- ADVERT is payload_type 4 not 1
- Frontend sends observer_id (not just observer_name) since some
  observers have null name
- Observer position derived from geographic center of nodes it
  commonly receives ADVERTs from
- Last hop in path disambiguated by proximity to observer position
This commit is contained in:
you
2026-03-19 08:26:37 +00:00
parent 4449b07e54
commit 2fe21cab24
2 changed files with 12 additions and 7 deletions
+2 -1
View File
@@ -505,7 +505,8 @@
if (routeBtn && pathHops.length) {
routeBtn.addEventListener('click', async () => {
try {
const observerParam = pkt.observer_name ? '&observer=' + encodeURIComponent(pkt.observer_name) : '';
const obsId = pkt.observer_name || pkt.observer_id || '';
const observerParam = obsId ? '&observer=' + encodeURIComponent(obsId) : '';
const resp = await fetch('/api/resolve-hops?hops=' + encodeURIComponent(pathHops.join(',')) + observerParam);
const data = await resp.json();
// Pass full pubkeys (server-disambiguated) to map, falling back to short prefix
+10 -6
View File
@@ -912,13 +912,17 @@ app.get('/api/resolve-hops', (req, res) => {
observerLat = obsNode.lat;
observerLon = obsNode.lon;
} else {
// Fall back to averaging nodes it typically hears
// Fall back to averaging nearby nodes from adverts this observer received
const obsNodes = db.db.prepare(`
SELECT DISTINCT n.lat, n.lon FROM packets p
JOIN nodes n ON p.decoded_json LIKE '%' || n.public_key || '%'
WHERE p.observer_id = ? AND n.lat IS NOT NULL AND n.lat != 0 AND n.lon != 0
LIMIT 50
`).all(observerId);
SELECT n.lat, n.lon FROM packets p
JOIN nodes n ON n.public_key = json_extract(p.decoded_json, '$.pubKey')
WHERE (p.observer_id = ? OR p.observer_name = ?)
AND p.payload_type = 4
AND n.lat IS NOT NULL AND n.lat != 0 AND n.lon != 0
GROUP BY n.public_key
ORDER BY COUNT(*) DESC
LIMIT 20
`).all(observerId, observerId);
if (obsNodes.length) {
observerLat = obsNodes.reduce((s, n) => s + n.lat, 0) / obsNodes.length;
observerLon = obsNodes.reduce((s, n) => s + n.lon, 0) / obsNodes.length;