| author | |
| committer | |
| log | d559ec390582fe4bd7e029097434273bbe1ddd9b |
| tree | 897212ae55cce903824bc68a6d7ac3c30f1b48ef |
| parent | 1e32e2ab9fc916bbdefd5efe7a151e083345c19f |
Publish a separate native UDP port and route the Phoenix VM tailnet address to it. Share the fixed endpoint relay with the guest and preserve the existing voice hostname and Pion listener.
Assisted-by: gpt-6.2-sol6 files changed, 73 insertions(+), 4 deletions(-)
nixos/snowglobe.nix+13-1| ... | ... | @@ -7,7 +7,7 @@ let |
| 7 | 7 | xmppUDPPorts = [ xmppNetwork.turn xmppNetwork.turn_tls ]; |
| 8 | 8 | irohNetwork = builtins.fromJSON (builtins.readFile ../service/iroh-relay/network.json); |
| 9 | 9 | spacebarVoice = builtins.fromJSON (builtins.readFile ../service/spacebar/voice-network.json); |
| 10 | udpPorts = xmppUDPPorts ++ [ irohNetwork.quic spacebarVoice.media ]; | |
| 10 | udpPorts = xmppUDPPorts ++ [ irohNetwork.quic spacebarVoice.media spacebarVoice.nativeMedia ]; | |
| 11 | 11 | encryptionRoots = { |
| 12 | 12 | clover = "clover"; |
| 13 | 13 | media = "clover/Media"; |
| ... | ... | @@ -40,6 +40,18 @@ in |
| 40 | 40 | reverse_proxy 127.0.0.1:${toString spacebarVoice.signaling} |
| 41 | 41 | ''; |
| 42 | 42 | |
| 43 | systemd.services.phoenix-voice-udp-relay = { | |
| 44 | wantedBy = [ "multi-user.target" ]; | |
| 45 | wants = [ "network-online.target" ]; | |
| 46 | after = [ "network-online.target" "nomad.service" ]; | |
| 47 | serviceConfig = { | |
| 48 | DynamicUser = true; | |
| 49 | ExecStart = "${pkgs.nodejs_24}/bin/node ${../tools/phoenix-voice-udp-relay.mjs} ${spacebarVoice.phoenixRelayAddress} ${(builtins.head config.networking.interfaces.enp4s0.ipv4.addresses).address} ${toString spacebarVoice.nativeMedia}"; | |
| 50 | Restart = "always"; | |
| 51 | RestartSec = 5; | |
| 52 | }; | |
| 53 | }; | |
| 54 | ||
| 43 | 55 | systemd.services.public-ports = { |
| 44 | 56 | wantedBy = [ "multi-user.target" ]; |
| 45 | 57 | wants = [ "network-online.target" ]; |
service/spacebar/build/supervisor.mjs+6-1| ... | ... | @@ -9,7 +9,7 @@ import { createInterface } from "node:readline"; |
| 9 | 9 | import { setTimeout as sleep } from "node:timers/promises"; |
| 10 | 10 | import { promisify } from "node:util"; |
| 11 | 11 | |
| 12 | const { BRANCH, PORT, VOICE_PUBLIC_HOST, VOICE_SIGNALING_PORT, VOICE_MEDIA_PORT } = process.env; | |
| 12 | const { BRANCH, PORT, VOICE_PUBLIC_HOST, VOICE_SIGNALING_PORT, VOICE_MEDIA_PORT, VOICE_NATIVE_MEDIA_PORT } = process.env; | |
| 13 | 13 | const WORK = "/work"; |
| 14 | 14 | const REPO = "/source.git"; |
| 15 | 15 | const POLL_MS = 250; |
| ... | ... | @@ -231,6 +231,11 @@ async function startVoice(release) { |
| 231 | 231 | WRTC_PUBLIC_IP: ip, |
| 232 | 232 | WRTC_PORT_MIN: VOICE_MEDIA_PORT, |
| 233 | 233 | WRTC_PORT_MAX: VOICE_MEDIA_PORT, |
| 234 | ...(VOICE_NATIVE_MEDIA_PORT ? { | |
| 235 | VOICE_UDP_PORT: VOICE_NATIVE_MEDIA_PORT, | |
| 236 | VOICE_UDP_PUBLIC_IP: ip, | |
| 237 | VOICE_UDP_LOOPBACK_RELAY: "true", | |
| 238 | } : {}), | |
| 234 | 239 | }); |
| 235 | 240 | await waitForVoice(voice.signaling, () => fetch(`http://127.0.0.1:${VOICE_SIGNALING_PORT}/`, { |
| 236 | 241 | signal: AbortSignal.timeout(1000), |
service/spacebar/service.pkl+2| ... | ... | @@ -41,6 +41,7 @@ container { |
| 41 | 41 | when (!site.preview) { |
| 42 | 42 | new { name = "voice"; containerPort = voice.signaling; hostPort = containerPort } |
| 43 | 43 | new { name = "voice-media"; containerPort = voice.media; hostPort = containerPort; loopback = false } |
| 44 | new { name = "voice-native-media"; containerPort = voice.nativeMedia; hostPort = containerPort; loopback = false } | |
| 44 | 45 | } |
| 45 | 46 | } |
| 46 | 47 | |
| ... | ... | @@ -64,6 +65,7 @@ container { |
| 64 | 65 | ["VOICE_PUBLIC_HOST"] = voiceHost |
| 65 | 66 | ["VOICE_SIGNALING_PORT"] = voice.signaling.toString() |
| 66 | 67 | ["VOICE_MEDIA_PORT"] = voice.media.toString() |
| 68 | ["VOICE_NATIVE_MEDIA_PORT"] = voice.nativeMedia.toString() | |
| 67 | 69 | } |
| 68 | 70 | } |
| 69 | 71 |
service/spacebar/voice-network.json+3-1| ... | ... | @@ -1,5 +1,7 @@ |
| 1 | 1 | { |
| 2 | 2 | "subdomain": "voice.phoenix-selfhosted", |
| 3 | 3 | "signaling": 17404, |
| 4 | "media": 6000 | |
| 4 | "media": 6000, | |
| 5 | "nativeMedia": 6001, | |
| 6 | "phoenixRelayAddress": "100.64.0.1" | |
| 5 | 7 | } |
tools/phoenix-voice-udp-relay.mjs created+41| ... | ... | @@ -0,0 +1,41 @@ |
| 1 | import { createSocket } from "node:dgram"; | |
| 2 | import { isIPv4 } from "node:net"; | |
| 3 | ||
| 4 | const [listenAddress, upstreamAddress, configuredPort] = process.argv.slice(2); | |
| 5 | const port = Number(configuredPort); | |
| 6 | if (!isIPv4(listenAddress ?? "") || !isIPv4(upstreamAddress ?? "") || listenAddress === upstreamAddress || | |
| 7 | listenAddress === "0.0.0.0" || upstreamAddress === "0.0.0.0" || !Number.isInteger(port) || port < 1 || port > 65535) { | |
| 8 | throw new Error("Expected distinct local and upstream IPv4 addresses and a fixed shared UDP port"); | |
| 9 | } | |
| 10 | ||
| 11 | const listener = createSocket("udp4"); | |
| 12 | const clients = new Map(); | |
| 13 | ||
| 14 | listener.on("message", (packet, remote) => { | |
| 15 | if (!packet.length || packet.length > 4096) return; | |
| 16 | const key = `${remote.address}:${remote.port}`; | |
| 17 | let client = clients.get(key); | |
| 18 | if (!client) { | |
| 19 | if (clients.size >= 64) return; | |
| 20 | const socket = createSocket("udp4"); | |
| 21 | const close = () => { | |
| 22 | clients.delete(key); | |
| 23 | clearTimeout(idle); | |
| 24 | socket.close(); | |
| 25 | }; | |
| 26 | const idle = setTimeout(close, 300_000).unref(); | |
| 27 | client = { socket, idle }; | |
| 28 | clients.set(key, client); | |
| 29 | // Keep the upstream tuple stable for this caller's discovery and media. | |
| 30 | socket.on("message", (reply, source) => { | |
| 31 | if (source.address !== upstreamAddress || source.port !== port || reply.length > 4096) return; | |
| 32 | idle.refresh(); | |
| 33 | if (listener.getSendQueueCount() < 64) listener.send(reply, remote.port, remote.address, () => {}); | |
| 34 | }); | |
| 35 | socket.once("error", close); | |
| 36 | } | |
| 37 | client.idle.refresh(); | |
| 38 | if (client.socket.getSendQueueCount() < 64) client.socket.send(packet, port, upstreamAddress, () => {}); | |
| 39 | }); | |
| 40 | ||
| 41 | listener.bind(port, listenAddress); |
tools/spacebar.md+8-1| ... | ... | @@ -54,10 +54,17 @@ start that is still waiting. Rolling back is pushing the old commit again. |
| 54 | 54 | |
| 55 | 55 | The production service publishes the voice WebSocket at `voice.phoenix-selfhosted.paperclover.net:443`. |
| 56 | 56 | [`voice-network.json`](../service/spacebar/voice-network.json) configures the |
| 57 | loopback WebSocket mapping and the UDP media port. The supervisor builds Pion | |
| 57 | WebSocket port and separate UDP ports for Pion and native Discord voice. The supervisor builds Pion | |
| 58 | 58 | from the Snowcord revision's `flake.lock`: git fetches the pinned commit, `go.sum` |
| 59 | 59 | pins the modules, and the build and SFU run with a minimal environment. The binary |
| 60 | 60 | is kept in `/work` for that pin, so a restart needs no network. |
| 61 | 61 | It starts one SFU and one standalone voice process after the API is healthy. |
| 62 | 62 | Each app release restarts voice, and an unavailable voice process retries |
| 63 | 63 | while the API continues serving. Previews leave voice disabled. |
| 64 | ||
| 65 | Snow Globe's tailnet UDP relay forwards the native media port to the published | |
| 66 | container port. The Phoenix VM uses the same relay tool bound to loopback with | |
| 67 | Snow Globe's tailnet address as upstream. Its gateway relay sets | |
| 68 | `X-Snowcord-Voice-Relay: phoenix-loopback` so voice advertises the VM's loopback | |
| 69 | address. The guest profile lets Phoenix bind and receive UDP on its temporary | |
| 70 | ports and send UDP only to the local relay port. |