send if we need to connect to the gerbil or not

This commit is contained in:
Owen
2026-07-31 10:54:18 -04:00
parent 45623ce36b
commit 97a1bc3697
4 changed files with 33 additions and 13 deletions
+3
View File
@@ -428,6 +428,9 @@ export const siteResources = pgTable(
onDelete: "restrict" onDelete: "restrict"
} }
), ),
requiresExitNodeConnection: boolean("requiresExitNodeConnection")
.notNull()
.default(false),
niceId: varchar("niceId").notNull(), niceId: varchar("niceId").notNull(),
name: varchar("name").notNull(), name: varchar("name").notNull(),
ssl: boolean("ssl").notNull().default(false), ssl: boolean("ssl").notNull().default(false),
+5
View File
@@ -425,6 +425,11 @@ export const siteResources = sqliteTable("siteResources", {
() => networks.networkId, () => networks.networkId,
{ onDelete: "restrict" } { onDelete: "restrict" }
), ),
requiresExitNodeConnection: integer("requiresExitNodeConnection", {
mode: "boolean"
})
.notNull()
.default(false),
niceId: text("niceId").notNull(), niceId: text("niceId").notNull(),
name: text("name").notNull(), name: text("name").notNull(),
ssl: integer("ssl", { mode: "boolean" }).notNull().default(false), ssl: integer("ssl", { mode: "boolean" }).notNull().default(false),
+15 -7
View File
@@ -48,10 +48,6 @@ export async function buildSiteConfigurationForOlmClient(
) )
.where(eq(clientSitesAssociationsCache.clientId, client.clientId)); .where(eq(clientSitesAssociationsCache.clientId, client.clientId));
if (sitesData.length === 0) {
return siteConfigurations;
}
// Batch-fetch every site resource this client has access to across ALL sites // Batch-fetch every site resource this client has access to across ALL sites
// in a single query, then group by siteId in memory. This avoids issuing one // in a single query, then group by siteId in memory. This avoids issuing one
// query per site (which would be N round-trips for N sites). // query per site (which would be N round-trips for N sites).
@@ -68,8 +64,8 @@ export async function buildSiteConfigurationForOlmClient(
clientSiteResourcesAssociationsCache.siteResourceId clientSiteResourcesAssociationsCache.siteResourceId
) )
) )
.innerJoin(networks, eq(siteResources.networkId, networks.networkId)) .leftJoin(networks, eq(siteResources.networkId, networks.networkId))
.innerJoin(siteNetworks, eq(networks.networkId, siteNetworks.networkId)) .leftJoin(siteNetworks, eq(networks.networkId, siteNetworks.networkId))
.where( .where(
and( and(
eq( eq(
@@ -80,8 +76,20 @@ export async function buildSiteConfigurationForOlmClient(
) )
); );
const haveInferenceResources = allClientSiteResources.some(
(row) => row.siteResource.requiresExitNodeConnection === true
);
if (sitesData.length === 0) {
return { siteConfigurations, haveInferenceResources };
}
const siteResourcesBySiteId = new Map<number, SiteResource[]>(); const siteResourcesBySiteId = new Map<number, SiteResource[]>();
for (const row of allClientSiteResources) { for (const row of allClientSiteResources) {
if (!row.siteId) {
// because we are doing a leftJoin above to get the inference resources without a network / sites
continue;
}
const arr = siteResourcesBySiteId.get(row.siteId); const arr = siteResourcesBySiteId.get(row.siteId);
if (arr) { if (arr) {
arr.push(row.siteResource); arr.push(row.siteResource);
@@ -226,5 +234,5 @@ export async function buildSiteConfigurationForOlmClient(
}); });
} }
return siteConfigurations; return { siteConfigurations, haveInferenceResources };
} }
+10 -6
View File
@@ -337,6 +337,8 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
return; return;
} }
// TODO: IF WE DO NOT HAVE AN INFERENCE RESOURCE DO WE NEED TO BE HOLDING A SUBNET ON THE CLIENT?
const newSubnet = await getUniqueSubnetForExitNode(exitNode); const newSubnet = await getUniqueSubnetForExitNode(exitNode);
if (!newSubnet) { if (!newSubnet) {
@@ -452,12 +454,13 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
// NOTE: its important that the client here is the old client and the public key is the new key // NOTE: its important that the client here is the old client and the public key is the new key
await waitForClientRebuildIdle(olm.clientId); await waitForClientRebuildIdle(olm.clientId);
const siteConfigurations = await buildSiteConfigurationForOlmClient( const { siteConfigurations, haveInferenceResources } =
client, await buildSiteConfigurationForOlmClient(
publicKey, client,
relay, publicKey,
jitMode relay,
); jitMode
);
// Return connect message with all site configurations // Return connect message with all site configurations
return { return {
@@ -470,6 +473,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
exitNode: exitNode:
exitNode && client.exitNodeSubnet exitNode && client.exitNodeSubnet
? { ? {
connect: haveInferenceResources, // we do not need to connect to the exit node if we do not have inference resources
endpoint: `${exitNode.endpoint}:${exitNode.listenPort}`, endpoint: `${exitNode.endpoint}:${exitNode.listenPort}`,
relayPort: relayPort:
config.getRawConfig().gerbil config.getRawConfig().gerbil