mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-05 02:06:41 +00:00
Change destructuring
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { db, exitNodes } from "@server/db";
|
import { db, ExitNode, exitNodes } from "@server/db";
|
||||||
import { getUniqueExitNodeEndpointName } from "@server/db/names";
|
import { getUniqueExitNodeEndpointName } from "@server/db/names";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
import { getNextAvailableSubnet } from "@server/lib/exitNodes";
|
import { getNextAvailableSubnet } from "@server/lib/exitNodes";
|
||||||
@@ -8,7 +8,7 @@ import { eq } from "drizzle-orm";
|
|||||||
export async function createExitNode(publicKey: string, reachableAt: string | undefined) {
|
export async function createExitNode(publicKey: string, reachableAt: string | undefined) {
|
||||||
// Fetch exit node
|
// Fetch exit node
|
||||||
const [exitNodeQuery] = await db.select().from(exitNodes).limit(1);
|
const [exitNodeQuery] = await db.select().from(exitNodes).limit(1);
|
||||||
let exitNode;
|
let exitNode: ExitNode;
|
||||||
if (!exitNodeQuery) {
|
if (!exitNodeQuery) {
|
||||||
const address = await getNextAvailableSubnet();
|
const address = await getNextAvailableSubnet();
|
||||||
// TODO: eventually we will want to get the next available port so that we can multiple exit nodes
|
// TODO: eventually we will want to get the next available port so that we can multiple exit nodes
|
||||||
@@ -24,7 +24,7 @@ export async function createExitNode(publicKey: string, reachableAt: string | un
|
|||||||
`Exit Node ${publicKey.slice(0, 8)}`;
|
`Exit Node ${publicKey.slice(0, 8)}`;
|
||||||
|
|
||||||
// create a new exit node
|
// create a new exit node
|
||||||
exitNode = await db
|
[exitNode] = await db
|
||||||
.insert(exitNodes)
|
.insert(exitNodes)
|
||||||
.values({
|
.values({
|
||||||
publicKey,
|
publicKey,
|
||||||
@@ -38,11 +38,11 @@ export async function createExitNode(publicKey: string, reachableAt: string | un
|
|||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
`Created new exit node ${exitNode[0].name} with address ${exitNode[0].address} and port ${exitNode[0].listenPort}`
|
`Created new exit node ${exitNode.name} with address ${exitNode.address} and port ${exitNode.listenPort}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// update the existing exit node
|
// update the existing exit node
|
||||||
exitNode = await db
|
[exitNode] = await db
|
||||||
.update(exitNodes)
|
.update(exitNodes)
|
||||||
.set({
|
.set({
|
||||||
reachableAt,
|
reachableAt,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { getAllowedIps } from "../target/helpers";
|
|||||||
import { proxyToRemote } from "@server/lib/remoteProxy";
|
import { proxyToRemote } from "@server/lib/remoteProxy";
|
||||||
import { getNextAvailableSubnet } from "@server/lib/exitNodes";
|
import { getNextAvailableSubnet } from "@server/lib/exitNodes";
|
||||||
import { createExitNode } from "./createExitNode";
|
import { createExitNode } from "./createExitNode";
|
||||||
|
|
||||||
// Define Zod schema for request validation
|
// Define Zod schema for request validation
|
||||||
const getConfigSchema = z.object({
|
const getConfigSchema = z.object({
|
||||||
publicKey: z.string(),
|
publicKey: z.string(),
|
||||||
@@ -69,13 +70,13 @@ export async function getConfig(
|
|||||||
if (config.isManagedMode()) {
|
if (config.isManagedMode()) {
|
||||||
req.body = {
|
req.body = {
|
||||||
...req.body,
|
...req.body,
|
||||||
endpoint: exitNode[0].endpoint,
|
endpoint: exitNode.endpoint,
|
||||||
listenPort: exitNode[0].listenPort
|
listenPort: exitNode.listenPort
|
||||||
};
|
};
|
||||||
return proxyToRemote(req, res, next, "hybrid/gerbil/get-config");
|
return proxyToRemote(req, res, next, "hybrid/gerbil/get-config");
|
||||||
}
|
}
|
||||||
|
|
||||||
const configResponse = await generateGerbilConfig(exitNode[0]);
|
const configResponse = await generateGerbilConfig(exitNode);
|
||||||
|
|
||||||
logger.debug("Sending config: ", configResponse);
|
logger.debug("Sending config: ", configResponse);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user