Update the remote subnets

This commit is contained in:
Owen
2025-11-20 15:17:48 -05:00
parent 3750c36aa7
commit 9420b41e39
4 changed files with 113 additions and 11 deletions

View File

@@ -36,6 +36,7 @@ import {
SubnetProxyTarget
} from "@server/lib/ip";
import {
addRemoteSubnets,
addTargets as addSubnetProxyTargets,
removeTargets as removeSubnetProxyTargets
} from "@server/routers/client/targets";
@@ -644,6 +645,8 @@ async function handleSubnetProxyTargetUpdates(
return;
}
let proxyJobs = [];
let olmJobs = [];
// Generate targets for added associations
if (clientSiteResourcesToAdd.length > 0) {
const addedClients = allClients.filter((client) =>
@@ -660,11 +663,21 @@ async function handleSubnetProxyTargetUpdates(
logger.info(
`Adding ${targetsToAdd.length} subnet proxy targets for siteResource ${siteResource.siteResourceId}`
);
await addSubnetProxyTargets(newt.newtId, targetsToAdd);
proxyJobs.push(
addSubnetProxyTargets(newt.newtId, targetsToAdd)
);
}
for (const client of addedClients) {
olmJobs.push(
addRemoteSubnets(client.clientId, siteResource.siteId, generateRemoteSubnets([siteResource]))
);
}
}
}
// here we use the existingSiteResource from BEFORE we updated the destination so we dont need to worry about updating destinations here
// Generate targets for removed associations
if (clientSiteResourcesToRemove.length > 0) {
const removedClients = existingClients.filter((client) =>
@@ -681,8 +694,18 @@ async function handleSubnetProxyTargetUpdates(
logger.info(
`Removing ${targetsToRemove.length} subnet proxy targets for siteResource ${siteResource.siteResourceId}`
);
await removeSubnetProxyTargets(newt.newtId, targetsToRemove);
proxyJobs.push(
removeSubnetProxyTargets(newt.newtId, targetsToRemove)
);
}
for (const client of removedClients) {
olmJobs.push(
addRemoteSubnets(client.clientId, siteResource.siteId, generateRemoteSubnets([siteResource]))
);
}
}
}
}
await Promise.all(proxyJobs);
}