Seperating out functions

This commit is contained in:
Owen
2025-12-24 11:50:27 -05:00
parent e2dfc3eb20
commit 0ccd5714f9
6 changed files with 304 additions and 163 deletions

View File

@@ -7,7 +7,7 @@ import config from "@server/lib/config";
export async function buildSiteConfigurationForOlmClient(
client: Client,
publicKey: string,
publicKey: string | null,
relay: boolean
) {
const siteConfigurations = [];
@@ -74,7 +74,7 @@ export async function buildSiteConfigurationForOlmClient(
.limit(1);
// Add the peer to the exit node for this site
if (clientSite.endpoint) {
if (clientSite.endpoint && publicKey) {
logger.info(
`Adding peer ${publicKey} to site ${site.siteId} with endpoint ${clientSite.endpoint}`
);

View File

@@ -174,6 +174,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
return;
}
// NOTE: its important that the client here is the old client and the public key is the new key
const siteConfigurations = await buildSiteConfigurationForOlmClient(client, publicKey, relay);
// REMOVED THIS SO IT CREATES THE INTERFACE AND JUST WAITS FOR THE SITES

View File

@@ -1,7 +1,18 @@
import { Client, Olm } from "@server/db";
import { buildSiteConfigurationForOlmClient } from "./buildSiteConfigurationForOlmClient";
import { sendToClient } from "#dynamic/routers/ws";
import logger from "@server/logger";
export async function sendOlmSyncMessage(olm: Olm, client: Client) {
const siteConfigurations = await buildSiteConfigurationForOlmClient(client, publicKey, relay);
// NOTE: WE ARE HARDCODING THE RELAY PARAMETER TO FALSE HERE BUT IN THE REGISTER MESSAGE ITS DEFINED BY THE CLIENT
const siteConfigurations = await buildSiteConfigurationForOlmClient(client, client.pubKey, false);
await sendToClient(olm.olmId, {
type: "olm/sync",
data: {
sites: siteConfigurations
}
}).catch((error) => {
logger.warn(`Error sending olm sync message:`, error);
});
}