Working on inference resource management

This commit is contained in:
Owen
2026-08-04 11:48:36 -04:00
parent a7e44944fb
commit 0b30cfc341
6 changed files with 87 additions and 29 deletions
+35 -8
View File
@@ -1,6 +1,7 @@
import {
Client,
db,
ExitNode,
exitNodes,
Olm,
sites,
@@ -48,12 +49,26 @@ export async function sendOlmSyncMessage(olm: Olm, client: Client) {
}
// 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,
jitMode
);
const { siteConfigurations, exitNodeAliases } =
await buildSiteConfigurationForOlmClient(
client,
client.pubKey,
false,
jitMode
);
// The exit node the client itself is assigned to (for site resources hosted
// on it, e.g. inference), same as what's sent in the initial olm/wg/connect
// message. This is separate from exitNodesData below, which is only the set
// of exit nodes used for hole punching to reach site peers.
let clientExitNode: ExitNode | null = null;
if (client.exitNodeId) {
[clientExitNode] = await db
.select()
.from(exitNodes)
.where(eq(exitNodes.exitNodeId, client.exitNodeId))
.limit(1);
}
// Get all exit nodes from sites where the client has peers
const clientSites = await db
@@ -113,11 +128,23 @@ export async function sendOlmSyncMessage(olm: Olm, client: Client) {
type: "olm/sync",
data: {
sites: siteConfigurations,
exitNodes: exitNodesData
exitNodes: exitNodesData, // this is for the holepunch information
// this is for the backhaul connection to the exit node
exitNode:
clientExitNode && client.exitNodeSubnet
? {
aliases: exitNodeAliases,
connect: exitNodeAliases.length > 0, // we do not need to connect to the exit node if we do not have inference resources and right now all site resources on the exit node have an alias
endpoint: `${clientExitNode.endpoint}:${clientExitNode.listenPort}`,
publicKey: clientExitNode.publicKey,
serverIP: clientExitNode.address.split("/")[0],
tunnelIP: client.exitNodeSubnet.split("/")[0]
}
: undefined
}
},
{
compress: canCompress(olm.version, "olm")
compress: canCompress(olm.version, "olm") // we dont increment the version here or we could get into a loop!
}
).catch((error) => {
logger.warn(`Error sending olm sync message:`, error);
@@ -571,7 +571,7 @@ export async function createSiteResource(
}
let tcpPortRangeStringAdjusted = tcpPortRangeString;
if (mode === "http") {
if (mode === "http" || mode === "inference") {
tcpPortRangeStringAdjusted = "443,80";
} else if (mode === "ssh") {
tcpPortRangeStringAdjusted = destinationPort
@@ -594,12 +594,14 @@ export async function createSiteResource(
aliasAddress,
tcpPortRangeString: tcpPortRangeStringAdjusted,
udpPortRangeString:
mode == "http" || mode == "ssh"
mode == "http" || mode == "ssh" || mode == "inference"
? ""
: udpPortRangeString,
disableIcmp:
disableIcmp ||
(mode == "http" || mode == "ssh" ? true : false), // default to true for http resources, otherwise false
(mode == "http" || mode == "ssh" || mode == "inference"
? true
: false), // default to true for http resources, otherwise false
domainId,
subdomain: finalSubdomain,
fullDomain,
@@ -166,8 +166,11 @@ const updateSiteResourceSchema = z
if (data.mode === undefined && data.destination === undefined) {
return true;
}
// destination is only optional for ssh mode with native authDaemonMode
if (data.mode === "ssh" && data.authDaemonMode === "native") {
// destination is only optional for ssh mode with native authDaemonMode or inference
if (
(data.mode === "ssh" && data.authDaemonMode === "native") ||
data.mode == "inference"
) {
return true;
}
return (
@@ -558,8 +561,9 @@ export async function updateSiteResource(
})
}
: {};
let tcpPortRangeStringAdjusted = tcpPortRangeString;
if (mode === "http") {
if (mode === "http" || mode == "inference") {
tcpPortRangeStringAdjusted = "443,80";
} else if (mode === "ssh") {
tcpPortRangeStringAdjusted = destinationPort
@@ -583,20 +587,20 @@ export async function updateSiteResource(
? alias
? alias.trim()
: null
: mode !== undefined &&
mode !== "host" &&
mode !== "ssh"
? null
: undefined,
: undefined,
tcpPortRangeString: tcpPortRangeStringAdjusted,
udpPortRangeString:
mode == "http" || mode == "ssh"
mode == "http" || mode == "ssh" || mode == "inference"
? ""
: udpPortRangeString,
disableIcmp:
mode !== undefined
? disableIcmp ||
(mode == "http" || mode == "ssh" ? true : false)
(mode == "http" ||
mode == "ssh" ||
mode == "inference"
? true
: false)
: disableIcmp,
domainId,
subdomain: finalSubdomain,