Seperate config gen into functions

This commit is contained in:
Owen
2025-12-20 11:41:23 -05:00
parent 322f3bfb1d
commit 75b9703793
9 changed files with 295 additions and 83 deletions

View File

@@ -5,7 +5,8 @@ import {
handleDockerStatusMessage,
handleDockerContainersMessage,
handleNewtPingRequestMessage,
handleApplyBlueprintMessage
handleApplyBlueprintMessage,
handleNewtPingMessage
} from "../newt";
import {
handleOlmRegisterMessage,
@@ -24,6 +25,7 @@ export const messageHandlers: Record<string, MessageHandler> = {
"olm/wg/relay": handleOlmRelayMessage,
"olm/wg/unrelay": handleOlmUnRelayMessage,
"olm/ping": handleOlmPingMessage,
"newt/ping": handleNewtPingMessage,
"newt/wg/register": handleNewtRegisterMessage,
"newt/wg/get-config": handleGetConfigMessage,
"newt/receive-bandwidth": handleReceiveBandwidthMessage,

View File

@@ -52,7 +52,11 @@ export interface HandlerContext {
senderWs: WebSocket;
client: Newt | Olm | RemoteExitNode | undefined;
clientType: ClientType;
sendToClient: (clientId: string, message: WSMessage, options?: SendMessageOptions) => Promise<boolean>;
sendToClient: (
clientId: string,
message: WSMessage,
options?: SendMessageOptions
) => Promise<boolean>;
broadcastToAllExcept: (
message: WSMessage,
excludeClientId?: string,

View File

@@ -95,7 +95,7 @@ const sendToClientLocal = async (
if (!clients || clients.length === 0) {
return false;
}
// Increment config version if requested
if (options.incrementConfigVersion) {
const currentVersion = clientConfigVersions.get(clientId) || 0;
@@ -106,14 +106,14 @@ const sendToClientLocal = async (
client.configVersion = newVersion;
});
}
// Include config version in message
const configVersion = clientConfigVersions.get(clientId) || 0;
const messageWithVersion = {
...message,
configVersion
};
const messageString = JSON.stringify(messageWithVersion);
clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) {
@@ -189,7 +189,7 @@ const hasActiveConnections = async (clientId: string): Promise<boolean> => {
};
// Get the current config version for a client
const getClientConfigVersion = (clientId: string): number => {
const getClientConfigVersion = async (clientId: string): Promise<number> => {
return clientConfigVersions.get(clientId) || 0;
};