update selection algorithm

This commit is contained in:
miloschwartz 2025-06-22 17:19:32 -04:00
parent f3b44a3085
commit d45443258b
No known key found for this signature in database
4 changed files with 117 additions and 85 deletions

View file

@ -3,7 +3,7 @@ import { MessageHandler } from "../ws";
import { exitNodes, Newt } from "@server/db";
import logger from "@server/logger";
import config from "@server/lib/config";
import { ne, eq, and, count } from "drizzle-orm";
import { ne, eq, or, and, count } from "drizzle-orm";
export const handleNewtPingRequestMessage: MessageHandler = async (context) => {
const { message, client, sendToClient } = context;
@ -17,10 +17,11 @@ export const handleNewtPingRequestMessage: MessageHandler = async (context) => {
}
// TODO: pick which nodes to send and ping better than just all of them
const exitNodesList = await db
let exitNodesList = await db
.select()
.from(exitNodes)
.where(ne(exitNodes.maxConnections, 0));
.from(exitNodes);
exitNodesList = exitNodesList.filter((node) => node.maxConnections !== 0);
let lastExitNodeId = null;
if (newt.siteId) {