mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-21 09:48:39 +02:00
Add exit node helper functions
This commit is contained in:
parent
2fea091e1f
commit
69a9bcb3da
2 changed files with 44 additions and 0 deletions
43
server/lib/exitNodes/exitNodes.ts
Normal file
43
server/lib/exitNodes/exitNodes.ts
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
import { db, exitNodes } from "@server/db";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { eq, and, or } from "drizzle-orm";
|
||||||
|
|
||||||
|
export async function privateVerifyExitNodeOrgAccess(
|
||||||
|
exitNodeId: number,
|
||||||
|
orgId: string
|
||||||
|
) {
|
||||||
|
const [exitNode] = await db
|
||||||
|
.select()
|
||||||
|
.from(exitNodes)
|
||||||
|
.where(eq(exitNodes.exitNodeId, exitNodeId));
|
||||||
|
|
||||||
|
// For any other type, deny access
|
||||||
|
return { hasAccess: true, exitNode };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listExitNodes(orgId: string, filterOnline = false) {
|
||||||
|
// TODO: pick which nodes to send and ping better than just all of them that are not remote
|
||||||
|
const allExitNodes = await db
|
||||||
|
.select({
|
||||||
|
exitNodeId: exitNodes.exitNodeId,
|
||||||
|
name: exitNodes.name,
|
||||||
|
address: exitNodes.address,
|
||||||
|
endpoint: exitNodes.endpoint,
|
||||||
|
publicKey: exitNodes.publicKey,
|
||||||
|
listenPort: exitNodes.listenPort,
|
||||||
|
reachableAt: exitNodes.reachableAt,
|
||||||
|
maxConnections: exitNodes.maxConnections,
|
||||||
|
online: exitNodes.online,
|
||||||
|
lastPing: exitNodes.lastPing,
|
||||||
|
type: exitNodes.type,
|
||||||
|
})
|
||||||
|
.from(exitNodes);
|
||||||
|
|
||||||
|
// Filter the nodes. If there are NO remoteExitNodes then do nothing. If there are then remove all of the non-remoteExitNodes
|
||||||
|
if (allExitNodes.length === 0) {
|
||||||
|
logger.warn("No exit nodes found!");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return allExitNodes;
|
||||||
|
}
|
1
server/lib/exitNodes/index.ts
Normal file
1
server/lib/exitNodes/index.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export * from "./privateExitNodes";
|
Loading…
Add table
Add a link
Reference in a new issue