mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-17 02:56:43 +02:00
Send localEndpoints on sites to olm
This commit is contained in:
@@ -133,7 +133,9 @@ export const handleNewtRegisterMessage: MessageHandler = async (context) => {
|
|||||||
pubKey: publicKey,
|
pubKey: publicKey,
|
||||||
exitNodeId: exitNodeId,
|
exitNodeId: exitNodeId,
|
||||||
subnet: newSubnet,
|
subnet: newSubnet,
|
||||||
localEndpoints: localEndpoints || null
|
localEndpoints: localEndpoints
|
||||||
|
? JSON.stringify(localEndpoints)
|
||||||
|
: null
|
||||||
})
|
})
|
||||||
.where(eq(sites.siteId, siteId))
|
.where(eq(sites.siteId, siteId))
|
||||||
.returning();
|
.returning();
|
||||||
@@ -142,7 +144,9 @@ export const handleNewtRegisterMessage: MessageHandler = async (context) => {
|
|||||||
.update(sites)
|
.update(sites)
|
||||||
.set({
|
.set({
|
||||||
pubKey: publicKey,
|
pubKey: publicKey,
|
||||||
localEndpoints: localEndpoints || null
|
localEndpoints: localEndpoints
|
||||||
|
? JSON.stringify(localEndpoints)
|
||||||
|
: null
|
||||||
})
|
})
|
||||||
.where(eq(sites.siteId, siteId))
|
.where(eq(sites.siteId, siteId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export async function buildSiteConfigurationForOlmClient(
|
|||||||
siteId: number;
|
siteId: number;
|
||||||
name?: string;
|
name?: string;
|
||||||
endpoint?: string;
|
endpoint?: string;
|
||||||
|
localEndpoints?: string[];
|
||||||
publicKey?: string;
|
publicKey?: string;
|
||||||
serverIP?: string | null;
|
serverIP?: string | null;
|
||||||
serverPort?: number | null;
|
serverPort?: number | null;
|
||||||
@@ -206,6 +207,9 @@ export async function buildSiteConfigurationForOlmClient(
|
|||||||
name: site.name,
|
name: site.name,
|
||||||
// relayEndpoint: relayEndpoint, // this can be undefined now if not relayed // lets not do this for now because it would conflict with the hole punch testing
|
// relayEndpoint: relayEndpoint, // this can be undefined now if not relayed // lets not do this for now because it would conflict with the hole punch testing
|
||||||
endpoint: site.endpoint,
|
endpoint: site.endpoint,
|
||||||
|
localEndpoints: site.localEndpoints
|
||||||
|
? JSON.parse(site.localEndpoints)
|
||||||
|
: undefined,
|
||||||
publicKey: site.publicKey,
|
publicKey: site.publicKey,
|
||||||
serverIP: site.address,
|
serverIP: site.address,
|
||||||
serverPort: site.listenPort,
|
serverPort: site.listenPort,
|
||||||
|
|||||||
@@ -3,24 +3,15 @@ import {
|
|||||||
db,
|
db,
|
||||||
networks,
|
networks,
|
||||||
siteNetworks,
|
siteNetworks,
|
||||||
siteResources,
|
siteResources
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
import { MessageHandler } from "@server/routers/ws";
|
import { MessageHandler } from "@server/routers/ws";
|
||||||
import {
|
import { clients, clientSitesAssociationsCache, Olm, sites } from "@server/db";
|
||||||
clients,
|
|
||||||
clientSitesAssociationsCache,
|
|
||||||
Olm,
|
|
||||||
sites
|
|
||||||
} from "@server/db";
|
|
||||||
import { and, eq, inArray, isNotNull, isNull } from "drizzle-orm";
|
import { and, eq, inArray, isNotNull, isNull } from "drizzle-orm";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import {
|
import { generateAliasConfig } from "@server/lib/ip";
|
||||||
generateAliasConfig,
|
|
||||||
} from "@server/lib/ip";
|
|
||||||
import { generateRemoteSubnets } from "@server/lib/ip";
|
import { generateRemoteSubnets } from "@server/lib/ip";
|
||||||
import {
|
import { addPeer as newtAddPeer } from "@server/routers/newt/peers";
|
||||||
addPeer as newtAddPeer,
|
|
||||||
} from "@server/routers/newt/peers";
|
|
||||||
|
|
||||||
export const handleOlmServerPeerAddMessage: MessageHandler = async (
|
export const handleOlmServerPeerAddMessage: MessageHandler = async (
|
||||||
context
|
context
|
||||||
@@ -135,10 +126,7 @@ export const handleOlmServerPeerAddMessage: MessageHandler = async (
|
|||||||
clientSiteResourcesAssociationsCache.siteResourceId
|
clientSiteResourcesAssociationsCache.siteResourceId
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.innerJoin(
|
.innerJoin(networks, eq(siteResources.networkId, networks.networkId))
|
||||||
networks,
|
|
||||||
eq(siteResources.networkId, networks.networkId)
|
|
||||||
)
|
|
||||||
.innerJoin(
|
.innerJoin(
|
||||||
siteNetworks,
|
siteNetworks,
|
||||||
and(
|
and(
|
||||||
@@ -147,10 +135,7 @@ export const handleOlmServerPeerAddMessage: MessageHandler = async (
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.where(
|
.where(
|
||||||
eq(
|
eq(clientSiteResourcesAssociationsCache.clientId, client.clientId)
|
||||||
clientSiteResourcesAssociationsCache.clientId,
|
|
||||||
client.clientId
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Return connect message with all site configurations
|
// Return connect message with all site configurations
|
||||||
@@ -161,6 +146,9 @@ export const handleOlmServerPeerAddMessage: MessageHandler = async (
|
|||||||
siteId: site.siteId,
|
siteId: site.siteId,
|
||||||
name: site.name,
|
name: site.name,
|
||||||
endpoint: site.endpoint,
|
endpoint: site.endpoint,
|
||||||
|
localEndpoints: site.localEndpoints
|
||||||
|
? JSON.parse(site.localEndpoints)
|
||||||
|
: undefined,
|
||||||
publicKey: site.publicKey,
|
publicKey: site.publicKey,
|
||||||
serverIP: site.address,
|
serverIP: site.address,
|
||||||
serverPort: site.listenPort,
|
serverPort: site.listenPort,
|
||||||
@@ -170,7 +158,7 @@ export const handleOlmServerPeerAddMessage: MessageHandler = async (
|
|||||||
aliases: generateAliasConfig(
|
aliases: generateAliasConfig(
|
||||||
allSiteResources.map(({ siteResources }) => siteResources)
|
allSiteResources.map(({ siteResources }) => siteResources)
|
||||||
),
|
),
|
||||||
chainId: chainId,
|
chainId: chainId
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
broadcast: false,
|
broadcast: false,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export async function addPeer(
|
|||||||
serverPort: number | null;
|
serverPort: number | null;
|
||||||
remoteSubnets: string[] | null; // optional, comma-separated list of subnets that this site can access
|
remoteSubnets: string[] | null; // optional, comma-separated list of subnets that this site can access
|
||||||
aliases: Alias[];
|
aliases: Alias[];
|
||||||
|
localEndpoints?: string[]; // optional, list of local endpoints for the peer
|
||||||
},
|
},
|
||||||
olmId?: string,
|
olmId?: string,
|
||||||
version?: string | null
|
version?: string | null
|
||||||
@@ -44,6 +45,7 @@ export async function addPeer(
|
|||||||
name: peer.name,
|
name: peer.name,
|
||||||
publicKey: peer.publicKey,
|
publicKey: peer.publicKey,
|
||||||
endpoint: peer.endpoint,
|
endpoint: peer.endpoint,
|
||||||
|
localEndpoints: peer.localEndpoints,
|
||||||
relayEndpoint: peer.relayEndpoint,
|
relayEndpoint: peer.relayEndpoint,
|
||||||
serverIP: peer.serverIP,
|
serverIP: peer.serverIP,
|
||||||
serverPort: peer.serverPort,
|
serverPort: peer.serverPort,
|
||||||
|
|||||||
Reference in New Issue
Block a user