mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-10 12:46:37 +00:00
Fix bugs with updating a resource
This commit is contained in:
@@ -203,9 +203,9 @@ export async function updateAndGenerateEndpointDestinations(
|
|||||||
|
|
||||||
// Update clientSites for each site on this exit node
|
// Update clientSites for each site on this exit node
|
||||||
for (const site of sitesOnExitNode) {
|
for (const site of sitesOnExitNode) {
|
||||||
logger.debug(
|
// logger.debug(
|
||||||
`Updating site ${site.siteId} on exit node ${exitNode.exitNodeId}`
|
// `Updating site ${site.siteId} on exit node ${exitNode.exitNodeId}`
|
||||||
);
|
// );
|
||||||
|
|
||||||
// if the public key or endpoint has changed, update it otherwise continue
|
// if the public key or endpoint has changed, update it otherwise continue
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -268,10 +268,13 @@ export async function updateSiteResource(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// after everything is rebuilt above we still need to update the targets and remote subnets if the destination changed
|
// after everything is rebuilt above we still need to update the targets and remote subnets if the destination changed
|
||||||
if (
|
const destinationChanged =
|
||||||
existingSiteResource.destination !==
|
existingSiteResource.destination !==
|
||||||
updatedSiteResource.destination
|
updatedSiteResource.destination;
|
||||||
) {
|
const aliasChanged =
|
||||||
|
existingSiteResource.alias !== updatedSiteResource.alias;
|
||||||
|
|
||||||
|
if (destinationChanged || aliasChanged) {
|
||||||
const [newt] = await trx
|
const [newt] = await trx
|
||||||
.select()
|
.select()
|
||||||
.from(newts)
|
.from(newts)
|
||||||
@@ -284,53 +287,55 @@ export async function updateSiteResource(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldTargets = generateSubnetProxyTargets(
|
// Only update targets on newt if destination changed
|
||||||
existingSiteResource,
|
if (destinationChanged) {
|
||||||
mergedAllClients
|
const oldTargets = generateSubnetProxyTargets(
|
||||||
);
|
existingSiteResource,
|
||||||
const newTargets = generateSubnetProxyTargets(
|
mergedAllClients
|
||||||
updatedSiteResource,
|
);
|
||||||
mergedAllClients
|
const newTargets = generateSubnetProxyTargets(
|
||||||
);
|
updatedSiteResource,
|
||||||
|
mergedAllClients
|
||||||
|
);
|
||||||
|
|
||||||
await updateTargets(newt.newtId, {
|
await updateTargets(newt.newtId, {
|
||||||
oldTargets: oldTargets,
|
oldTargets: oldTargets,
|
||||||
newTargets: newTargets
|
newTargets: newTargets
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update olms for both destination and alias changes
|
||||||
let olmJobs: Promise<void>[] = [];
|
let olmJobs: Promise<void>[] = [];
|
||||||
for (const client of mergedAllClients) {
|
for (const client of mergedAllClients) {
|
||||||
// we also need to update the remote subnets on the olms for each client that has access to this site
|
// we also need to update the remote subnets on the olms for each client that has access to this site
|
||||||
try {
|
olmJobs.push(
|
||||||
olmJobs.push(
|
updatePeerData(
|
||||||
updatePeerData(
|
client.clientId,
|
||||||
client.clientId,
|
updatedSiteResource.siteId,
|
||||||
updatedSiteResource.siteId,
|
{
|
||||||
{
|
oldRemoteSubnets: generateRemoteSubnets([
|
||||||
oldRemoteSubnets: generateRemoteSubnets([
|
existingSiteResource
|
||||||
existingSiteResource
|
]),
|
||||||
]),
|
newRemoteSubnets: generateRemoteSubnets([
|
||||||
newRemoteSubnets: generateRemoteSubnets([
|
updatedSiteResource
|
||||||
updatedSiteResource
|
])
|
||||||
])
|
},
|
||||||
},
|
{
|
||||||
{
|
oldAliases: generateAliasConfig([
|
||||||
oldAliases: generateAliasConfig([
|
existingSiteResource
|
||||||
existingSiteResource
|
]),
|
||||||
]),
|
newAliases: generateAliasConfig([
|
||||||
newAliases: generateAliasConfig([
|
updatedSiteResource
|
||||||
updatedSiteResource
|
])
|
||||||
])
|
}
|
||||||
}
|
).catch((error) => {
|
||||||
)
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
logger.warn(
|
|
||||||
// this is okay because sometimes the olm is not online to receive the update or associated with the client yet
|
// this is okay because sometimes the olm is not online to receive the update or associated with the client yet
|
||||||
`Error updating peer data for client ${client.clientId}:`,
|
logger.warn(
|
||||||
error
|
`Error updating peer data for client ${client.clientId}:`,
|
||||||
);
|
error
|
||||||
}
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(olmJobs);
|
await Promise.all(olmJobs);
|
||||||
|
|||||||
Reference in New Issue
Block a user