diff --git a/public/index.html b/public/index.html index 14dc43fc..c66ee34f 100644 --- a/public/index.html +++ b/public/index.html @@ -82,7 +82,7 @@ - + diff --git a/public/packets.js b/public/packets.js index 92c365f4..a3db8769 100644 --- a/public/packets.js +++ b/public/packets.js @@ -927,7 +927,11 @@ try { const obsId = obsName(pkt.observer_id); const observerParam = obsId ? '&observer=' + encodeURIComponent(obsId) : ''; - const resp = await fetch('/api/resolve-hops?hops=' + encodeURIComponent(pathHops.join(',')) + observerParam); + // Anchor disambiguation from sender's location if known (e.g. ADVERT lat/lon) + const senderLat = decoded.lat || decoded.latitude; + const senderLon = decoded.lon || decoded.longitude; + const originParam = (senderLat != null && senderLon != null) ? `&originLat=${senderLat}&originLon=${senderLon}` : ''; + const resp = await fetch('/api/resolve-hops?hops=' + encodeURIComponent(pathHops.join(',')) + observerParam + originParam); const data = await resp.json(); // Pass full pubkeys (server-disambiguated) to map, falling back to short prefix const resolvedKeys = pathHops.map(h => { diff --git a/server.js b/server.js index e60daf41..ec723971 100644 --- a/server.js +++ b/server.js @@ -1559,6 +1559,11 @@ app.get('/api/analytics/hash-sizes', (req, res) => { app.get('/api/resolve-hops', (req, res) => { const hops = (req.query.hops || '').split(',').filter(Boolean); const observerId = req.query.observer || null; + // Origin anchor: sender's lat/lon for forward-pass disambiguation. + // Without this, the first ambiguous hop falls through to the backward pass + // which anchors from the observer — wrong when sender and observer are far apart. + const originLat = req.query.originLat ? parseFloat(req.query.originLat) : null; + const originLon = req.query.originLon ? parseFloat(req.query.originLon) : null; if (!hops.length) return res.json({ resolved: {} }); const allNodes = db.db.prepare('SELECT public_key, name, lat, lon FROM nodes WHERE name IS NOT NULL').all(); @@ -1623,7 +1628,7 @@ app.get('/api/resolve-hops', (req, res) => { const dist = (lat1, lon1, lat2, lon2) => Math.sqrt((lat1 - lat2) ** 2 + (lon1 - lon2) ** 2); // Forward pass: resolve each ambiguous hop using previous hop's position - let lastPos = null; + let lastPos = (originLat != null && originLon != null) ? { lat: originLat, lon: originLon } : null; for (let hi = 0; hi < hops.length; hi++) { const hop = hops[hi]; if (hopPositions[hop]) {