How noiseonwires/yac-ws-bridge works
Purpose and topology
Bridge to Freedom is a multiplexed raw-TCP tunnel using Yandex Cloud (YC) API Gateway WebSockets. A server-side Go adapter reaches a target TCP service; a client-side Go helper or MAUI app exposes a local TCP listener. YC’s serverless function performs authenticated peer discovery, while direct YC WebSocket-management gRPC carries most data.
Executable entry points
• Go adapter: adapter-and-helper/cmd/adapter/main.go
• Go helper: adapter-and-helper/cmd/helper/main.go
• YC Node.js Cloud Function handler: bridge-cloud/index.js
• Cross-platform GUI client: maui-client/MauiProgram.cs, maui-client/MainPage.xaml.cs
• Linux MAUI head: maui-client-linux/Program.cs
Go tunnel core
Both Go binaries share internal packages for configuration, framing, stream lifecycle, upstream WebSocket connectivity, and YC send APIs:
• Configuration and runtime options: adapter-and-helper/internal/config/config.go
• Tunnel frame/wire protocol: adapter-and-helper/internal/protocol/protocol.go
• Multiplexed stream management, FIN/open/data processing, ordering, and write coalescing: adapter-and-helper/internal/streams/streams.go
• Persistent authenticated upstream WebSocket connection and reconnect/ping behavior: adapter-and-helper/internal/upstream/upstream.go
The helper accepts local TCP connections, allocates stream IDs, and emits OPEN/DATA/FIN frames. The adapter receives frames, opens a TCP connection to its configured target, and returns response/data frames. Multiple streams share each peer’s upstream WebSocket session.
YC transport boundary
adapter-and-helper/internal/wsapi/wsapi.go abstracts outbound delivery. adapter-and-helper/internal/wsapi/grpc.go uses YC’s WebSocket-management gRPC wsSend path for direct peer delivery; adapter-and-helper/internal/wsapi/rest.go provides the REST-side integration surface. In normal mode, Cloud Function traffic is control-plane discovery only. In helper relay mode, helper-to-adapter frames instead traverse its upstream WebSocket and the function relays them.
YC limits shape transport behavior: periodic pings preserve WebSocket sessions; frame/message limits motivate coalescing and stream framing; reconnect loops handle Gateway connection churn.
Discovery and recovery control plane
The Cloud Function at bridge-cloud/index.js authenticates adapter and helper HELLO handshakes, associates their Gateway connection IDs, and notifies peers when both are present. bridge-cloud/spec.yaml binds the adapter/helper WebSocket routes to that function through YC API Gateway.
The adapter additionally exposes an authenticated HTTP recovery endpoint containing current adapter/helper connection IDs. The function calls it through HTTP_URL after cold starts or instance changes, allowing discovery state restoration. Endpoint URL, shared token, and route names must align across deployed function, Gateway, and clients.
Native and GUI client boundary
The MAUI client is a functional alternative to the Go helper: maui-client/Services/TunnelService.cs owns local tunnel behavior and maui-client/Services/Protocol.cs implements compatible framing. Platform hosts include Android foreground-service support in maui-client/Platforms/Android/TunnelForegroundService.cs and iOS background-audio support in maui-client/Platforms/iOS/SilentAudioService.cs.
Deployment/runtime configuration
Go 1.21+ builds the adapter/helper module in adapter-and-helper/go.mod; Node.js 18 is the documented YC function runtime, with dependencies in bridge-cloud/package.json; MAUI/.NET builds native client variants. Deployment-critical example configuration lives in adapter-and-helper/adapter.config.yaml and adapter-and-helper/helper.config.yaml. These configure Gateway URLs, shared authentication, TCP listen/target addresses, reconnect/ping policy, coalescing, and relay behavior.
Main entry points: main.go Go adapter · TunnelService.cs MAUI tunnel client · streams.go Multiplexed streams · spec.yaml YC API Gateway WebSockets
Components 17
Go tunnel runtime
- Go adapter · Connects tunnel streams to the configured target TCP service.
adapter-and-helper/cmd/adapter/main.go - Go helper · Exposes a local TCP listener for tunnel clients.
adapter-and-helper/cmd/helper/main.go - Runtime configuration
adapter-and-helper/internal/config/config.go - Tunnel framing · Defines OPEN, DATA, and FIN wire frames.
adapter-and-helper/internal/protocol/protocol.go - Multiplexed streams · Handles stream lifecycle, ordering, and coalesced writes.
adapter-and-helper/internal/streams/streams.go - Upstream WebSocket · Maintains authenticated sessions with reconnect and ping behavior.
adapter-and-helper/internal/upstream/upstream.go - Outbound delivery API
adapter-and-helper/internal/wsapi/wsapi.go - YC gRPC sender · Directly sends frames to a peer Gateway connection.
adapter-and-helper/internal/wsapi/grpc.go - REST integration
adapter-and-helper/internal/wsapi/rest.go - Adapter recovery endpoint · Returns current adapter and helper connection IDs for state restoration.
adapter-and-helper/cmd/adapter/main.go
Yandex Cloud control and transport
- YC API Gateway WebSockets · Hosts peer WebSocket connections and routes handshakes.
bridge-cloud/spec.yaml - Discovery function · Authenticates HELLO peers, records connection IDs, and notifies matched peers.
bridge-cloud/index.js
Native client
- MAUI tunnel client · Alternative local TCP tunnel client compatible with the Go adapter.
maui-client/Services/TunnelService.cs - MAUI framing
maui-client/Services/Protocol.cs - Android foreground service
maui-client/Platforms/Android/TunnelForegroundService.cs - iOS background audio
maui-client/Platforms/iOS/SilentAudioService.cs
Other components
- Target TCP service
Connections 20
- Go helper → Runtime configuration: loads
- Go adapter → Runtime configuration: loads
- Go helper → Multiplexed streams: allocates local streams
- Go adapter → Multiplexed streams: processes streams
- Multiplexed streams → Tunnel framing: encodes frames
- Go adapter → Target TCP service: opens TCP connections
- Go helper → Upstream WebSocket: connects
- Go adapter → Upstream WebSocket: connects
- Upstream WebSocket → YC API Gateway WebSockets: persistent WebSocket session
- Multiplexed streams → Outbound delivery API: delivers frames
- Outbound delivery API → YC gRPC sender: normal direct mode
- Outbound delivery API → REST integration: REST surface
- YC gRPC sender → YC API Gateway WebSockets: wsSend to peer
- YC API Gateway WebSockets → Discovery function: routes HELLO handshakes
- Discovery function → Adapter recovery endpoint: restores discovery state
- MAUI tunnel client → MAUI framing: uses
- MAUI tunnel client → YC API Gateway WebSockets: WebSocket tunnel session
- MAUI tunnel client → Go adapter: compatible peer tunnel
- Android foreground service → MAUI tunnel client: keeps tunnel active
- iOS background audio → MAUI tunnel client: keeps tunnel active