dial

package
v0.47.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 19 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dial is the client half of 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 carrier passes through what gRPC cannot: CDN public hostnames, access proxies, HTTP/1.1-only edges.

Index

Constants

View Source
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

func NormalizeURL(raw string) (string, error)

NormalizeURL maps a tunnel URL to its WebSocket form: ws/wss pass through, http(s) become ws(s). Any other scheme, or a missing host, is an error.

func Run

func Run(ctx context.Context, opts Options) error

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(s):// are aliases.
	URL string

	// Header goes out with the WebSocket upgrade request: the
	// Authorization bearer, plus anything an authenticating proxy in
	// front wants.
	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, as if by 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. Default: the
	// global provider, a no-op until an SDK is installed.
	MeterProvider metric.MeterProvider

	// RequestHook reports every request this peer served over the
	// tunnel, once its handler is done. Nothing is stored.
	RequestHook reqlog.Hook

	// 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL