diff --git a/server/lib/offlineThresholds.ts b/server/lib/offlineThresholds.ts index e3c2d369a..abcfd6993 100644 --- a/server/lib/offlineThresholds.ts +++ b/server/lib/offlineThresholds.ts @@ -1,3 +1,5 @@ +import config from "@server/lib/config"; + export type OfflineThresholds = { // how often the offline checkers run checkIntervalMs: number; @@ -19,8 +21,14 @@ export const DEFAULT_OFFLINE_THRESHOLDS: OfflineThresholds = { remoteExitNodeMs: 2 * 60 * 1000 // 2 minutes }; -// The thresholds are only configurable in the private config file, so the -// open build always uses the defaults. See server/private/lib/offlineThresholds.ts export function getOfflineThresholds(): OfflineThresholds { - return DEFAULT_OFFLINE_THRESHOLDS; + const offlineChecker = config.getRawConfig().offline_checker; + + return { + checkIntervalMs: offlineChecker.check_interval_ms, + newtMs: offlineChecker.newt_threshold_ms, + newtWireguardMs: offlineChecker.newt_wireguard_threshold_ms, + olmMs: offlineChecker.olm_threshold_ms, + remoteExitNodeMs: offlineChecker.remote_exit_node_threshold_ms + }; } diff --git a/server/lib/readConfigFile.ts b/server/lib/readConfigFile.ts index 0d8786f89..8ec49b038 100644 --- a/server/lib/readConfigFile.ts +++ b/server/lib/readConfigFile.ts @@ -4,6 +4,7 @@ import { configFilePath1, configFilePath2 } from "./consts"; import { z } from "zod"; import stoi from "./stoi"; import { getEnvOrYaml, readEnvOrFile } from "./getEnvOrYaml"; +import { DEFAULT_OFFLINE_THRESHOLDS } from "@server/lib/offlineThresholds"; const portSchema = z.number().positive().gt(0).lte(65535); @@ -456,6 +457,36 @@ export const configSchema = z }) .prefault({}) }) + .prefault({}), + // How long a newt site / olm client / remote exit node has to go + // without a ping before the offline checker marks it offline, and how + // often the checkers run. + offline_checker: z + .object({ + check_interval_ms: z + .number() + .int() + .positive() + .default(DEFAULT_OFFLINE_THRESHOLDS.checkIntervalMs), + newt_threshold_ms: z + .number() + .int() + .default(DEFAULT_OFFLINE_THRESHOLDS.newtMs), + // wireguard sites don't ping, so they are judged by their + // last bandwidth update instead + newt_wireguard_threshold_ms: z + .number() + .int() + .default(DEFAULT_OFFLINE_THRESHOLDS.newtWireguardMs), + olm_threshold_ms: z + .number() + .int() + .default(DEFAULT_OFFLINE_THRESHOLDS.olmMs), + remote_exit_node_threshold_ms: z + .number() + .int() + .default(DEFAULT_OFFLINE_THRESHOLDS.remoteExitNodeMs) + }) .prefault({}) }) .refine( diff --git a/server/private/lib/offlineThresholds.ts b/server/private/lib/offlineThresholds.ts deleted file mode 100644 index 2f3d392ac..000000000 --- a/server/private/lib/offlineThresholds.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is part of a proprietary work. - * - * Copyright (c) 2025-2026 Fossorial, Inc. - * All rights reserved. - * - * This file is licensed under the Fossorial Commercial License. - * You may not use this file except in compliance with the License. - * Unauthorized use, copying, modification, or distribution is strictly prohibited. - * - * This file is not licensed under the AGPLv3. - */ - -import type { OfflineThresholds } from "@server/lib/offlineThresholds"; -import privateConfig from "#private/lib/config"; - -export function getOfflineThresholds(): OfflineThresholds { - const offlineChecker = privateConfig.getRawPrivateConfig().offline_checker; - - return { - checkIntervalMs: offlineChecker.check_interval_ms, - newtMs: offlineChecker.newt_threshold_ms, - newtWireguardMs: offlineChecker.newt_wireguard_threshold_ms, - olmMs: offlineChecker.olm_threshold_ms, - remoteExitNodeMs: offlineChecker.remote_exit_node_threshold_ms - }; -} diff --git a/server/private/lib/readConfigFile.ts b/server/private/lib/readConfigFile.ts index cd24b053b..a78a16d3b 100644 --- a/server/private/lib/readConfigFile.ts +++ b/server/private/lib/readConfigFile.ts @@ -18,7 +18,6 @@ import { z } from "zod"; import { colorsSchema } from "@server/lib/colorsSchema"; import { build } from "@server/build"; import { getEnvOrYaml } from "@server/lib/getEnvOrYaml"; -import { DEFAULT_OFFLINE_THRESHOLDS } from "@server/lib/offlineThresholds"; const portSchema = z.number().positive().gt(0).lte(65535); @@ -177,36 +176,6 @@ export const privateConfigSchema = z .default("http://gerbil:3004") }) .prefault({}), - // How long a newt site / olm client / remote exit node has to go - // without a ping before the offline checker marks it offline, and how - // often the checkers run. - offline_checker: z - .object({ - check_interval_ms: z - .number() - .int() - .positive() - .default(DEFAULT_OFFLINE_THRESHOLDS.checkIntervalMs), - newt_threshold_ms: z - .number() - .int() - .default(DEFAULT_OFFLINE_THRESHOLDS.newtMs), - // wireguard sites don't ping, so they are judged by their - // last bandwidth update instead - newt_wireguard_threshold_ms: z - .number() - .int() - .default(DEFAULT_OFFLINE_THRESHOLDS.newtWireguardMs), - olm_threshold_ms: z - .number() - .int() - .default(DEFAULT_OFFLINE_THRESHOLDS.olmMs), - remote_exit_node_threshold_ms: z - .number() - .int() - .default(DEFAULT_OFFLINE_THRESHOLDS.remoteExitNodeMs) - }) - .prefault({}), flags: z .object({ enable_redis: z.boolean().optional().default(false), diff --git a/server/private/routers/remoteExitNode/offlineChecker.ts b/server/private/routers/remoteExitNode/offlineChecker.ts index b916102ea..59cc58dbe 100644 --- a/server/private/routers/remoteExitNode/offlineChecker.ts +++ b/server/private/routers/remoteExitNode/offlineChecker.ts @@ -14,7 +14,7 @@ import { db, exitNodes } from "@server/db"; import { eq, lt, isNull, and, or } from "drizzle-orm"; import logger from "@server/logger"; -import { getOfflineThresholds } from "#private/lib/offlineThresholds"; +import { getOfflineThresholds } from "@server/lib/offlineThresholds"; // Track if the offline checker interval is running let offlineCheckerInterval: NodeJS.Timeout | null = null; diff --git a/server/routers/newt/offlineChecker.ts b/server/routers/newt/offlineChecker.ts index 075800747..defa8e829 100644 --- a/server/routers/newt/offlineChecker.ts +++ b/server/routers/newt/offlineChecker.ts @@ -3,7 +3,7 @@ import { hasActiveConnections } from "#dynamic/routers/ws"; import { eq, lt, isNull, and, or, ne, not, inArray } from "drizzle-orm"; import logger from "@server/logger"; import { fireSiteOfflineAlert, fireSiteOnlineAlert } from "@server/lib/alerts"; -import { getOfflineThresholds } from "#dynamic/lib/offlineThresholds"; +import { getOfflineThresholds } from "@server/lib/offlineThresholds"; // Track if the offline checker interval is running let offlineCheckerInterval: NodeJS.Timeout | null = null; diff --git a/server/routers/olm/offlineChecker.ts b/server/routers/olm/offlineChecker.ts index a5558fd24..3b6444faa 100644 --- a/server/routers/olm/offlineChecker.ts +++ b/server/routers/olm/offlineChecker.ts @@ -5,7 +5,7 @@ import { eq, lt, isNull, and, or } from "drizzle-orm"; import logger from "@server/logger"; import { sendTerminateClient } from "../client/terminate"; import { OlmErrorCodes } from "./error"; -import { getOfflineThresholds } from "#dynamic/lib/offlineThresholds"; +import { getOfflineThresholds } from "@server/lib/offlineThresholds"; // Track if the offline checker interval is running let offlineCheckerInterval: NodeJS.Timeout | null = null;