From 977666bc3c8cd9dfdc97549caed763e292a8a53a Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 16 Nov 2024 11:35:39 -0800 Subject: [PATCH] server: add worker ids --- server/.vscode/launch.json | 2 +- server/src/scrypted-cluster-main.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/server/.vscode/launch.json b/server/.vscode/launch.json index 8ff32a128..fbf7c5f97 100644 --- a/server/.vscode/launch.json +++ b/server/.vscode/launch.json @@ -96,7 +96,7 @@ "env": { "SCRYPTED_CLUSTER_LABELS": "compute", "SCRYPTED_CLUSTER_MODE": "client", - "SCRYPTED_CLUSTER_SERVER": "192.168.2.124", + "SCRYPTED_CLUSTER_SERVER": "scrypted-nvr", "SCRYPTED_CLUSTER_SECRET": "swordfish", "SCRYPTED_CAN_RESTART": "true", "SCRYPTED_VOLUME": "/Users/koush/.scrypted-cluster/volume-client", diff --git a/server/src/scrypted-cluster-main.ts b/server/src/scrypted-cluster-main.ts index 4d33781f0..61f2b4146 100644 --- a/server/src/scrypted-cluster-main.ts +++ b/server/src/scrypted-cluster-main.ts @@ -1,3 +1,4 @@ +import os from 'os'; import type { ForkOptions } from '@scrypted/types'; import { once } from 'events'; import net from 'net'; @@ -155,7 +156,7 @@ export function startClusterClient(mainFilename: string) { const auth: ClusterObject = { address: socket.localAddress, port: socket.localPort, - id: undefined, + id: process.env.SCRYPTED_CLUSTER_ID || os.hostname(), proxyId: undefined, sourceKey: undefined, sha256: undefined, @@ -285,6 +286,9 @@ export function createClusterServer(runtime: ScryptedRuntime, certificate: Retur const sha256 = computeClusterObjectHash(auth, runtime.clusterSecret); if (sha256 !== auth.sha256) throw new Error('cluster object hash mismatch'); + + peer.peerName = auth.id || `${socket.remoteAddress}`; + // the remote address may be ipv6 prefixed so use a fuzzy match. // eg ::ffff:192.168.2.124 if (!process.env.SCRYPTED_DISABLE_CLUSTER_SERVER_TRUST) {