Discovery: wide-area bridge DNS-SD

# Conflicts:
#	apps/ios/Sources/Bridge/BridgeDiscoveryModel.swift
#	src/cli/dns-cli.ts
This commit is contained in:
Peter Steinberger
2025-12-17 20:25:40 +01:00
parent e9bfe34850
commit 557ffdbe35
24 changed files with 293 additions and 19 deletions

View File

@@ -225,6 +225,8 @@ describe("node bridge server", () => {
displayName?: string;
platform?: string;
version?: string;
deviceFamily?: string;
modelIdentifier?: string;
remoteIp?: string;
} | null = null;
@@ -233,6 +235,8 @@ describe("node bridge server", () => {
displayName?: string;
platform?: string;
version?: string;
deviceFamily?: string;
modelIdentifier?: string;
remoteIp?: string;
} | null = null;
@@ -262,6 +266,8 @@ describe("node bridge server", () => {
displayName: "Iris",
platform: "ios",
version: "1.0",
deviceFamily: "iPad",
modelIdentifier: "iPad16,6",
});
// Approve the pending request from the gateway side.
@@ -296,6 +302,8 @@ describe("node bridge server", () => {
displayName: "Different name",
platform: "ios",
version: "2.0",
deviceFamily: "iPad",
modelIdentifier: "iPad99,1",
});
const line3 = JSON.parse(await readLine2()) as { type: string };
expect(line3.type).toBe("hello-ok");
@@ -310,6 +318,8 @@ describe("node bridge server", () => {
expect(lastAuthed?.displayName).toBe("Iris");
expect(lastAuthed?.platform).toBe("ios");
expect(lastAuthed?.version).toBe("1.0");
expect(lastAuthed?.deviceFamily).toBe("iPad");
expect(lastAuthed?.modelIdentifier).toBe("iPad16,6");
expect(lastAuthed?.remoteIp?.includes("127.0.0.1")).toBe(true);
socket2.destroy();

View File

@@ -17,6 +17,8 @@ type BridgeHelloFrame = {
token?: string;
platform?: string;
version?: string;
deviceFamily?: string;
modelIdentifier?: string;
};
type BridgePairRequestFrame = {
@@ -25,6 +27,8 @@ type BridgePairRequestFrame = {
displayName?: string;
platform?: string;
version?: string;
deviceFamily?: string;
modelIdentifier?: string;
remoteAddress?: string;
};
@@ -108,6 +112,8 @@ export type NodeBridgeClientInfo = {
displayName?: string;
platform?: string;
version?: string;
deviceFamily?: string;
modelIdentifier?: string;
remoteIp?: string;
};
@@ -263,6 +269,8 @@ export async function startNodeBridgeServer(
displayName: verified.node.displayName ?? hello.displayName,
platform: verified.node.platform ?? hello.platform,
version: verified.node.version ?? hello.version,
deviceFamily: verified.node.deviceFamily ?? hello.deviceFamily,
modelIdentifier: verified.node.modelIdentifier ?? hello.modelIdentifier,
remoteIp: remoteAddress,
};
connections.set(nodeId, { socket, nodeInfo, invokeWaiters });
@@ -319,6 +327,8 @@ export async function startNodeBridgeServer(
displayName: req.displayName,
platform: req.platform,
version: req.version,
deviceFamily: req.deviceFamily,
modelIdentifier: req.modelIdentifier,
remoteIp: remoteAddress,
},
opts.pairingBaseDir,
@@ -347,6 +357,8 @@ export async function startNodeBridgeServer(
displayName: req.displayName,
platform: req.platform,
version: req.version,
deviceFamily: req.deviceFamily,
modelIdentifier: req.modelIdentifier,
remoteIp: remoteAddress,
};
connections.set(nodeId, { socket, nodeInfo, invokeWaiters });

View File

@@ -9,6 +9,8 @@ export type NodePairingPendingRequest = {
displayName?: string;
platform?: string;
version?: string;
deviceFamily?: string;
modelIdentifier?: string;
remoteIp?: string;
isRepair?: boolean;
ts: number;
@@ -20,6 +22,8 @@ export type NodePairingPairedNode = {
displayName?: string;
platform?: string;
version?: string;
deviceFamily?: string;
modelIdentifier?: string;
remoteIp?: string;
createdAtMs: number;
approvedAtMs: number;
@@ -172,6 +176,8 @@ export async function requestNodePairing(
displayName: req.displayName,
platform: req.platform,
version: req.version,
deviceFamily: req.deviceFamily,
modelIdentifier: req.modelIdentifier,
remoteIp: req.remoteIp,
isRepair,
ts: Date.now(),
@@ -199,6 +205,8 @@ export async function approveNodePairing(
displayName: pending.displayName,
platform: pending.platform,
version: pending.version,
deviceFamily: pending.deviceFamily,
modelIdentifier: pending.modelIdentifier,
remoteIp: pending.remoteIp,
createdAtMs: existing?.createdAtMs ?? now,
approvedAtMs: now,

View File

@@ -5,6 +5,8 @@ export type SystemPresence = {
ip?: string;
version?: string;
platform?: string;
deviceFamily?: string;
modelIdentifier?: string;
lastInputSeconds?: number;
mode?: string;
reason?: string;
@@ -54,12 +56,20 @@ function initSelfPresence() {
if (p === "win32") return `windows ${rel}`;
return `${p} ${rel}`;
})();
const deviceFamily = (() => {
const p = os.platform();
if (p === "darwin") return "Mac";
if (p === "win32") return "Windows";
if (p === "linux") return "Linux";
return p;
})();
const text = `Gateway: ${host}${ip ? ` (${ip})` : ""} · app ${version} · mode gateway · reason self`;
const selfEntry: SystemPresence = {
host,
ip,
version,
platform,
deviceFamily,
mode: "gateway",
reason: "self",
text,
@@ -123,6 +133,8 @@ type SystemPresencePayload = {
ip?: string;
version?: string;
platform?: string;
deviceFamily?: string;
modelIdentifier?: string;
lastInputSeconds?: number;
mode?: string;
reason?: string;
@@ -147,6 +159,8 @@ export function updateSystemPresence(payload: SystemPresencePayload) {
ip: payload.ip ?? parsed.ip ?? existing.ip,
version: payload.version ?? parsed.version ?? existing.version,
platform: payload.platform ?? existing.platform,
deviceFamily: payload.deviceFamily ?? existing.deviceFamily,
modelIdentifier: payload.modelIdentifier ?? existing.modelIdentifier,
mode: payload.mode ?? parsed.mode ?? existing.mode,
lastInputSeconds:
payload.lastInputSeconds ??