Skip to content

feat: websocket relay#112

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

feat: websocket relay#112
nicholasliverett wants to merge 11 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.

Also added a --websocket-relay flag to use the websocket relay without the timer or trying UDP. So it forces the websocket relay at first connect.

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
Pangolin: fosrl/pangolin#2831

nicholasliverett and others added 11 commits April 11, 2026 10:49
Introduce a WebSocketRelayBind implementation and plumbing to support TCP relay over websockets. Adds olm/ws_relay_bind.go (bind implementation, connect/read/write loops, Open/Send/Shutdown) and integrates relay handling in Olm: caching relay tunnel URL, buildRelayTunnelURL helper, updated token update handling, and shutting down wsRelayBind on Close. Adds RelayEndpointWss to peer and exit node types, a PeerManager.RelayPeerWss stub to mark peers as relayed, and a GetTokenState accessor on the websocket client. Misc: tweak logging around device startup failure and adjust tunnel registration relay flag; bump go.mod module go version string. These changes prepare the codebase to use websocket-based TCP relay transport as a fallback.
Implement per-site TCP fallback for UDP relay and the websocket relay transport switch.

- Track per-site relay timers (relayTimers) with synchronization and initialize in Olm.
- Add scheduleRelayTCPFallback and cancelRelayTCPFallback to start/stop an 8s timer that triggers switching to websocket relay if a peer remains disconnected.
- Implement switchToWebsocketRelayBind to build the websocket relay URL, bring up a new WireGuard device using the websocket bind, reconfigure peers on the new device, and swap devices cleanly.
- Hook timer scheduling into handleWgPeerRelay and cancel on handleWgPeerUnrelay.
- Extend PeerManager with SetDevice, IsPeerConnected and IsPeerRelayed helpers to support device swapping and connectivity checks.
- Add PeerMonitor.IsWGConnected to report current WireGuard connection state for a peer.

This enables automatic fallback from UDP-relayed connections to a websocket/TCP-based relay when UDP relay connectivity does not establish within 8 seconds, and provides APIs for swapping devices and checking peer connection/relay status.
Introduce a WebSocketRelayBind implementation and plumbing to support TCP relay over websockets. Adds olm/ws_relay_bind.go (bind implementation, connect/read/write loops, Open/Send/Shutdown) and integrates relay handling in Olm: caching relay tunnel URL, buildRelayTunnelURL helper, updated token update handling, and shutting down wsRelayBind on Close. Adds RelayEndpointWss to peer and exit node types, a PeerManager.RelayPeerWss stub to mark peers as relayed, and a GetTokenState accessor on the websocket client. Misc: tweak logging around device startup failure and adjust tunnel registration relay flag; bump go.mod module go version string. These changes prepare the codebase to use websocket-based TCP relay transport as a fallback.
Implement per-site TCP fallback for UDP relay and the websocket relay transport switch.

- Track per-site relay timers (relayTimers) with synchronization and initialize in Olm.
- Add scheduleRelayTCPFallback and cancelRelayTCPFallback to start/stop an 8s timer that triggers switching to websocket relay if a peer remains disconnected.
- Implement switchToWebsocketRelayBind to build the websocket relay URL, bring up a new WireGuard device using the websocket bind, reconfigure peers on the new device, and swap devices cleanly.
- Hook timer scheduling into handleWgPeerRelay and cancel on handleWgPeerUnrelay.
- Extend PeerManager with SetDevice, IsPeerConnected and IsPeerRelayed helpers to support device swapping and connectivity checks.
- Add PeerMonitor.IsWGConnected to report current WireGuard connection state for a peer.

This enables automatic fallback from UDP-relayed connections to a websocket/TCP-based relay when UDP relay connectivity does not establish within 8 seconds, and provides APIs for swapping devices and checking peer connection/relay status.
Introduce a new WebSocketRelay option in the OlmConfig structure, allowing users to enable or disable WebSocket relay transport. Update the configuration loading functions to support this new option from environment variables and command-line arguments. Modify the connection handling logic to utilize the WebSocket relay when enabled, including adjustments to the relay switching mechanism and logging for better visibility. This enhances the flexibility of the relay transport options available in the application.
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