mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-28 21:58:15 +02:00
Improve gerbil logging
This commit is contained in:
parent
69802e78f8
commit
f0138fad4f
4 changed files with 52 additions and 27 deletions
|
@ -341,8 +341,8 @@ export async function updateClient(
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (axios.isAxiosError(error)) {
|
if (axios.isAxiosError(error)) {
|
||||||
throw new Error(
|
logger.error(
|
||||||
`Error communicating with Gerbil. Make sure Pangolin can reach the Gerbil HTTP API: ${error.response?.status}`
|
`Error updating destinations (can Pangolin see Gerbil HTTP API?) for exit node at ${destination.reachableAt} (status: ${error.response?.status}): ${error.message}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
@ -1,15 +1,24 @@
|
||||||
import axios from 'axios';
|
import axios from "axios";
|
||||||
import logger from '@server/logger';
|
import logger from "@server/logger";
|
||||||
import { db } from "@server/db";
|
import { db } from "@server/db";
|
||||||
import { exitNodes } from '@server/db';
|
import { exitNodes } from "@server/db";
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq } from "drizzle-orm";
|
||||||
|
|
||||||
export async function addPeer(exitNodeId: number, peer: {
|
export async function addPeer(
|
||||||
publicKey: string;
|
exitNodeId: number,
|
||||||
allowedIps: string[];
|
peer: {
|
||||||
}) {
|
publicKey: string;
|
||||||
logger.info(`Adding peer with public key ${peer.publicKey} to exit node ${exitNodeId}`);
|
allowedIps: string[];
|
||||||
const [exitNode] = await db.select().from(exitNodes).where(eq(exitNodes.exitNodeId, exitNodeId)).limit(1);
|
}
|
||||||
|
) {
|
||||||
|
logger.info(
|
||||||
|
`Adding peer with public key ${peer.publicKey} to exit node ${exitNodeId}`
|
||||||
|
);
|
||||||
|
const [exitNode] = await db
|
||||||
|
.select()
|
||||||
|
.from(exitNodes)
|
||||||
|
.where(eq(exitNodes.exitNodeId, exitNodeId))
|
||||||
|
.limit(1);
|
||||||
if (!exitNode) {
|
if (!exitNode) {
|
||||||
throw new Error(`Exit node with ID ${exitNodeId} not found`);
|
throw new Error(`Exit node with ID ${exitNodeId} not found`);
|
||||||
}
|
}
|
||||||
|
@ -18,25 +27,37 @@ export async function addPeer(exitNodeId: number, peer: {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(`${exitNode.reachableAt}/peer`, peer, {
|
const response = await axios.post(
|
||||||
headers: {
|
`${exitNode.reachableAt}/peer`,
|
||||||
'Content-Type': 'application/json',
|
peer,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
logger.info('Peer added successfully:', { peer: response.data.status });
|
logger.info("Peer added successfully:", { peer: response.data.status });
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (axios.isAxiosError(error)) {
|
if (axios.isAxiosError(error)) {
|
||||||
throw new Error(`Error communicating with Gerbil. Make sure Pangolin can reach the Gerbil HTTP API: ${error.response?.status}`);
|
logger.error(
|
||||||
|
`Error adding peer (can Pangolin see Gerbil HTTP API?) for exit node at ${exitNode.reachableAt} (status: ${error.response?.status}): ${error.message}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deletePeer(exitNodeId: number, publicKey: string) {
|
export async function deletePeer(exitNodeId: number, publicKey: string) {
|
||||||
logger.info(`Deleting peer with public key ${publicKey} from exit node ${exitNodeId}`);
|
logger.info(
|
||||||
const [exitNode] = await db.select().from(exitNodes).where(eq(exitNodes.exitNodeId, exitNodeId)).limit(1);
|
`Deleting peer with public key ${publicKey} from exit node ${exitNodeId}`
|
||||||
|
);
|
||||||
|
const [exitNode] = await db
|
||||||
|
.select()
|
||||||
|
.from(exitNodes)
|
||||||
|
.where(eq(exitNodes.exitNodeId, exitNodeId))
|
||||||
|
.limit(1);
|
||||||
if (!exitNode) {
|
if (!exitNode) {
|
||||||
throw new Error(`Exit node with ID ${exitNodeId} not found`);
|
throw new Error(`Exit node with ID ${exitNodeId} not found`);
|
||||||
}
|
}
|
||||||
|
@ -44,12 +65,16 @@ export async function deletePeer(exitNodeId: number, publicKey: string) {
|
||||||
throw new Error(`Exit node with ID ${exitNodeId} is not reachable`);
|
throw new Error(`Exit node with ID ${exitNodeId} is not reachable`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const response = await axios.delete(`${exitNode.reachableAt}/peer?public_key=${encodeURIComponent(publicKey)}`);
|
const response = await axios.delete(
|
||||||
logger.info('Peer deleted successfully:', response.data.status);
|
`${exitNode.reachableAt}/peer?public_key=${encodeURIComponent(publicKey)}`
|
||||||
|
);
|
||||||
|
logger.info("Peer deleted successfully:", response.data.status);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (axios.isAxiosError(error)) {
|
if (axios.isAxiosError(error)) {
|
||||||
throw new Error(`Error communicating with Gerbil. Make sure Pangolin can reach the Gerbil HTTP API: ${error.response?.status}`);
|
logger.error(
|
||||||
|
`Error deleting peer (can Pangolin see Gerbil HTTP API?) for exit node at ${exitNode.reachableAt} (status: ${error.response?.status}): ${error.message}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,8 +203,8 @@ export async function updateHolePunch(
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (axios.isAxiosError(error)) {
|
if (axios.isAxiosError(error)) {
|
||||||
throw new Error(
|
logger.error(
|
||||||
`Error communicating with Gerbil. Make sure Pangolin can reach the Gerbil HTTP API: ${error.response?.status}`
|
`Error updating destinations (can Pangolin see Gerbil HTTP API?) for exit node at ${destination.reachableAt} (status: ${error.response?.status}): ${error.message}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
@ -128,8 +128,8 @@ export const handleGetConfigMessage: MessageHandler = async (context) => {
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (axios.isAxiosError(error)) {
|
if (axios.isAxiosError(error)) {
|
||||||
throw new Error(
|
logger.error(
|
||||||
`Error communicating with Gerbil. Make sure Pangolin can reach the Gerbil HTTP API: ${error.response?.status}`
|
`Error updating proxy mapping (can Pangolin see Gerbil HTTP API?) for exit node at ${exitNode.reachableAt} (status: ${error.response?.status}): ${error.message}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue