Adding and removing peers working; better axios errors

This commit is contained in:
Owen 2025-08-14 17:57:50 -07:00
parent 04ecf41c5a
commit 2c96eb7851
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
2 changed files with 71 additions and 66 deletions

View file

@ -33,24 +33,24 @@ export async function createHybridClientServer() {
// Register message handlers // Register message handlers
client.registerHandler("remoteExitNode/peers/add", async (message) => { client.registerHandler("remoteExitNode/peers/add", async (message) => {
const { pubKey, allowedIps } = message.data; const { publicKey, allowedIps } = message.data;
// TODO: we are getting the exit node twice here // TODO: we are getting the exit node twice here
// NOTE: there should only be one gerbil registered so... // NOTE: there should only be one gerbil registered so...
const [exitNode] = await db.select().from(exitNodes).limit(1); const [exitNode] = await db.select().from(exitNodes).limit(1);
await addPeer(exitNode.exitNodeId, { await addPeer(exitNode.exitNodeId, {
publicKey: pubKey, publicKey: publicKey,
allowedIps: allowedIps || [] allowedIps: allowedIps || []
}); });
}); });
client.registerHandler("remoteExitNode/peers/remove", async (message) => { client.registerHandler("remoteExitNode/peers/remove", async (message) => {
const { pubKey } = message.data; const { publicKey } = message.data;
// TODO: we are getting the exit node twice here // TODO: we are getting the exit node twice here
// NOTE: there should only be one gerbil registered so... // NOTE: there should only be one gerbil registered so...
const [exitNode] = await db.select().from(exitNodes).limit(1); const [exitNode] = await db.select().from(exitNodes).limit(1);
await deletePeer(exitNode.exitNodeId, pubKey); await deletePeer(exitNode.exitNodeId, publicKey);
}); });
// /update-proxy-mapping // /update-proxy-mapping
@ -65,21 +65,18 @@ export async function createHybridClientServer() {
const response = await axios.post(`${exitNode.endpoint}/update-proxy-mapping`, message.data); const response = await axios.post(`${exitNode.endpoint}/update-proxy-mapping`, message.data);
logger.info(`Successfully updated proxy mapping: ${response.status}`); logger.info(`Successfully updated proxy mapping: ${response.status}`);
} catch (error) { } catch (error) {
// Extract useful information from axios error without circular references // pull data out of the axios error to log
if (error && typeof error === 'object' && 'response' in error) { if (axios.isAxiosError(error)) {
const axiosError = error as any; logger.error("Error updating proxy mapping:", {
logger.error("Failed to update proxy mapping:", { message: error.message,
status: axiosError.response?.status, code: error.code,
statusText: axiosError.response?.statusText, status: error.response?.status,
data: axiosError.response?.data, statusText: error.response?.statusText,
message: axiosError.message, url: error.config?.url,
url: axiosError.config?.url method: error.config?.method
}); });
} else { } else {
logger.error("Failed to update proxy mapping:", { logger.error("Error updating proxy mapping:", error);
message: error instanceof Error ? error.message : String(error),
stack: error instanceof Error ? error.stack : undefined
});
} }
} }
}); });
@ -96,21 +93,18 @@ export async function createHybridClientServer() {
const response = await axios.post(`${exitNode.endpoint}/update-destinations`, message.data); const response = await axios.post(`${exitNode.endpoint}/update-destinations`, message.data);
logger.info(`Successfully updated destinations: ${response.status}`); logger.info(`Successfully updated destinations: ${response.status}`);
} catch (error) { } catch (error) {
// Extract useful information from axios error without circular references // pull data out of the axios error to log
if (error && typeof error === 'object' && 'response' in error) { if (axios.isAxiosError(error)) {
const axiosError = error as any; logger.error("Error updating destinations:", {
logger.error("Failed to update destinations:", { message: error.message,
status: axiosError.response?.status, code: error.code,
statusText: axiosError.response?.statusText, status: error.response?.status,
data: axiosError.response?.data, statusText: error.response?.statusText,
message: axiosError.message, url: error.config?.url,
url: axiosError.config?.url method: error.config?.method
}); });
} else { } else {
logger.error("Failed to update proxy mapping:", { logger.error("Error updating destinations:", error);
message: error instanceof Error ? error.message : String(error),
stack: error instanceof Error ? error.stack : undefined
});
} }
} }
}); });

View file

@ -87,8 +87,7 @@ export class TraefikConfigManager {
public async HandleTraefikConfig(): Promise<void> { public async HandleTraefikConfig(): Promise<void> {
try { try {
// Get all active domains for this exit node via HTTP call // Get all active domains for this exit node via HTTP call
const getTraefikConfig = const getTraefikConfig = await this.getTraefikConfig();
await this.getTraefikConfig();
if (!getTraefikConfig) { if (!getTraefikConfig) {
logger.error( logger.error(
@ -138,12 +137,32 @@ export class TraefikConfigManager {
try { try {
const [exitNode] = await db.select().from(exitNodes).limit(1); const [exitNode] = await db.select().from(exitNodes).limit(1);
if (exitNode) { if (exitNode) {
try {
await axios.post(
`${exitNode.reachableAt}/update-local-snis`,
{ fullDomains: Array.from(domains) },
{ headers: { "Content-Type": "application/json" } }
);
} catch (error) {
// pull data out of the axios error to log
if (axios.isAxiosError(error)) {
logger.error("Error updating local SNI:", {
message: error.message,
code: error.code,
status: error.response?.status,
statusText: error.response?.statusText,
url: error.config?.url,
method: error.config?.method
});
} else {
logger.error(
"Error updating local SNI:",
error
);
}
}
} else {
logger.error("No exit node found"); logger.error("No exit node found");
await axios.post(
`${exitNode.reachableAt}/update-local-snis`,
{ fullDomains: Array.from(domains) },
{ headers: { "Content-Type": "application/json" } }
);
} }
} catch (err) { } catch (err) {
logger.error("Failed to post domains to SNI proxy:", err); logger.error("Failed to post domains to SNI proxy:", err);
@ -199,22 +218,19 @@ export class TraefikConfigManager {
); );
return { domains, traefikConfig }; return { domains, traefikConfig };
} catch (err) { } catch (error) {
// Extract useful information from axios error without circular references // pull data out of the axios error to log
if (err && typeof err === 'object' && 'response' in err) { if (axios.isAxiosError(error)) {
const axiosError = err as any; logger.error("Error fetching traefik config:", {
logger.error("Failed to fetch traefik config:", { message: error.message,
status: axiosError.response?.status, code: error.code,
statusText: axiosError.response?.statusText, status: error.response?.status,
data: axiosError.response?.data, statusText: error.response?.statusText,
message: axiosError.message, url: error.config?.url,
url: axiosError.config?.url method: error.config?.method
}); });
} else { } else {
logger.error("Failed to fetch traefik config:", { logger.error("Error fetching traefik config:", error);
message: err instanceof Error ? err.message : String(err),
stack: err instanceof Error ? err.stack : undefined
});
} }
return null; return null;
} }
@ -303,23 +319,18 @@ export class TraefikConfigManager {
return response.data.data; return response.data.data;
} catch (error) { } catch (error) {
// Extract useful information from axios error without circular references // pull data out of the axios error to log
if (error && typeof error === 'object' && 'response' in error) { if (axios.isAxiosError(error)) {
const axiosError = error as any; logger.error("Error getting certificates:", {
logger.error("Error fetching certificates for domains:", { message: error.message,
status: axiosError.response?.status, code: error.code,
statusText: axiosError.response?.statusText, status: error.response?.status,
data: axiosError.response?.data, statusText: error.response?.statusText,
message: axiosError.message, url: error.config?.url,
url: axiosError.config?.url, method: error.config?.method
domains: domainArray
}); });
} else { } else {
logger.error("Error fetching certificates for domains:", { logger.error("Error getting certificates:", error);
message: error instanceof Error ? error.message : String(error),
stack: error instanceof Error ? error.stack : undefined,
domains: domainArray
});
} }
return []; return [];
} }