Able to connect multi site on olm - POC 1

This commit is contained in:
Owen
2025-04-01 12:49:02 -04:00
parent 96d6ad8142
commit 5ff4215bde
5 changed files with 39 additions and 30 deletions

View File

@@ -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) {

View File

@@ -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 } =