Use formatEndpoint where appropriate

Fixes fosrl/newt#454
This commit is contained in:
Owen
2026-09-24 14:34:54 -04:00
parent e68963b852
commit e92911e7c8
4 changed files with 8 additions and 9 deletions
+1 -1
View File
@@ -96,7 +96,7 @@ export async function buildClientConfigurationForNewtClient(
await updatePeer(client.clients.clientId, {
siteId: site.siteId,
endpoint: site.endpoint!,
relayEndpoint: `${exitNode.endpoint}:${config.getRawConfig().gerbil.clients_start_port}`,
relayEndpoint: formatEndpoint(exitNode.endpoint, config.getRawConfig().gerbil.clients_start_port),
publicKey: site.publicKey!,
serverIP: site.address,
serverPort: site.listenPort
@@ -15,6 +15,7 @@ import { fetchContainers } from "./dockerSocket";
import { buildTargetConfigurationForNewtClient } from "./buildConfiguration";
import { canCompress } from "@server/lib/clientVersionChecks";
import { NewtErrorCodes, sendNewtError } from "./error";
import { formatEndpoint } from "@server/lib/ip";
export const handleNewtRegisterMessage: MessageHandler = async (context) => {
const { message, client, sendToClient } = context;
@@ -224,7 +225,7 @@ export const handleNewtRegisterMessage: MessageHandler = async (context) => {
message: {
type: "newt/wg/connect",
data: {
endpoint: `${exitNode.endpoint}:${exitNode.listenPort}`,
endpoint: formatEndpoint(exitNode.endpoint, exitNode.listenPort),
relayPort: config.getRawConfig().gerbil.clients_start_port,
publicKey: exitNode.publicKey,
serverIP: exitNode.address.split("/")[0],
+3 -6
View File
@@ -4,6 +4,7 @@ import logger from "@server/logger";
import { canCompress } from "@server/lib/clientVersionChecks";
import { decrypt } from "@server/lib/crypto";
import config from "@server/lib/config";
import { formatEndpoint } from "@server/lib/ip";
export async function addTargets(
newtId: string,
@@ -14,9 +15,7 @@ export async function addTargets(
) {
//create a list of udp and tcp targets
const payloadTargets = targets.map((target) => {
return `${target.internalPort ? target.internalPort + ":" : ""}${
target.ip
}:${target.port}`;
return `${target.internalPort ? target.internalPort + ":" : ""}${formatEndpoint(target.ip, target.port)}`;
});
if (payloadTargets.length > 0) {
@@ -208,9 +207,7 @@ export async function removeTargets(
) {
//create a list of udp and tcp targets
const payloadTargets = targets.map((target) => {
return `${target.internalPort ? target.internalPort + ":" : ""}${
target.ip
}:${target.port}`;
return `${target.internalPort ? target.internalPort + ":" : ""}${formatEndpoint(target.ip, target.port)}`;
});
if (payloadTargets.length > 0) {
@@ -30,6 +30,7 @@ import {
} from "#dynamic/lib/exitNodes";
import { getUniqueSubnetForExitNode } from "@server/lib/exitNodes";
import { addPeer, deletePeer } from "../gerbil/peers";
import { formatEndpoint } from "@server/lib/ip";
const HOLEPUNCH_STALE_CHAIN_THRESHOLD = 18;
const HOLEPUNCH_STALE_CHAIN_TTL_SECONDS = 1800;
@@ -508,7 +509,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
? {
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: `${exitNode.endpoint}:${exitNode.listenPort}`,
endpoint: formatEndpoint(exitNode.endpoint, exitNode.listenPort),
publicKey: exitNode.publicKey,
serverIP: exitNode.address.split("/")[0],
tunnelIP: `${clientSubnet.split("/")[0]}/${exitNode.address.split("/")[1]}` // we need to use the exit node's subnet mask here because the client will be using the exit node's subnet mask for its routing table so we can address it