mirror of
https://github.com/fosrl/pangolin.git
synced 2026-10-14 16:49:05 +02:00
Propogated Changes. listen port is now accessed from db instead of config
This commit is contained in:
@@ -36,6 +36,7 @@ export async function listExitNodes(
|
||||
endpoint: exitNodes.endpoint,
|
||||
publicKey: exitNodes.publicKey,
|
||||
listenPort: exitNodes.listenPort,
|
||||
relayPort: exitNodes.relayPort,
|
||||
reachableAt: exitNodes.reachableAt,
|
||||
maxConnections: exitNodes.maxConnections,
|
||||
online: exitNodes.online,
|
||||
|
||||
@@ -34,7 +34,6 @@ import {
|
||||
import { sendToExitNode } from "#dynamic/lib/exitNodes";
|
||||
import { sendToClientsBatch } from "#dynamic/routers/ws";
|
||||
import { canCompress } from "@server/lib/clientVersionChecks";
|
||||
import config from "@server/lib/config";
|
||||
import logger from "@server/logger";
|
||||
import {
|
||||
generateAliasConfig,
|
||||
@@ -816,6 +815,7 @@ async function handleMessagesForSiteClients(
|
||||
siteId: number;
|
||||
exitNode: {
|
||||
publicKey: string;
|
||||
relayPort: number;
|
||||
endpoint: string;
|
||||
};
|
||||
};
|
||||
@@ -961,6 +961,7 @@ async function handleMessagesForSiteClients(
|
||||
siteId,
|
||||
exitNode: {
|
||||
publicKey: exitNode.publicKey,
|
||||
relayPort: exitNode.relayPort,
|
||||
endpoint: exitNode.endpoint
|
||||
}
|
||||
},
|
||||
@@ -1238,8 +1239,6 @@ async function syncClientExitNodeConnections(
|
||||
.map((r) => [r.clientId as number, r])
|
||||
);
|
||||
|
||||
const relayPort = config.getRawConfig().gerbil.clients_start_port;
|
||||
|
||||
const connectPayloads: {
|
||||
clientId: string;
|
||||
message: { type: string; data: any };
|
||||
@@ -1278,7 +1277,7 @@ async function syncClientExitNodeConnections(
|
||||
data: {
|
||||
connect: true,
|
||||
endpoint: `${exitNode.endpoint}:${exitNode.listenPort}`,
|
||||
relayPort,
|
||||
relayPort: exitNode.relayPort,
|
||||
publicKey: exitNode.publicKey,
|
||||
serverIP: exitNode.address.split("/")[0],
|
||||
tunnelIP: client.exitNodeSubnet.split("/")[0],
|
||||
@@ -2451,6 +2450,7 @@ async function handleMessagesForClientSites(
|
||||
siteId: number;
|
||||
exitNode: {
|
||||
publicKey: string;
|
||||
relayPort: number;
|
||||
endpoint: string;
|
||||
};
|
||||
};
|
||||
@@ -2550,6 +2550,7 @@ async function handleMessagesForClientSites(
|
||||
siteId: site.siteId,
|
||||
exitNode: {
|
||||
publicKey: exitNode.publicKey,
|
||||
relayPort: exitNode.relayPort,
|
||||
endpoint: exitNode.endpoint
|
||||
}
|
||||
},
|
||||
|
||||
@@ -34,6 +34,7 @@ export async function createExitNode(
|
||||
// TODO: eventually we will want to get the next available port so that we can multiple exit nodes
|
||||
// const listenPort = await getNextAvailablePort();
|
||||
const listenPort = config.getRawConfig().gerbil.start_port;
|
||||
const relayPort = config.getRawConfig().gerbil.clients_start_port;
|
||||
|
||||
const exitNodeName =
|
||||
config.getRawConfig().gerbil.exit_node_name ||
|
||||
@@ -49,6 +50,7 @@ export async function createExitNode(
|
||||
privateConfig.getRawPrivateConfig().app.region || null,
|
||||
address,
|
||||
listenPort,
|
||||
relayPort,
|
||||
online: true,
|
||||
reachableAt,
|
||||
name: exitNodeName
|
||||
|
||||
@@ -201,10 +201,7 @@ export async function createRemoteExitNode(
|
||||
let releaseSubnetLock: (() => Promise<void>) | null = null;
|
||||
let newExitNodeAddress: string | null = null;
|
||||
if (!existingExitNode) {
|
||||
const { value, release } = await getNextAvailableSubnet(
|
||||
db,
|
||||
orgId
|
||||
);
|
||||
const { value, release } = await getNextAvailableSubnet(db, orgId);
|
||||
newExitNodeAddress = value;
|
||||
releaseSubnetLock = release;
|
||||
}
|
||||
@@ -220,6 +217,7 @@ export async function createRemoteExitNode(
|
||||
endpoint: "",
|
||||
publicKey: "",
|
||||
listenPort: 0,
|
||||
relayPort: 0,
|
||||
online: false,
|
||||
type: "remoteExitNode"
|
||||
})
|
||||
|
||||
@@ -96,7 +96,10 @@ export async function buildClientConfigurationForNewtClient(
|
||||
await updatePeer(client.clients.clientId, {
|
||||
siteId: site.siteId,
|
||||
endpoint: site.endpoint!,
|
||||
relayEndpoint: formatEndpoint(exitNode.endpoint, config.getRawConfig().gerbil.clients_start_port),
|
||||
relayEndpoint: formatEndpoint(
|
||||
exitNode.endpoint,
|
||||
exitNode.relayPort
|
||||
),
|
||||
publicKey: site.publicKey!,
|
||||
serverIP: site.address,
|
||||
serverPort: site.listenPort
|
||||
@@ -121,6 +124,7 @@ export async function buildClientConfigurationForNewtClient(
|
||||
siteId,
|
||||
exitNode: {
|
||||
publicKey: exitNode.publicKey,
|
||||
relayPort: exitNode.relayPort,
|
||||
endpoint: exitNode.endpoint
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
import logger from "@server/logger";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { addPeer, deletePeer } from "../newt/peers";
|
||||
import config from "@server/lib/config";
|
||||
import { SiR } from "react-icons/si";
|
||||
|
||||
export async function buildSiteConfigurationForOlmClient(
|
||||
@@ -129,7 +128,6 @@ export async function buildSiteConfigurationForOlmClient(
|
||||
}
|
||||
}
|
||||
|
||||
const clientsStartPort = config.getRawConfig().gerbil.clients_start_port;
|
||||
const peerOps: Promise<unknown>[] = [];
|
||||
|
||||
// Process each site
|
||||
@@ -216,7 +214,7 @@ export async function buildSiteConfigurationForOlmClient(
|
||||
logger.warn(`Exit node not found for site ${site.siteId}`);
|
||||
continue;
|
||||
}
|
||||
relayEndpoint = `${exitNode.endpoint}:${clientsStartPort}`;
|
||||
relayEndpoint = `${exitNode.endpoint}:${exitNode.relayPort}`;
|
||||
}
|
||||
|
||||
// Add site configuration to the array
|
||||
|
||||
@@ -289,7 +289,7 @@ export async function getOlmToken(
|
||||
let exitNodesHpData = allExitNodes.map((exitNode: ExitNode) => {
|
||||
return {
|
||||
publicKey: exitNode.publicKey,
|
||||
relayPort: config.getRawConfig().gerbil.clients_start_port,
|
||||
relayPort: exitNode.relayPort,
|
||||
endpoint: exitNode.endpoint,
|
||||
siteIds: exitNodeIdToSiteIds[exitNode.exitNodeId] ?? []
|
||||
};
|
||||
@@ -347,8 +347,7 @@ export async function getOlmToken(
|
||||
exitNodesHpData = [
|
||||
{
|
||||
publicKey: best.publicKey,
|
||||
relayPort:
|
||||
config.getRawConfig().gerbil.clients_start_port,
|
||||
relayPort: best.relayPort,
|
||||
endpoint: best.endpoint,
|
||||
siteIds: []
|
||||
// it should still HP without the site ids but it will get stuck in the client
|
||||
|
||||
@@ -4,7 +4,6 @@ import { clients, clientSitesAssociationsCache, Olm } from "@server/db";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { updatePeersBatch } from "../newt/peers";
|
||||
import logger from "@server/logger";
|
||||
import config from "@server/lib/config";
|
||||
import { parseSiteChainBatch, resolveNewtIdsBySite } from "./batchUtils";
|
||||
|
||||
export const handleOlmRelayMessage: MessageHandler = async (context) => {
|
||||
@@ -77,6 +76,7 @@ export const handleOlmRelayMessage: MessageHandler = async (context) => {
|
||||
siteId: number;
|
||||
chainId?: string;
|
||||
relayEndpoint: string;
|
||||
relayPort: number;
|
||||
}[] = [];
|
||||
|
||||
for (let i = 0; i < siteIds.length; i++) {
|
||||
@@ -97,7 +97,8 @@ export const handleOlmRelayMessage: MessageHandler = async (context) => {
|
||||
valid.push({
|
||||
siteId,
|
||||
chainId: chainIds[i],
|
||||
relayEndpoint: exitNode.endpoint
|
||||
relayEndpoint: exitNode.endpoint,
|
||||
relayPort: exitNode.relayPort
|
||||
});
|
||||
}
|
||||
|
||||
@@ -121,7 +122,9 @@ export const handleOlmRelayMessage: MessageHandler = async (context) => {
|
||||
);
|
||||
|
||||
// Only ack sites we can actually tell their newt to relay for
|
||||
const newtIdBySiteId = await resolveNewtIdsBySite(valid.map((v) => v.siteId));
|
||||
const newtIdBySiteId = await resolveNewtIdsBySite(
|
||||
valid.map((v) => v.siteId)
|
||||
);
|
||||
const pushable = valid.filter((v) => {
|
||||
if (!newtIdBySiteId.has(v.siteId)) {
|
||||
logger.warn(`Newt not found for site ${v.siteId}`);
|
||||
@@ -144,8 +147,6 @@ export const handleOlmRelayMessage: MessageHandler = async (context) => {
|
||||
}))
|
||||
);
|
||||
|
||||
const relayPort = config.getRawConfig().gerbil.clients_start_port;
|
||||
|
||||
if (isBatch) {
|
||||
return {
|
||||
message: {
|
||||
@@ -153,7 +154,7 @@ export const handleOlmRelayMessage: MessageHandler = async (context) => {
|
||||
data: {
|
||||
siteIds: pushable.map((v) => v.siteId),
|
||||
relayEndpoints: pushable.map((v) => v.relayEndpoint),
|
||||
relayPort,
|
||||
relayPort: pushable.map((v) => v.relayPort),
|
||||
chainIds: pushable.map((v) => v.chainId)
|
||||
}
|
||||
},
|
||||
@@ -169,7 +170,7 @@ export const handleOlmRelayMessage: MessageHandler = async (context) => {
|
||||
data: {
|
||||
siteId: single.siteId,
|
||||
relayEndpoint: single.relayEndpoint,
|
||||
relayPort,
|
||||
relayPort: single.relayPort,
|
||||
chainId: single.chainId
|
||||
}
|
||||
},
|
||||
|
||||
@@ -216,6 +216,7 @@ export const handleOlmServerInitAddPeerHandshake: MessageHandler = async (
|
||||
siteId: site.siteId,
|
||||
exitNode: {
|
||||
publicKey: exitNode.publicKey,
|
||||
relayPort: exitNode.relayPort,
|
||||
endpoint: exitNode.endpoint
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { sendToClient, sendToClientsBatch } from "#dynamic/routers/ws";
|
||||
import { clientSitesAssociationsCache, db, olms } from "@server/db";
|
||||
import { canCompress } from "@server/lib/clientVersionChecks";
|
||||
import config from "@server/lib/config";
|
||||
import logger from "@server/logger";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { Alias } from "yaml";
|
||||
@@ -155,6 +154,7 @@ export async function initPeerAddHandshake(
|
||||
siteId: number;
|
||||
exitNode: {
|
||||
publicKey: string;
|
||||
relayPort: number;
|
||||
endpoint: string;
|
||||
};
|
||||
},
|
||||
@@ -181,7 +181,7 @@ export async function initPeerAddHandshake(
|
||||
siteId: peer.siteId,
|
||||
exitNode: {
|
||||
publicKey: peer.exitNode.publicKey,
|
||||
relayPort: config.getRawConfig().gerbil.clients_start_port,
|
||||
relayPort: peer.exitNode.relayPort,
|
||||
endpoint: peer.exitNode.endpoint
|
||||
},
|
||||
chainId
|
||||
@@ -297,6 +297,7 @@ export async function initPeerAddHandshakeBatch(
|
||||
siteId: number;
|
||||
exitNode: {
|
||||
publicKey: string;
|
||||
relayPort: number;
|
||||
endpoint: string;
|
||||
};
|
||||
};
|
||||
@@ -317,8 +318,7 @@ export async function initPeerAddHandshakeBatch(
|
||||
siteId: item.peer.siteId,
|
||||
exitNode: {
|
||||
publicKey: item.peer.exitNode.publicKey,
|
||||
relayPort:
|
||||
config.getRawConfig().gerbil.clients_start_port,
|
||||
relayPort: item.peer.exitNode.relayPort,
|
||||
endpoint: item.peer.exitNode.endpoint
|
||||
},
|
||||
chainId: item.chainId
|
||||
|
||||
@@ -12,7 +12,6 @@ import { buildSiteConfigurationForOlmClient } from "./buildConfiguration";
|
||||
import { sendToClient } from "#dynamic/routers/ws";
|
||||
import logger from "@server/logger";
|
||||
import { count, eq, inArray } from "drizzle-orm";
|
||||
import config from "@server/lib/config";
|
||||
import { canCompress } from "@server/lib/clientVersionChecks";
|
||||
import { build } from "@server/build";
|
||||
|
||||
@@ -125,7 +124,7 @@ export async function sendOlmSyncMessage(olm: Olm, client: Client) {
|
||||
exitNodesData = allExitNodes.map((exitNode) => {
|
||||
return {
|
||||
publicKey: exitNode.publicKey,
|
||||
relayPort: config.getRawConfig().gerbil.clients_start_port,
|
||||
relayPort: exitNode.relayPort,
|
||||
endpoint: exitNode.endpoint,
|
||||
siteIds: exitNodeIdToSiteIds[exitNode.exitNodeId] ?? []
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@ export async function copyInConfig() {
|
||||
|
||||
const endpoint = config.getRawConfig().gerbil.base_endpoint;
|
||||
const listenPort = config.getRawConfig().gerbil.start_port;
|
||||
const relayPort = config.getRawConfig().gerbil.clients_start_port;
|
||||
|
||||
if (
|
||||
!config.getRawConfig().flags?.disable_config_managed_domains &&
|
||||
@@ -23,7 +24,7 @@ export async function copyInConfig() {
|
||||
if (exitNodeName) {
|
||||
await db
|
||||
.update(exitNodes)
|
||||
.set({ endpoint, listenPort })
|
||||
.set({ endpoint, listenPort, relayPort })
|
||||
.where(eq(exitNodes.name, exitNodeName));
|
||||
} else {
|
||||
await db
|
||||
@@ -34,6 +35,10 @@ export async function copyInConfig() {
|
||||
.update(exitNodes)
|
||||
.set({ listenPort })
|
||||
.where(ne(exitNodes.listenPort, listenPort));
|
||||
await db
|
||||
.update(exitNodes)
|
||||
.set({ relayPort })
|
||||
.where(ne(exitNodes.relayPort, relayPort));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user