Move up client reject

This commit is contained in:
Owen
2025-04-01 22:49:08 -04:00
parent 8c267489c7
commit 7faf1fba8b

View File

@@ -13,9 +13,12 @@ import { addPeer, deletePeer } from "../newt/peers";
import logger from "@server/logger"; import logger from "@server/logger";
export const handleOlmRegisterMessage: MessageHandler = async (context) => { export const handleOlmRegisterMessage: MessageHandler = async (context) => {
logger.info("Handling register olm message!");
const { message, client: c, sendToClient } = context; const { message, client: c, sendToClient } = context;
const olm = c as Olm; const olm = c as Olm;
logger.info("Handling register olm message!");
const now = new Date().getTime() / 1000;
if (!olm) { if (!olm) {
logger.warn("Olm not found"); logger.warn("Olm not found");
return; return;
@@ -50,7 +53,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
.from(exitNodes) .from(exitNodes)
.where(eq(exitNodes.exitNodeId, client.exitNodeId)) .where(eq(exitNodes.exitNodeId, client.exitNodeId))
.limit(1); .limit(1);
// Send holepunch message for each site // Send holepunch message for each site
sendToClient(olm.olmId, { sendToClient(olm.olmId, {
type: "olm/wg/holepunch", type: "olm/wg/holepunch",
@@ -60,6 +63,10 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
}); });
} }
if (client.lastHolePunch && now - client.lastHolePunch > 6) {
logger.warn("Client last hole punch is too old, skipping all sites");
}
// Update the client's public key // Update the client's public key
await db await db
.update(clients) .update(clients)
@@ -81,7 +88,6 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
// Prepare an array to store site configurations // Prepare an array to store site configurations
const siteConfigurations = []; const siteConfigurations = [];
const now = new Date().getTime() / 1000;
// Process each site // Process each site
for (const { sites: site } of sitesData) { for (const { sites: site } of sitesData) {
@@ -105,13 +111,6 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
continue; continue;
} }
if (client.lastHolePunch && now - client.lastHolePunch > 6) {
logger.warn(
"Client last hole punch is too old, skipping all sites"
);
break;
}
// If public key changed, delete old peer from this site // If public key changed, delete old peer from this site
if (pubKeyChanged) { if (pubKeyChanged) {
logger.info( logger.info(
@@ -126,7 +125,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
} }
// Add the peer to the exit node for this site // Add the peer to the exit node for this site
if (client.endpoint) { if (client.endpoint) {
logger.info( logger.info(
`Adding peer ${publicKey} to site ${site.siteId} with endpoint ${client.endpoint}` `Adding peer ${publicKey} to site ${site.siteId} with endpoint ${client.endpoint}`
); );
@@ -138,7 +137,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
} else { } else {
logger.warn( logger.warn(
`Client ${client.clientId} has no endpoint, skipping peer addition` `Client ${client.clientId} has no endpoint, skipping peer addition`
); );
} }
// Add site configuration to the array // Add site configuration to the array