mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-23 05:16:38 +00:00
Able to connect multi site on olm - POC 1
This commit is contained in:
@@ -51,32 +51,32 @@ export async function getAllRelays(
|
||||
}
|
||||
}
|
||||
|
||||
// get the clients on each site and map them to the site
|
||||
const sitesAndClients = await Promise.all(sitesRes.map(async (site) => {
|
||||
const clientsRes = await db.select().from(clients).where(eq(clients.siteId, site.siteId));
|
||||
return {
|
||||
site,
|
||||
clients: clientsRes
|
||||
};
|
||||
}));
|
||||
// // get the clients on each site and map them to the site
|
||||
// const sitesAndClients = await Promise.all(sitesRes.map(async (site) => {
|
||||
// const clientsRes = await db.select().from(clients).where(eq(clients.siteId, site.siteId));
|
||||
// return {
|
||||
// site,
|
||||
// clients: clientsRes
|
||||
// };
|
||||
// }));
|
||||
|
||||
let mappings: { [key: string]: {
|
||||
destinationIp: string;
|
||||
destinationPort: number;
|
||||
} } = {};
|
||||
|
||||
for (const siteAndClients of sitesAndClients) {
|
||||
const { site, clients } = siteAndClients;
|
||||
for (const client of clients) {
|
||||
if (!client.endpoint || !site.endpoint || !site.subnet) {
|
||||
continue;
|
||||
}
|
||||
mappings[client.endpoint] = {
|
||||
destinationIp: site.subnet.split("/")[0],
|
||||
destinationPort: parseInt(site.endpoint.split(":")[1])
|
||||
};
|
||||
}
|
||||
}
|
||||
// for (const siteAndClients of sitesAndClients) {
|
||||
// const { site, clients } = siteAndClients;
|
||||
// for (const client of clients) {
|
||||
// if (!client.endpoint || !site.endpoint || !site.subnet) {
|
||||
// continue;
|
||||
// }
|
||||
// mappings[client.endpoint] = {
|
||||
// destinationIp: site.subnet.split("/")[0],
|
||||
// destinationPort: parseInt(site.endpoint.split(":")[1])
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
|
||||
return res.status(HttpCode.OK).send({ mappings });
|
||||
} catch (error) {
|
||||
|
||||
@@ -80,10 +80,10 @@ export async function updateHolePunch(
|
||||
.where(eq(clients.clientId, olm.clientId))
|
||||
.returning();
|
||||
|
||||
[site] = await db
|
||||
.select()
|
||||
.from(sites)
|
||||
.where(eq(sites.siteId, client.siteId));
|
||||
// [site] = await db
|
||||
// .select()
|
||||
// .from(sites)
|
||||
// .where(eq(sites.siteId, client.siteId));
|
||||
|
||||
} else if (newtId) {
|
||||
const { session, newt: newtSession } =
|
||||
|
||||
@@ -6,6 +6,7 @@ import db from "@server/db";
|
||||
import { clients, clientSites, Newt, Site, sites } from "@server/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { getNextAvailableClientSubnet } from "@server/lib/ip";
|
||||
import config from "@server/lib/config";
|
||||
|
||||
const inputSchema = z.object({
|
||||
publicKey: z.string(),
|
||||
@@ -58,7 +59,12 @@ export const handleGetConfigMessage: MessageHandler = async (context) => {
|
||||
let site: Site | undefined;
|
||||
if (!siteRes.address) {
|
||||
let address = await getNextAvailableClientSubnet(siteRes.orgId);
|
||||
address = address.split("/")[0]; // get the first part of the CIDR
|
||||
if (!address) {
|
||||
logger.error("handleGetConfigMessage: No available address");
|
||||
return;
|
||||
}
|
||||
|
||||
address = `${address.split("/")[0]}/${config.getRawConfig().orgs.block_size}` // we want the block size of the whole org
|
||||
|
||||
// create a new exit node
|
||||
const [updateRes] = await db
|
||||
|
||||
Reference in New Issue
Block a user