From e57574ba9c91a62092a10ee9c7eb9a43e9ea96f7 Mon Sep 17 00:00:00 2001 From: Owen Date: Fri, 11 Apr 2025 10:33:20 -0400 Subject: [PATCH] Solve olm not having chance to send hp message --- server/routers/gerbil/updateHolePunch.ts | 55 ++++++++++--------- .../routers/olm/handleOlmRegisterMessage.ts | 3 +- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/server/routers/gerbil/updateHolePunch.ts b/server/routers/gerbil/updateHolePunch.ts index 8d57d032..910b2900 100644 --- a/server/routers/gerbil/updateHolePunch.ts +++ b/server/routers/gerbil/updateHolePunch.ts @@ -45,12 +45,13 @@ export async function updateHolePunch( const { olmId, newtId, ip, port, timestamp, token } = parsedParams.data; - // logger.debug(`Got hole punch with ip: ${ip}, port: ${port} for olmId: ${olmId} or newtId: ${newtId}`); - + let currentSiteId: number | undefined; let destinations: PeerDestination[] = []; - + if (olmId) { + logger.debug(`Got hole punch with ip: ${ip}, port: ${port} for olmId: ${olmId}`); + const { session, olm: olmSession } = await validateOlmSessionToken(token); if (!session || !olmSession) { @@ -197,33 +198,33 @@ export async function updateHolePunch( } // If this is a newt/site, also add other sites in the same org - if (updatedSite.orgId) { - const orgSites = await db - .select() - .from(sites) - .where(eq(sites.orgId, updatedSite.orgId)); + // if (updatedSite.orgId) { + // const orgSites = await db + // .select() + // .from(sites) + // .where(eq(sites.orgId, updatedSite.orgId)); - for (const site of orgSites) { - // Don't add the current site to the destinations - if (site.siteId !== currentSiteId && site.subnet && site.endpoint && site.listenPort) { - const [host, portStr] = site.endpoint.split(':'); - if (host && portStr) { - destinations.push({ - destinationIP: host, - destinationPort: site.listenPort - }); - } - } - } - } + // for (const site of orgSites) { + // // Don't add the current site to the destinations + // if (site.siteId !== currentSiteId && site.subnet && site.endpoint && site.listenPort) { + // const [host, portStr] = site.endpoint.split(':'); + // if (host && portStr) { + // destinations.push({ + // destinationIP: host, + // destinationPort: site.listenPort + // }); + // } + // } + // } + // } } - if (destinations.length === 0) { - logger.warn( - `No peer destinations found for olmId: ${olmId} or newtId: ${newtId}` - ); - return next(createHttpError(HttpCode.NOT_FOUND, "No peer destinations found")); - } + // if (destinations.length === 0) { + // logger.warn( + // `No peer destinations found for olmId: ${olmId} or newtId: ${newtId}` + // ); + // return next(createHttpError(HttpCode.NOT_FOUND, "No peer destinations found")); + // } // Return the new multi-peer structure return res.status(HttpCode.OK).send({ diff --git a/server/routers/olm/handleOlmRegisterMessage.ts b/server/routers/olm/handleOlmRegisterMessage.ts index c8e12f9c..7cbf5a2b 100644 --- a/server/routers/olm/handleOlmRegisterMessage.ts +++ b/server/routers/olm/handleOlmRegisterMessage.ts @@ -63,8 +63,9 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => { }); } - if (client.lastHolePunch && now - client.lastHolePunch > 6) { + if (now - (client.lastHolePunch || 0) > 6) { logger.warn("Client last hole punch is too old, skipping all sites"); + return; } // Update the client's public key