How benyamin218118/tunnel works
This is a TCP-based relay tunnel with two configured roles: Relay accepts client connections and forwards them through a tunnel to Gate, which connects to the configured destination. The main workflow is configured in main.go and implemented largely in tunnel.go; the same Tunnel implementation branches by role. TCP, optional WebSocket transport, and experimental UDP-over-TCP are represented as distinct paths. The sampled source supports these runtime flows; CDN tunneling is documented but its network path is external to the code.
Main entry points: tunnel.go Relay accept · main.go CLI configuration · models.go Connection map
Components 16
Startup
- CLI configuration
main.go - Tunnel runtime
tunnel.go - TCP/UDP listeners
tunnel.go
TCP forwarding
- Client
- Relay accept
tunnel.go - Gate accept
tunnel.go - Destination service
- Bidirectional copy
tunnel.go
WebSocket transport
- Relay WS handshake
tunnel.go - Gate WS handshake
tunnel.go - Optional CDN
UDP forwarding
- UDP client
- Connection map
models.go - UDP marker detection
tunnel.go - UDP response forwarding
tunnel.go
Other components
- Operator
Connections 22
- Operator → CLI configuration: sets flags
- CLI configuration → Tunnel runtime: creates runtime
- Tunnel runtime → TCP/UDP listeners: opens listeners
- TCP/UDP listeners → Client: accepts TCP
- TCP/UDP listeners → UDP client: accepts UDP
- Client → Relay accept: connects
- Relay accept → Gate accept: dials gate
- Gate accept → Destination service: dials destination
- Relay accept → Bidirectional copy: copies bytes
- Gate accept → Bidirectional copy: copies bytes
- Bidirectional copy → Destination service: forwards TCP
- Relay accept → Relay WS handshake: starts handshake
- Relay WS handshake → Optional CDN: may traverse
- Optional CDN → Gate WS handshake: forwards upgrade
- Gate WS handshake → Gate accept: accepts upgrade
- UDP client → Relay accept: sends datagram
- Relay accept → Connection map: looks up or stores
- Relay accept → Gate accept: sends marker and data
- Gate accept → UDP marker detection: detects marker
- UDP marker detection → Destination service: dials UDP
- Gate accept → UDP response forwarding: returns datagrams
- UDP response forwarding → UDP client: writes response