mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-04 09:46:40 +00:00
Update gerbil with new sites and targets
This commit is contained in:
@@ -13,6 +13,7 @@ import { findNextAvailableCidr } from "@server/utils/ip";
|
||||
// Define Zod schema for request validation
|
||||
const getConfigSchema = z.object({
|
||||
publicKey: z.string(),
|
||||
reachableAt: z.string().optional(),
|
||||
});
|
||||
|
||||
export type GetConfigResponse = {
|
||||
@@ -37,7 +38,7 @@ export async function getConfig(req: Request, res: Response, next: NextFunction)
|
||||
);
|
||||
}
|
||||
|
||||
const { publicKey } = parsedParams.data;
|
||||
const { publicKey, reachableAt } = parsedParams.data;
|
||||
|
||||
if (!publicKey) {
|
||||
return next(createHttpError(HttpCode.BAD_REQUEST, 'publicKey is required'));
|
||||
@@ -57,6 +58,7 @@ export async function getConfig(req: Request, res: Response, next: NextFunction)
|
||||
endpoint: `${subEndpoint}.${config.gerbil.base_endpoint}`,
|
||||
address,
|
||||
listenPort,
|
||||
reachableAt,
|
||||
name: `Exit Node ${publicKey.slice(0, 8)}`,
|
||||
}).returning().execute();
|
||||
|
||||
|
||||
57
server/routers/gerbil/peers.ts
Normal file
57
server/routers/gerbil/peers.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import axios from 'axios';
|
||||
import logger from '@server/logger';
|
||||
import db from '@server/db';
|
||||
import { exitNodes } from '@server/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
export async function addPeer(exitNodeId: number, peer: {
|
||||
publicKey: string;
|
||||
allowedIps: string[];
|
||||
}) {
|
||||
|
||||
const [exitNode] = await db.select().from(exitNodes).where(eq(exitNodes.exitNodeId, exitNodeId)).limit(1);
|
||||
if (!exitNode) {
|
||||
throw new Error(`Exit node with ID ${exitNodeId} not found`);
|
||||
}
|
||||
if (!exitNode.reachableAt) {
|
||||
throw new Error(`Exit node with ID ${exitNodeId} is not reachable`);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.post(`${exitNode.reachableAt}/peer`, peer, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
});
|
||||
|
||||
logger.info('Peer added successfully:', response.data.status);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
throw new Error(`HTTP error! status: ${error.response?.status}`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function deletePeer(exitNodeId: number, publicKey: string) {
|
||||
const [exitNode] = await db.select().from(exitNodes).where(eq(exitNodes.exitNodeId, exitNodeId)).limit(1);
|
||||
if (!exitNode) {
|
||||
throw new Error(`Exit node with ID ${exitNodeId} not found`);
|
||||
}
|
||||
if (!exitNode.reachableAt) {
|
||||
throw new Error(`Exit node with ID ${exitNodeId} is not reachable`);
|
||||
}
|
||||
try {
|
||||
const response = await axios.delete(`${exitNode.reachableAt}/peer`, {
|
||||
data: { publicKey } // Send public key in request body
|
||||
});
|
||||
logger.info('Peer deleted successfully:', response.data.status);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
throw new Error(`HTTP error! status: ${error.response?.status}`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user