From 3b3d7b134a64819d60db581f9da63f19da50e910 Mon Sep 17 00:00:00 2001 From: miloschwartz Date: Wed, 18 Jun 2025 15:57:45 -0400 Subject: [PATCH] mark exit node as was previously connected --- .../routers/newt/handleNewtPingRequestMessage.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/routers/newt/handleNewtPingRequestMessage.ts b/server/routers/newt/handleNewtPingRequestMessage.ts index e0cdb83d..d8d9a951 100644 --- a/server/routers/newt/handleNewtPingRequestMessage.ts +++ b/server/routers/newt/handleNewtPingRequestMessage.ts @@ -19,10 +19,21 @@ export const handleNewtPingRequestMessage: MessageHandler = async (context) => { // TODO: pick which nodes to send and ping better than just all of them const exitNodesList = await db.select().from(exitNodes); + let lastExitNodeId = null; + if (newt.siteId) { + const [lastExitNode] = await db + .select() + .from(sites) + .where(eq(sites.siteId, newt.siteId)) + .limit(1); + lastExitNodeId = lastExitNode?.exitNodeId || null; + } + const exitNodesPayload = await Promise.all( exitNodesList.map(async (node) => { // (MAX_CONNECTIONS - current_connections) / MAX_CONNECTIONS) // higher = more desirable + // like saying, this node has x% of its capacity left let weight = 1; const maxConnections = node.maxConnections; @@ -48,7 +59,8 @@ export const handleNewtPingRequestMessage: MessageHandler = async (context) => { exitNodeId: node.exitNodeId, exitNodeName: node.name, endpoint: node.endpoint, - weight + weight, + wasPreviouslyConnected: node.exitNodeId === lastExitNodeId }; }) );