mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-02 08:46:38 +00:00
mark exit node as was previously connected
This commit is contained in:
@@ -19,10 +19,21 @@ 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);
|
||||||
|
|
||||||
|
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(
|
const exitNodesPayload = await Promise.all(
|
||||||
exitNodesList.map(async (node) => {
|
exitNodesList.map(async (node) => {
|
||||||
// (MAX_CONNECTIONS - current_connections) / MAX_CONNECTIONS)
|
// (MAX_CONNECTIONS - current_connections) / MAX_CONNECTIONS)
|
||||||
// higher = more desirable
|
// higher = more desirable
|
||||||
|
// like saying, this node has x% of its capacity left
|
||||||
|
|
||||||
let weight = 1;
|
let weight = 1;
|
||||||
const maxConnections = node.maxConnections;
|
const maxConnections = node.maxConnections;
|
||||||
@@ -48,7 +59,8 @@ export const handleNewtPingRequestMessage: MessageHandler = async (context) => {
|
|||||||
exitNodeId: node.exitNodeId,
|
exitNodeId: node.exitNodeId,
|
||||||
exitNodeName: node.name,
|
exitNodeName: node.name,
|
||||||
endpoint: node.endpoint,
|
endpoint: node.endpoint,
|
||||||
weight
|
weight,
|
||||||
|
wasPreviouslyConnected: node.exitNodeId === lastExitNodeId
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user