mirror of
https://github.com/fosrl/pangolin.git
synced 2026-10-21 12:09:04 +02:00
Move the offline intervals to the regular config
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
@@ -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),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user