Skip to content

feat: websocket relay#2831

Open
nicholasliverett wants to merge 4 commits intofosrl:devfrom
nicholasliverett:feature-websocket-relay
Open

feat: websocket relay#2831
nicholasliverett wants to merge 4 commits intofosrl:devfrom
nicholasliverett:feature-websocket-relay

Conversation

@nicholasliverett
Copy link
Copy Markdown

@nicholasliverett nicholasliverett commented Apr 11, 2026

Community Contribution License Agreement

By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.

What does this PR do?

You can read about the discussion related to this topic here: Transport flexiblity
As discussed, in more restrictive networks UDP connections may be completely blocked and clients are unable to connect to resources. To get around this we use a commonly allowed protocol: HTTPS, or more specifically websockets.

Description

OLM will try its normal direct UDP/hole punch and UDP relay. If OLM receives a relayEndpointWss (sent with relay info) it starts an 8s timer. Once that timer is up it switches from the shared UDP bind to a websocket bind. Traffic then flows OLM-(wss)->Pangolin-(tcp relay port)->Gerbil->Newt. Now since we are using a websocket the RTT is more than just raw wireguard, and it might be something to look into.

Note: the only thing changed is olm's connection to the gerbil relay, to newt nothing changes.

How to test?

Setup Pangolin, Gerbil, and Olm from companion PRs mentioned below and regular newt. Have to spin up pangolin, gerbil, newt, and olm to test this. Ideally checking, regular connections, restricted networks, and the force relay flag

Companion PRs

Gerbil: fosrl/gerbil#77
Olm: fosrl/olm#112

nicholasliverett and others added 4 commits April 9, 2026 16:30
Add a relay tunnel WebSocket bridge to proxy binary frames to the Gerbil TCP relay and wire it into the WS upgrade flow. Introduce tcp_relay_port (default 4430) in the config schema. Add relayEndpointWss and relayPort to OLM token responses and relay messages (helpers added to build the WSS relay endpoint). Implement relayTunnelBridge.ts to validate OLM tokens, resolve Gerbil targets, frame/parse length-prefixed packets, connect to Gerbil over TCP, and forward framed binary data between WebSocket and TCP. Integrate the upgrade handler into the existing ws upgrade path (ws.ts). Files changed: server/lib/readConfigFile.ts, server/routers/olm/getOlmToken.ts, server/routers/olm/handleOlmRelayMessage.ts, server/routers/ws/ws.ts and new server/routers/ws/relayTunnelBridge.ts.
Refactor the configuration schema to include an optional wss_relay_port with a default value of 4430. Update the relayTunnelBridge to use wss_relay_port for connection targeting, ensuring proper fallback handling. This change enhances the WebSocket relay functionality and improves configuration flexibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants