Documentation
¶
Overview ¶
Package dial is the client half of the holt: a persistent attach loop that dials the hub over a WebSocket, serves an http.Handler over the reverse tunnel, and redials with jittered backoff until the context ends or the hub sends a terminal GoAway.
The WebSocket is the tunnel's carrier because it passes through what gRPC cannot: CDN public hostnames (Cloudflare included), access proxies, and HTTP/1.1-only edges. wss:// puts TLS under the socket exactly like https; extra headers on the upgrade request carry whatever the edge in front of the hub wants (a bearer token, a Cloudflare Access service token, …).
Index ¶
Constants ¶
const ( // DefaultKeepalive paces WebSocket-level pings from the peer. // Proxies drop idle sockets (Cloudflare after ~100 s of silence); // pinging well under that keeps a quiet tunnel attached. DefaultKeepalive = 40 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func NormalizeURL ¶
NormalizeURL maps a tunnel URL to its WebSocket form: ws and wss pass through, http becomes ws and https becomes wss (so tokens minted before the WebSocket carrier keep working). Any other scheme, or a missing host, is an error.
func Run ¶
Run attaches to the hub and serves Handler over the tunnel, redialing with jittered exponential backoff (500 ms doubling to 30 s) until ctx is cancelled or the hub sends a terminal GoAway. A successful handshake resets the backoff. Returns nil on a terminal GoAway (clean exit) and ctx.Err() on shutdown.
Types ¶
type Options ¶
type Options struct {
// URL is the hub's tunnel endpoint: ws:// (plaintext) or wss://
// (TLS to the edge, system roots). http:// and https:// are
// accepted as aliases so pre-WebSocket tunnel URLs keep working.
URL string
// Header goes out with the WebSocket upgrade request: the
// Authorization bearer the hub's middleware verifies, plus
// anything an authenticating proxy in front wants (e.g.
// CF-Access-Client-Id / CF-Access-Client-Secret).
Header http.Header
// HTTPClient overrides the client used for the upgrade request
// (custom roots, proxies). Default: a private client with its own
// connection pool. Between redial attempts Run closes the
// client's idle connections so every attempt dials fresh.
HTTPClient *http.Client
// Keepalive paces WebSocket pings; 0 means DefaultKeepalive, a
// negative value disables them (the inner HTTP/2 PING remains).
Keepalive time.Duration
// Handler is served over the tunnel — the hub dials it as if it
// were a normal HTTP server.
Handler http.Handler
// Version is the peer build version, sent in Hello (observability).
Version string
Logger *zap.Logger
// MeterProvider builds the peer's own instruments (attaches,
// failed attempts by reason, session duration, and a gauge that
// is 1 while a tunnel is up). Optional: without it the global
// provider is used, a no-op until an SDK is installed.
MeterProvider metric.MeterProvider
// TunnelType is what this peer carries, declared at attach so the
// hub records it, reports it, and can refuse what it cannot serve.
// Empty means http, or https when TLSConfig is set: the payload is
// TLS end to end then, which is what https names here.
TunnelType tunneltype.Type
// TLSConfig, when set, encrypts the payload end-to-end INSIDE the
// tunnel: after the plaintext holt handshake the peer runs a
// TLS server over the stream and serves Handler over HTTPS. The
// hub must dial with a matching client config (hub.WithPeerTLS).
// This is independent of any TLS on the outer WebSocket — it
// stays encrypted even if that hop is plaintext or terminated
// at a proxy. NextProtos is forced to h2.
TLSConfig *tls.Config
}
Options wires one attach loop.