How tik-choco-lab/webrtc-p2p-tunnel works
Project type and purpose
• This is a Go-based command-line application (“webrtc-p2p-tunnel”) that establishes a peer-to-peer tunnel over WebRTC DataChannels. It listens on a local TCP port, uses a signaling service to exchange SDP/ICE with a remote peer, and forwards TCP-level traffic bidirectionally through the WebRTC channel.
File structure
• cmd/tunnel/main.go: The CLI entrypoint that parses flags, sets up logging, and orchestrates the tunnel.
• internal/logger/logger.go: A thin wrapper around Go’s logging primitives, used by all modules.
• internal/signal: Implements a signaling client for exchanging SDP/ICE messages with a remote peer (likely over WebSocket or HTTP).
• internal/rtc: Manages WebRTC PeerConnection and DataChannel (“chat.go”, “peer.go”, “tunnel_message.go”).
• internal/tcp/listener.go: Listens on a local TCP port, accepts inbound connections, and hands off I/O to the DataChannel.
README for additional insights
• Usage is simply “go run ./cmd/tunnel” or “go build ./cmd/tunnel.” No built-in signaling server provided, so the CLI must connect to a remote signaling endpoint (configurable via flags).
Be very detailed
• Eight components (CLI, logger, signal, rtc-peer, rtc-channel, tcp-listener, external signaling server, remote TCP endpoint).
• Initialization sequence: CLI → logger → signal.connect() → rtc.setup() → datachannel.open → tcp.listen().