Documentation
¶
Overview ¶
Package remote implements a reverse forwarding handler for connections received from remote TNET nodes. It listens for "rtcp", "rudp", and "runix" protocols and forwards the accepted connections to the configured hop.
The handler is registered under the names "rtcp", "rudp", and "runix" via NewHandler in init().
Connection processing flow ¶
Each inbound net.Conn is processed by Handle, which wraps the connection with I/O stats, checks the rate limiter, and dispatches to one of two forwarding paths:
Handle() ├─ stats_wrapper.WrapConn (per-connection I/O counters) ├─ newRecorderObject (session metadata: service, SID, addresses) ├─ checkRateLimit (connection rate limiter, if configured) ├─ Router nil check → errRouterNotAvailable ├─ [sniffing enabled] sniffing.Sniff (peek buffer, detect protocol) │ └─ handleSniffedProtocol() │ ├─ sniffing.ProtoHTTP → SnifferBuilder.Build().HandleHTTP() │ ├─ sniffing.ProtoTLS → SnifferBuilder.Build().HandleTLS() │ └─ default → fall through to raw forwarding └─ [sniffing disabled / unrecognised] handleRawForwarding()
Protocol sniffing dispatch (handleSniffedProtocol) ¶
When sniffing is enabled and the initial bytes match HTTP or TLS, the connection is delegated to the forwarder package for protocol-aware handling:
- HTTP: parses the request, applies MITM if configured, forwards to the upstream, and records WebSocket frames when enabled.
- TLS: parses the ClientHello to extract the server name, applies MITM or SNI-based routing through the hop, and records the TLS handshake.
SnifferBuilder is populated once during Init and reused via Build() to create per-connection forwarder.Sniffer instances.
Raw forwarding (handleRawForwarding) ¶
The default path for unrecognised traffic. It selects a target node from context metadata or the hop, dials the upstream through the router, wraps the connection with proxy protocol (HAProxy) when enabled, and pipes data bidirectionally:
- Node selection — context host metadata takes priority, then getHop().Select() with optional protocol hint.
- Router dial — Router.Dial() through the configured chain.
- Proxy protocol — proxyproto.WrapClientConn() prepends HAProxy header when metadata proxyProtocol is set.
- Bidirectional pipe — xnet.Pipe(ctx, conn, cc) with read timeout.
Hop management ¶
The handler implements handler.Forwarder. Forward() is called during service startup (and on reload) to install or update the hop. The hop is protected by a mutex because Forward() runs on the loader goroutine while Handle() reads it from per-connection goroutines.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type SnifferBuilder ¶ added in v0.28.1
type SnifferBuilder struct {
Websocket bool
WebsocketSampleRate float64
Recorder recorder.Recorder
RecorderOptions *recorder.Options
Certificate *x509.Certificate
PrivateKey crypto.PrivateKey
ALPN string
CertPool tls_util.CertPool
MitmBypass bypass.Bypass
// ReadTimeout is the timeout for reading upstream HTTP response headers
// and TLS ServerHello during sniffing. Passed through to forwarder.Sniffer.
// See forwarder.Sniffer.ReadTimeout for details.
ReadTimeout time.Duration
// Cache is the HTTP response cache (nil when caching is disabled).
Cache *httpcache.Cache
}
SnifferBuilder holds configuration for creating per-connection protocol sniffers. It is populated once during Init and reused for each connection.
func (*SnifferBuilder) Build ¶ added in v0.28.1
func (b *SnifferBuilder) Build() *forwarder.Sniffer
Build creates a new forwarder.Sniffer from the builder's configuration.