7c09d257bea1

fix: mDNS peer discovery — look up device in registry and update lastKnownIp before firing TRIGGER_SYNC (v3.6.100)

time
2026-05-22 18:33 UTC · 5 months ago
machine
koh2
parent
c49affb655fc
2 files src/background/messages.ts+19 −0src/popup/chirp-pair-capacitor.ts+9 −1
src/background/messages.ts+19 −0
@@ -1081,8 +1081,27 @@10811081         const payload = (msg.payload ?? {}) as {10821082           reason?: "vault_change" | "foreground" | "manual" | "mdns";10831083           force?: boolean;1084+          deviceId?: string;1085+          discoveredIp?: string;1086+          discoveredPort?: number;10841087         };10851088         const reason = payload.reason ?? "foreground";1089+1090+        // mDNS discovery delivers a fresh (ip, port) resolved by the native1091+        // side. Update the cached address before the sync runner tries to1092+        // connect — avoids a subnet probe on the very next round.1093+        if (1094+          reason === "mdns" &&1095+          typeof payload.deviceId === "string" &&1096+          typeof payload.discoveredIp === "string"1097+        ) {1098+          const { findPairedDeviceById, setLastKnownIp } = await import("./paired-devices");1099+          const device = await findPairedDeviceById(payload.deviceId);1100+          if (device?.longTermPublicKeyHex) {1101+            await setLastKnownIp(device.longTermPublicKeyHex, payload.discoveredIp).catch(() => undefined);1102+          }1103+        }1104+10861105         const { triggerSyncIfReachable } = await import("./sync-trigger");10871106         void triggerSyncIfReachable({ reason, force: payload.force === true });10881107         return { ok: true };

view file

src/popup/chirp-pair-capacitor.ts+9 −1
@@ -159,9 +159,17 @@159159   if (!appActive) return;160160 161161   try {162+    // Pass the resolved address so the background can update lastKnownIp163+    // before attempting the session — saves the runner from a stale-IP164+    // probe on the very next sync round.162165     await chrome.runtime.sendMessage({163166       type: "TRIGGER_SYNC",164-      payload: { reason: "mdns" },167+      payload: {168+        reason: "mdns",169+        deviceId: event.deviceId,170+        discoveredIp: event.ip,171+        discoveredPort: typeof event.port === "number" ? event.port : undefined,172+      },165173     });166174   } catch {167175     // Background may not be listening — non-fatal; next vault-change or

view file