fix: anchor hop disambiguation from sender origin, not just observer

resolve-hops now accepts originLat/originLon params. Forward pass
starts from sender position so first ambiguous hop resolves to the
nearest node to the sender, not the observer.
This commit is contained in:
you
2026-03-21 02:19:20 +00:00
parent 8726026486
commit 75a1b8fc98
3 changed files with 12 additions and 3 deletions
+1 -1
View File
@@ -82,7 +82,7 @@
<script src="roles.js?v=1774080000"></script>
<script src="app.js?v=1774052279"></script>
<script src="home.js?v=1774042199"></script>
<script src="packets.js?v=1774057771"></script>
<script src="packets.js?v=1774059560"></script>
<script src="map.js?v=1774055877" onerror="console.error('Failed to load:', this.src)"></script>
<script src="channels.js?v=1774050030" onerror="console.error('Failed to load:', this.src)"></script>
<script src="nodes.js?v=1774050030" onerror="console.error('Failed to load:', this.src)"></script>
+5 -1
View File
@@ -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 => {
+6 -1
View File
@@ -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]) {