mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-04 01:36:39 +00:00
Try to fix issue not sending newt commands
This commit is contained in:
@@ -432,7 +432,12 @@ export function generateRemoteSubnets(
|
|||||||
): string[] {
|
): string[] {
|
||||||
const remoteSubnets = allSiteResources
|
const remoteSubnets = allSiteResources
|
||||||
.filter((sr) => {
|
.filter((sr) => {
|
||||||
if (sr.mode === "cidr") return true;
|
if (sr.mode === "cidr") {
|
||||||
|
// check if its a valid CIDR using zod
|
||||||
|
const cidrSchema = z.union([z.cidrv4(), z.cidrv6()]);
|
||||||
|
const parseResult = cidrSchema.safeParse(sr.destination);
|
||||||
|
return parseResult.success;
|
||||||
|
}
|
||||||
if (sr.mode === "host") {
|
if (sr.mode === "host") {
|
||||||
// check if its a valid IP using zod
|
// check if its a valid IP using zod
|
||||||
const ipSchema = z.union([z.ipv4(), z.ipv6()]);
|
const ipSchema = z.union([z.ipv4(), z.ipv6()]);
|
||||||
@@ -456,13 +461,12 @@ export function generateRemoteSubnets(
|
|||||||
export type Alias = { alias: string | null; aliasAddress: string | null };
|
export type Alias = { alias: string | null; aliasAddress: string | null };
|
||||||
|
|
||||||
export function generateAliasConfig(allSiteResources: SiteResource[]): Alias[] {
|
export function generateAliasConfig(allSiteResources: SiteResource[]): Alias[] {
|
||||||
let aliasConfigs = allSiteResources
|
return allSiteResources
|
||||||
.filter((sr) => sr.alias && sr.aliasAddress && sr.mode == "host")
|
.filter((sr) => sr.alias && sr.aliasAddress && sr.mode == "host")
|
||||||
.map((sr) => ({
|
.map((sr) => ({
|
||||||
alias: sr.alias,
|
alias: sr.alias,
|
||||||
aliasAddress: sr.aliasAddress
|
aliasAddress: sr.aliasAddress
|
||||||
}));
|
}));
|
||||||
return aliasConfigs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SubnetProxyTarget = {
|
export type SubnetProxyTarget = {
|
||||||
|
|||||||
@@ -955,24 +955,9 @@ export async function rebuildClientAssociationsFromClient(
|
|||||||
|
|
||||||
/////////// Send messages ///////////
|
/////////// Send messages ///////////
|
||||||
|
|
||||||
// Get the olm for this client
|
|
||||||
const [olm] = await trx
|
|
||||||
.select({ olmId: olms.olmId })
|
|
||||||
.from(olms)
|
|
||||||
.where(eq(olms.clientId, client.clientId))
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if (!olm) {
|
|
||||||
logger.warn(
|
|
||||||
`Olm not found for client ${client.clientId}, skipping peer updates`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle messages for sites being added
|
// Handle messages for sites being added
|
||||||
await handleMessagesForClientSites(
|
await handleMessagesForClientSites(
|
||||||
client,
|
client,
|
||||||
olm.olmId,
|
|
||||||
sitesToAdd,
|
sitesToAdd,
|
||||||
sitesToRemove,
|
sitesToRemove,
|
||||||
trx
|
trx
|
||||||
@@ -996,11 +981,26 @@ async function handleMessagesForClientSites(
|
|||||||
userId: string | null;
|
userId: string | null;
|
||||||
orgId: string;
|
orgId: string;
|
||||||
},
|
},
|
||||||
olmId: string,
|
|
||||||
sitesToAdd: number[],
|
sitesToAdd: number[],
|
||||||
sitesToRemove: number[],
|
sitesToRemove: number[],
|
||||||
trx: Transaction | typeof db = db
|
trx: Transaction | typeof db = db
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
// Get the olm for this client
|
||||||
|
const [olm] = await trx
|
||||||
|
.select({ olmId: olms.olmId })
|
||||||
|
.from(olms)
|
||||||
|
.where(eq(olms.clientId, client.clientId))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!olm) {
|
||||||
|
logger.warn(
|
||||||
|
`Olm not found for client ${client.clientId}, skipping peer updates`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const olmId = olm.olmId;
|
||||||
|
|
||||||
if (!client.subnet || !client.pubKey) {
|
if (!client.subnet || !client.pubKey) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Client ${client.clientId} missing subnet or pubKey, skipping peer updates`
|
`Client ${client.clientId} missing subnet or pubKey, skipping peer updates`
|
||||||
@@ -1021,9 +1021,9 @@ async function handleMessagesForClientSites(
|
|||||||
.leftJoin(newts, eq(sites.siteId, newts.siteId))
|
.leftJoin(newts, eq(sites.siteId, newts.siteId))
|
||||||
.where(inArray(sites.siteId, allSiteIds));
|
.where(inArray(sites.siteId, allSiteIds));
|
||||||
|
|
||||||
let newtJobs: Promise<any>[] = [];
|
const newtJobs: Promise<any>[] = [];
|
||||||
let olmJobs: Promise<any>[] = [];
|
const olmJobs: Promise<any>[] = [];
|
||||||
let exitNodeJobs: Promise<any>[] = [];
|
const exitNodeJobs: Promise<any>[] = [];
|
||||||
|
|
||||||
for (const siteData of sitesData) {
|
for (const siteData of sitesData) {
|
||||||
const site = siteData.sites;
|
const site = siteData.sites;
|
||||||
@@ -1130,18 +1130,8 @@ async function handleMessagesForClientResources(
|
|||||||
resourcesToRemove: number[],
|
resourcesToRemove: number[],
|
||||||
trx: Transaction | typeof db = db
|
trx: Transaction | typeof db = db
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Group resources by site
|
const proxyJobs: Promise<any>[] = [];
|
||||||
const resourcesBySite = new Map<number, SiteResource[]>();
|
const olmJobs: Promise<any>[] = [];
|
||||||
|
|
||||||
for (const resource of allNewResources) {
|
|
||||||
if (!resourcesBySite.has(resource.siteId)) {
|
|
||||||
resourcesBySite.set(resource.siteId, []);
|
|
||||||
}
|
|
||||||
resourcesBySite.get(resource.siteId)!.push(resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
let proxyJobs: Promise<any>[] = [];
|
|
||||||
let olmJobs: Promise<any>[] = [];
|
|
||||||
|
|
||||||
// Handle additions
|
// Handle additions
|
||||||
if (resourcesToAdd.length > 0) {
|
if (resourcesToAdd.length > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user