fix(federation): persist remote instance_name when ensurePeered/performHandshake succeeds

Initiator side of the bidirectional handshake exchange. /peer/accept now returns instanceName in the response body (prior commit); performHandshake parses it and persists alongside status='active'. Tolerates missing field (older peers) and non-JSON bodies.
This commit is contained in:
Jannis Braun
2026-04-25 00:45:06 +02:00
parent eba16e16a3
commit 18d6b0acfa
2 changed files with 161 additions and 2 deletions
+14 -2
View File
@@ -155,9 +155,21 @@ async function performHandshake(
}
if (response.ok) {
// 200 = peer accepted and activated
// 200 = peer accepted and activated. Parse remote's instanceName from
// the response body so we can render a friendly label for the peer.
// Tolerate omission (older peers) and non-JSON bodies (defensive).
let remoteInstanceName: string | null = null;
try {
const body = (await response.json()) as { instanceName?: string | null };
if (typeof body?.instanceName === 'string' && body.instanceName.length > 0) {
remoteInstanceName = body.instanceName;
}
} catch {
// Non-JSON or empty body — leave remoteInstanceName as null.
}
db.update(schema.federationPeers)
.set({ status: 'active', lastSeenAt: Date.now() })
.set({ status: 'active', lastSeenAt: Date.now(), instanceName: remoteInstanceName })
.where(eq(schema.federationPeers.id, peerId))
.run();
const { connectionManager } = await import('../ws/handler.js');