From 21ce678e5b8a1be75c25224295088d6b36b830c6 Mon Sep 17 00:00:00 2001 From: Owen Date: Fri, 15 Aug 2025 15:52:09 -0700 Subject: [PATCH] Move exit node function --- server/lib/exitNodes/exitNodes.ts | 12 ++++++++++++ server/routers/newt/handleNewtRegisterMessage.ts | 15 ++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/server/lib/exitNodes/exitNodes.ts b/server/lib/exitNodes/exitNodes.ts index f5854e27..f49b9cdb 100644 --- a/server/lib/exitNodes/exitNodes.ts +++ b/server/lib/exitNodes/exitNodes.ts @@ -1,5 +1,6 @@ import { db, exitNodes } from "@server/db"; import logger from "@server/logger"; +import { ExitNodePingResult } from "@server/routers/newt"; import { eq, and, or } from "drizzle-orm"; export async function verifyExitNodeOrgAccess( @@ -41,3 +42,14 @@ export async function listExitNodes(orgId: string, filterOnline = false) { return allExitNodes; } + +export function selectBestExitNode( + pingResults: ExitNodePingResult[] +): ExitNodePingResult | null { + if (!pingResults || pingResults.length === 0) { + logger.warn("No ping results provided"); + return null; + } + + return pingResults[0]; +} diff --git a/server/routers/newt/handleNewtRegisterMessage.ts b/server/routers/newt/handleNewtRegisterMessage.ts index 26aa3477..b274a474 100644 --- a/server/routers/newt/handleNewtRegisterMessage.ts +++ b/server/routers/newt/handleNewtRegisterMessage.ts @@ -9,7 +9,7 @@ import { findNextAvailableCidr, getNextAvailableClientSubnet } from "@server/lib/ip"; -import { verifyExitNodeOrgAccess } from "@server/lib/exitNodes"; +import { selectBestExitNode, verifyExitNodeOrgAccess } from "@server/lib/exitNodes"; export type ExitNodePingResult = { exitNodeId: number; @@ -265,15 +265,4 @@ export const handleNewtRegisterMessage: MessageHandler = async (context) => { broadcast: false, // Send to all clients excludeSender: false // Include sender in broadcast }; -}; - -function selectBestExitNode( - pingResults: ExitNodePingResult[] -): ExitNodePingResult | null { - if (!pingResults || pingResults.length === 0) { - logger.warn("No ping results provided"); - return null; - } - - return pingResults[0]; -} +}; \ No newline at end of file