Documentation
¶
Overview ¶
Package entrypoint implements a public tunnel entry point that accepts external connections and routes them through the tunnel network to internal services behind NAT/firewall.
Protocol dispatch is done by peeking at the first byte of the connection:
relay.Version1 (0x52 'R') → relay protocol (handleConnect) dissector.Handshake (0x16) → TLS passthrough (handleTLS) otherwise → HTTP proxy (handleHTTP)
The entrypoint is constructed by the parent tunnel package via Config and a DialFunc. It operates as a standalone service with its own TCP listener, decoder wrapper, and protocol-specific handling — independent of the parent's relay-handshake path.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHandler ¶
func NewHandler(ep *Entrypoint) handler.Handler
NewHandler wraps an Entrypoint as a handler.Handler.
The returned handler's Init is a no-op (the Entrypoint is fully initialized by New()). Handle delegates to ep.Handle.
func NewTCPListener ¶
NewTCPListener creates a new TCP listener wrapper around a raw net.Listener.
Imports the proxyproto, metrics, admission, and conn-limiter wrappers in the standard TNET listener order (see architecture docs). Options carry the service name, proxy protocol version, and optional admission/ conn-limit config.
Types ¶
type Config ¶
type Config struct {
// Node is the local tunnel node ID (from tunnelHandler.id).
Node string
// Service is the parent handler's service name, used for ingress lookups,
// logging, and TLS certificate selection.
Service string
Ingress ingress.Ingress
SD sd.SD
Logger logger.Logger
Recorder recorder.RecorderObject
SniffingWebsocket bool
WebsocketSampleRate float64
// ReadTimeout is applied as SetReadDeadline on upstream connections
// before sniffing HTTP/TLS reads. Also used as
// http.Transport.ResponseHeaderTimeout. 0 or negative defaults to 15s.
ReadTimeout time.Duration
// ProxyProtocol is the PROXY protocol version (1 or 2) for the listener.
ProxyProtocol int
// KeepAlive enables HTTP keep-alive for the transport. Disabled by default.
KeepAlive bool
// Compression enables HTTP transport-level compression. Disabled by default.
Compression bool
}
Config carries dependencies from the tunnel handler into the entrypoint.
All fields must be set by the caller before calling New. The DialFunc bridges the package boundary to avoid an import cycle.
type DialContext ¶
DialContext carries metadata for a dial request. This interface satisfies the context.Context Value() contract, allowing the parent package to pass a real context.Context which is recovered via type assertion in the DialFunc implementation.
type DialFunc ¶
type DialFunc func(ctx DialContext, network, tid string) (conn net.Conn, node, cid string, err error)
DialFunc is the function signature for establishing a tunnel connection. Implemented by the parent package (tunnel) to avoid import cycles.
ctx carries recorder objects and loggers for the tunnel connection. network is always "tcp" for entrypoint connections. tid is the string representation of the target tunnel ID.
type Entrypoint ¶
type Entrypoint struct {
// contains filtered or unexported fields
}
Entrypoint is a public tunnel entry point that accepts external connections and routes them through the tunnel network.
Protocol dispatch is done by peeking at the first byte of the connection:
- relay.Version1 (0x52 'R') → relay protocol (handleConnect)
- dissector.Handshake (0x16) → TLS passthrough (handleTLS)
- otherwise → HTTP proxy (handleHTTP)
For HTTP/TLS paths, the dial flow is:
ep.Dial() → ingress lookup (host → tunnelID) → dialFn() → tunnel connection
The relay protocol path handles its own tunnel ID extraction from the relay request frame.
func New ¶
func New(cfg *Config, dialFn DialFunc) *Entrypoint
New creates a new Entrypoint with the given config and dial function.
The config fields are copied into the Entrypoint struct. The dial function is stored as-is — nil functions cause dial failures at runtime, not at construction time.
The HTTP transport is initialized immediately with ep.dial as its DialContext; responses time out after cfg.ReadTimeout (default 15s).
func (*Entrypoint) Handle ¶
Handle processes an incoming connection on the entrypoint listener.
The first byte is peeked to dispatch protocol handling:
- relay.Version1 (0x52 'R') → ep.handleConnect (relay protocol)
- dissector.Handshake (0x16) → ep.handleTLS (TLS passthrough)
- otherwise → ep.handleHTTP (HTTP forward proxy)
Recording instrumentation (stats, HTTP/TLS metadata) wraps the connection and is finalized in the deferred recorder callback.