From beea28daf3932d51ddaa99eefb36978440739893 Mon Sep 17 00:00:00 2001 From: Owen Date: Mon, 1 Dec 2025 16:20:10 -0500 Subject: [PATCH] Handle hp oddities --- server/routers/gerbil/updateHolePunch.ts | 10 +++++++-- .../routers/olm/handleOlmRegisterMessage.ts | 21 ++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/server/routers/gerbil/updateHolePunch.ts b/server/routers/gerbil/updateHolePunch.ts index c5f0d2b8..208f3a98 100644 --- a/server/routers/gerbil/updateHolePunch.ts +++ b/server/routers/gerbil/updateHolePunch.ts @@ -230,7 +230,9 @@ export async function updateAndGenerateEndpointDestinations( .returning(); if ( - updatedClientSitesAssociationsCache.endpoint !== site.endpoint // this is the endpoint from the join table not the site + updatedClientSitesAssociationsCache.endpoint !== + site.endpoint && // this is the endpoint from the join table not the site + updatedClient.pubKey === publicKey // only trigger if the client's public key matches the current public key which means it has registered so we dont prematurely send the update ) { logger.info( `ClientSitesAssociationsCache for client ${olm.clientId} and site ${site.siteId} endpoint changed from ${site.endpoint} to ${updatedClientSitesAssociationsCache.endpoint}` @@ -318,7 +320,11 @@ export async function updateAndGenerateEndpointDestinations( .where(eq(sites.siteId, newt.siteId)) .returning(); - if (updatedSite.endpoint != site.endpoint) { + if ( + updatedSite.endpoint != site.endpoint && + updatedSite.publicKey == publicKey + ) { + // only trigger if the site's public key matches the current public key which means it has registered so we dont prematurely send the update logger.info( `Site ${newt.siteId} endpoint changed from ${site.endpoint} to ${updatedSite.endpoint}` ); diff --git a/server/routers/olm/handleOlmRegisterMessage.ts b/server/routers/olm/handleOlmRegisterMessage.ts index 6f3e59c1..7cde2c76 100644 --- a/server/routers/olm/handleOlmRegisterMessage.ts +++ b/server/routers/olm/handleOlmRegisterMessage.ts @@ -126,15 +126,6 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => { .where(eq(olms.olmId, olm.olmId)); } - // this prevents us from accepting a register from an olm that has not hole punched yet. - // the olm will pump the register so we can keep checking - if (now - (client.lastHolePunch || 0) > 5) { - logger.warn( - "Client last hole punch is too old; skipping this register" - ); - return; - } - if (client.pubKey !== publicKey) { logger.info( "Public key mismatch. Updating public key and clearing session info..." @@ -172,8 +163,18 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => { `Found ${sitesData.length} sites for client ${client.clientId}` ); + // this prevents us from accepting a register from an olm that has not hole punched yet. + // the olm will pump the register so we can keep checking + // TODO: I still think there is a better way to do this rather than locking it out here but ??? + if (now - (client.lastHolePunch || 0) > 5 && sitesData.length > 0) { + logger.warn( + "Client last hole punch is too old and we have sites to send; skipping this register" + ); + return; + } + // Process each site - for (const { sites: site } of sitesData) { + for (const { sites: site, clientSitesAssociationsCache: association } of sitesData) { if (!site.exitNodeId) { logger.warn( `Site ${site.siteId} does not have exit node, skipping`