mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-15 23:17:55 +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 { exitNodes, Newt } from "@server/db";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import config from "@server/lib/config";
|
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) => {
|
export const handleNewtPingRequestMessage: MessageHandler = async (context) => {
|
||||||
const { message, client, sendToClient } = 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
|
// 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;
|
let lastExitNodeId = null;
|
||||||
if (newt.siteId) {
|
if (newt.siteId) {
|
||||||
|
@ -50,6 +53,10 @@ export const handleNewtPingRequestMessage: MessageHandler = async (context) => {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (currentConnections.count >= maxConnections) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
weight =
|
weight =
|
||||||
(maxConnections - currentConnections.count) /
|
(maxConnections - currentConnections.count) /
|
||||||
maxConnections;
|
maxConnections;
|
||||||
|
@ -65,11 +72,14 @@ export const handleNewtPingRequestMessage: MessageHandler = async (context) => {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// filter out null values
|
||||||
|
const filteredExitNodes = exitNodesPayload.filter((node) => node !== null);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
message: {
|
message: {
|
||||||
type: "newt/ping/exitNodes",
|
type: "newt/ping/exitNodes",
|
||||||
data: {
|
data: {
|
||||||
exitNodes: exitNodesPayload
|
exitNodes: filteredExitNodes
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
broadcast: false, // Send to all clients
|
broadcast: false, // Send to all clients
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue