mirror of
https://github.com/fosrl/pangolin.git
synced 2026-09-09 12:36:16 +02:00
Fix circular import
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025-2026 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { EventEmitter } from "events";
|
||||||
|
|
||||||
|
export interface ExitNodeOnlineEvent {
|
||||||
|
exitNodeId: number;
|
||||||
|
endpoint: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const EXIT_NODE_ONLINE_EVENT = "exit-node-online";
|
||||||
|
|
||||||
|
export const exitNodeEvents = new EventEmitter();
|
||||||
@@ -17,6 +17,22 @@ import { eq } from "drizzle-orm";
|
|||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import redisManager from "#private/lib/redis";
|
import redisManager from "#private/lib/redis";
|
||||||
import { sendToClient } from "../ws";
|
import { sendToClient } from "../ws";
|
||||||
|
import {
|
||||||
|
exitNodeEvents,
|
||||||
|
EXIT_NODE_ONLINE_EVENT,
|
||||||
|
ExitNodeOnlineEvent
|
||||||
|
} from "./exitNodeEvents";
|
||||||
|
|
||||||
|
exitNodeEvents.on(
|
||||||
|
EXIT_NODE_ONLINE_EVENT,
|
||||||
|
({ exitNodeId, endpoint }: ExitNodeOnlineEvent) => {
|
||||||
|
scheduleExitNodeReconnect(exitNodeId, endpoint).catch((error) => {
|
||||||
|
logger.error("Failed to schedule exit node reconnect", {
|
||||||
|
error
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const INITIAL_DELAY_MS = 15 * 1000; // 15 seconds before first check
|
const INITIAL_DELAY_MS = 15 * 1000; // 15 seconds before first check
|
||||||
const CHECK_INTERVAL_MS = 10 * 1000; // Check every 10 seconds
|
const CHECK_INTERVAL_MS = 10 * 1000; // Check every 10 seconds
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { MessageHandler } from "@server/routers/ws";
|
|||||||
import { RemoteExitNode } from "@server/db";
|
import { RemoteExitNode } from "@server/db";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { scheduleExitNodeReconnect } from "./exitNodeReconnectScheduler";
|
import { exitNodeEvents, EXIT_NODE_ONLINE_EVENT } from "./exitNodeEvents";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles ping messages from clients and responds with pong
|
* Handles ping messages from clients and responds with pong
|
||||||
@@ -60,13 +60,9 @@ export const handleRemoteExitNodePingMessage: MessageHandler = async (
|
|||||||
!currentExitNode.online &&
|
!currentExitNode.online &&
|
||||||
currentExitNode.endpoint
|
currentExitNode.endpoint
|
||||||
) {
|
) {
|
||||||
scheduleExitNodeReconnect(
|
exitNodeEvents.emit(EXIT_NODE_ONLINE_EVENT, {
|
||||||
remoteExitNode.exitNodeId,
|
exitNodeId: remoteExitNode.exitNodeId,
|
||||||
currentExitNode.endpoint
|
endpoint: currentExitNode.endpoint
|
||||||
).catch((error) => {
|
|
||||||
logger.error("Failed to schedule exit node reconnect", {
|
|
||||||
error
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user