mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-03 01:24:58 +02:00
Dont go over capacity or accept no capacity
This commit is contained in:
parent
494b54ac32
commit
2fd8134a57
1 changed files with 13 additions and 3 deletions
|
@ -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 { eq, and, count } from "drizzle-orm";
|
||||
import { ne, eq, and, count } from "drizzle-orm";
|
||||
|
||||
export const handleNewtPingRequestMessage: MessageHandler = async (context) => {
|
||||
const { message, client, sendToClient } = context;
|
||||
|
@ -17,7 +17,10 @@ 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);
|
||||
const exitNodesList = await db
|
||||
.select()
|
||||
.from(exitNodes)
|
||||
.where(ne(exitNodes.maxConnections, 0));
|
||||
|
||||
let lastExitNodeId = null;
|
||||
if (newt.siteId) {
|
||||
|
@ -50,6 +53,10 @@ export const handleNewtPingRequestMessage: MessageHandler = async (context) => {
|
|||
)
|
||||
);
|
||||
|
||||
if (currentConnections.count >= maxConnections) {
|
||||
return null
|
||||
}
|
||||
|
||||
weight =
|
||||
(maxConnections - currentConnections.count) /
|
||||
maxConnections;
|
||||
|
@ -65,11 +72,14 @@ export const handleNewtPingRequestMessage: MessageHandler = async (context) => {
|
|||
})
|
||||
);
|
||||
|
||||
// filter out null values
|
||||
const filteredExitNodes = exitNodesPayload.filter((node) => node !== null);
|
||||
|
||||
return {
|
||||
message: {
|
||||
type: "newt/ping/exitNodes",
|
||||
data: {
|
||||
exitNodes: exitNodesPayload
|
||||
exitNodes: filteredExitNodes
|
||||
}
|
||||
},
|
||||
broadcast: false, // Send to all clients
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue