mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-31 16:14:46 +02:00
Fix issues with relaying and holepunching
This commit is contained in:
parent
4b6985718a
commit
a665e3aae9
5 changed files with 10 additions and 15 deletions
|
@ -97,7 +97,7 @@ export async function pickClientDefaults(
|
||||||
|
|
||||||
let subnets = clientsQuery.map((client) => client.subnet);
|
let subnets = clientsQuery.map((client) => client.subnet);
|
||||||
|
|
||||||
// exclude the exit node address by replacing after the / with a site block size
|
// exclude the newt address by replacing after the / with a site block size
|
||||||
subnets.push(
|
subnets.push(
|
||||||
address.replace(
|
address.replace(
|
||||||
/\/\d+$/,
|
/\/\d+$/,
|
||||||
|
|
|
@ -133,7 +133,7 @@ export async function updateHolePunch(
|
||||||
|
|
||||||
return res.status(HttpCode.OK).send({
|
return res.status(HttpCode.OK).send({
|
||||||
destinationIp: site.subnet.split("/")[0],
|
destinationIp: site.subnet.split("/")[0],
|
||||||
destinationPort: parseInt(site.endpoint.split(":")[1])
|
destinationPort: site.listenPort
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import config from "@server/lib/config";
|
||||||
|
|
||||||
const inputSchema = z.object({
|
const inputSchema = z.object({
|
||||||
publicKey: z.string(),
|
publicKey: z.string(),
|
||||||
|
port: z.number().int().positive(),
|
||||||
});
|
});
|
||||||
|
|
||||||
type Input = z.infer<typeof inputSchema>;
|
type Input = z.infer<typeof inputSchema>;
|
||||||
|
@ -41,7 +42,7 @@ export const handleGetConfigMessage: MessageHandler = async (context) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { publicKey } = message.data as Input;
|
const { publicKey, port } = message.data as Input;
|
||||||
|
|
||||||
const siteId = newt.siteId;
|
const siteId = newt.siteId;
|
||||||
|
|
||||||
|
@ -58,7 +59,6 @@ export const handleGetConfigMessage: MessageHandler = async (context) => {
|
||||||
let site: Site | undefined;
|
let site: Site | undefined;
|
||||||
if (!siteRes.address) {
|
if (!siteRes.address) {
|
||||||
const address = await getNextAvailableSubnet();
|
const address = await getNextAvailableSubnet();
|
||||||
const listenPort = await getNextAvailablePort();
|
|
||||||
|
|
||||||
// create a new exit node
|
// create a new exit node
|
||||||
const [updateRes] = await db
|
const [updateRes] = await db
|
||||||
|
@ -66,7 +66,7 @@ export const handleGetConfigMessage: MessageHandler = async (context) => {
|
||||||
.set({
|
.set({
|
||||||
publicKey,
|
publicKey,
|
||||||
address,
|
address,
|
||||||
listenPort
|
listenPort: port,
|
||||||
})
|
})
|
||||||
.where(eq(sites.siteId, siteId))
|
.where(eq(sites.siteId, siteId))
|
||||||
.returning();
|
.returning();
|
||||||
|
@ -79,7 +79,8 @@ export const handleGetConfigMessage: MessageHandler = async (context) => {
|
||||||
const [siteRes] = await db
|
const [siteRes] = await db
|
||||||
.update(sites)
|
.update(sites)
|
||||||
.set({
|
.set({
|
||||||
publicKey
|
publicKey,
|
||||||
|
listenPort: port,
|
||||||
})
|
})
|
||||||
.where(eq(sites.siteId, siteId))
|
.where(eq(sites.siteId, siteId))
|
||||||
.returning();
|
.returning();
|
||||||
|
@ -116,7 +117,6 @@ export const handleGetConfigMessage: MessageHandler = async (context) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
const configResponse = {
|
const configResponse = {
|
||||||
listenPort: site.listenPort,
|
|
||||||
ipAddress: site.address,
|
ipAddress: site.address,
|
||||||
peers
|
peers
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,13 +67,8 @@ export const handleOlmRelayMessage: MessageHandler = async (context) => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
message: {
|
message: {
|
||||||
type: "olm/wg/connect",
|
type: "olm/wg/relay-success",
|
||||||
data: {
|
data: {}
|
||||||
endpoint: site.endpoint,
|
|
||||||
publicKey: site.publicKey,
|
|
||||||
serverIP: site.address!.split("/")[0],
|
|
||||||
tunnelIP: client.subnet
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
broadcast: false, // Send to all olms
|
broadcast: false, // Send to all olms
|
||||||
excludeSender: false // Include sender in broadcast
|
excludeSender: false // Include sender in broadcast
|
||||||
|
|
|
@ -324,7 +324,7 @@ PersistentKeepalive = 5`;
|
||||||
|
|
||||||
let payload: CreateSiteBody = {
|
let payload: CreateSiteBody = {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
type: data.method
|
type: data.method as any,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (data.method == "wireguard") {
|
if (data.method == "wireguard") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue