From 23e9a61f3ea48342d96f426d1f6cd0dc253dd04d Mon Sep 17 00:00:00 2001 From: Owen Date: Tue, 9 Dec 2025 10:31:43 -0500 Subject: [PATCH] Fixing various bugs --- server/lib/blueprints/proxyResources.ts | 6 ++---- server/lib/ip.ts | 6 +++--- server/routers/gerbil/receiveBandwidth.ts | 25 +++++++++++++++-------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/server/lib/blueprints/proxyResources.ts b/server/lib/blueprints/proxyResources.ts index 738a833f..706fab12 100644 --- a/server/lib/blueprints/proxyResources.ts +++ b/server/lib/blueprints/proxyResources.ts @@ -1086,10 +1086,8 @@ async function getDomainId( // remove the base domain of the domain let subdomain = null; - if (domainSelection.type == "ns" || domainSelection.type == "wildcard") { - if (fullDomain != baseDomain) { - subdomain = fullDomain.replace(`.${baseDomain}`, ""); - } + if (fullDomain != baseDomain) { + subdomain = fullDomain.replace(`.${baseDomain}`, ""); } // Return the first valid domain diff --git a/server/lib/ip.ts b/server/lib/ip.ts index d367a018..3949a5f6 100644 --- a/server/lib/ip.ts +++ b/server/lib/ip.ts @@ -247,7 +247,7 @@ export async function getNextAvailableClientSubnet( orgId: string, transaction: Transaction | typeof db = db ): Promise { - const [org] = await db.select().from(orgs).where(eq(orgs.orgId, orgId)); + const [org] = await transaction.select().from(orgs).where(eq(orgs.orgId, orgId)); if (!org) { throw new Error(`Organization with ID ${orgId} not found`); @@ -257,14 +257,14 @@ export async function getNextAvailableClientSubnet( throw new Error(`Organization with ID ${orgId} has no subnet defined`); } - const existingAddressesSites = await db + const existingAddressesSites = await transaction .select({ address: sites.address }) .from(sites) .where(and(isNotNull(sites.address), eq(sites.orgId, orgId))); - const existingAddressesClients = await db + const existingAddressesClients = await transaction .select({ address: clients.subnet }) diff --git a/server/routers/gerbil/receiveBandwidth.ts b/server/routers/gerbil/receiveBandwidth.ts index 297e7c02..5c9cacb2 100644 --- a/server/routers/gerbil/receiveBandwidth.ts +++ b/server/routers/gerbil/receiveBandwidth.ts @@ -160,12 +160,20 @@ export async function updateSiteBandwidth( // Aggregate bandwidth usage for the org const totalBandwidth = peer.bytesIn + peer.bytesOut; - const currentOrgUsage = orgUsageMap.get(updatedSite.orgId) || 0; - orgUsageMap.set(updatedSite.orgId, currentOrgUsage + totalBandwidth); + const currentOrgUsage = + orgUsageMap.get(updatedSite.orgId) || 0; + orgUsageMap.set( + updatedSite.orgId, + currentOrgUsage + totalBandwidth + ); // Add 10 seconds of uptime for each active site - const currentOrgUptime = orgUptimeMap.get(updatedSite.orgId) || 0; - orgUptimeMap.set(updatedSite.orgId, currentOrgUptime + 10 / 60); + const currentOrgUptime = + orgUptimeMap.get(updatedSite.orgId) || 0; + orgUptimeMap.set( + updatedSite.orgId, + currentOrgUptime + 10 / 60 + ); } } catch (error) { logger.error( @@ -181,7 +189,9 @@ export async function updateSiteBandwidth( // This separates the concerns and reduces lock contention if (calcUsageAndLimits && (orgUsageMap.size > 0 || orgUptimeMap.size > 0)) { // Sort org IDs to ensure consistent lock ordering - const allOrgIds = [...new Set([...orgUsageMap.keys(), ...orgUptimeMap.keys()])].sort(); + const allOrgIds = [ + ...new Set([...orgUsageMap.keys(), ...orgUptimeMap.keys()]) + ].sort(); for (const orgId of allOrgIds) { try { @@ -237,10 +247,7 @@ export async function updateSiteBandwidth( } } } catch (error) { - logger.error( - `Error processing usage for org ${orgId}:`, - error - ); + logger.error(`Error processing usage for org ${orgId}:`, error); // Continue with other orgs } }