From 2fe21cab247a41cee50aaa8da4a3f5ab451e7d3a Mon Sep 17 00:00:00 2001 From: you Date: Thu, 19 Mar 2026 08:26:37 +0000 Subject: [PATCH] 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 --- public/packets.js | 3 ++- server.js | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/public/packets.js b/public/packets.js index ea9da8e6..9bd691b5 100644 --- a/public/packets.js +++ b/public/packets.js @@ -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 diff --git a/server.js b/server.js index 9e01e1ac..15b9b465 100644 --- a/server.js +++ b/server.js @@ -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;