attach

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 17 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 attach is the hub's tunnel front door: an http.Handler that accepts a peer's WebSocket upgrade, runs the holt handshake, and registers the resulting tunnel in the registry. Identity is the application's concern: the Handler is constructed with an Identity func that extracts the peer ID from the request context (JWT claims, mTLS SAN, header — whatever the surrounding middleware established). The handshake itself carries no identity.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler accepts reverse-tunnel attachments over WebSockets: the peer upgrades a plain HTTP request, then every binary message carries one TunnelFrame. WebSockets are the carrier precisely because they pass through the layers that gRPC cannot — CDN public hostnames, access proxies, HTTP/1.1-only edges.

Mount it behind the application's auth middleware; the Identity func reads whatever that middleware established from the upgrade request's context.

func NewHandler

func NewHandler(registry *registry.Registry, identity Identity, logger *zap.Logger, opts ...HandlerOption) *Handler

NewHandler builds the attach handler. identity maps the authenticated request context to the registry key.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP accepts one peer's reverse tunnel: identity, WebSocket upgrade, handshake, then an HTTP/2 client session over the raw byte stream until the peer disconnects or the registry closes the tunnel.

type HandlerOption

type HandlerOption func(*Handler)

HandlerOption configures a Handler.

func WithPeerTLS

func WithPeerTLS(cfg *tls.Config) HandlerOption

WithPeerTLS makes the hub run a TLS client over each tunnel before speaking HTTP/2, so the payload is encrypted end-to-end between hub and peer. Peers must attach with a matching TLS server config (dial.Options.TLSConfig). Use it to verify peer certificates and to keep the payload confidential even when the outer WebSocket hop is plaintext or TLS-terminated at a proxy. NextProtos is forced to h2.

func WithTracerProvider

func WithTracerProvider(tp trace.TracerProvider) HandlerOption

WithTracerProvider sets the OTel TracerProvider used to span each tunnel's lifetime. Optional — without it the global provider is used, which is a no-op until the application installs an SDK.

type Identity

type Identity func(ctx context.Context) (peer string, err error)

Identity extracts the peer ID from a request context. The application supplies it — it's the bridge from whatever auth middleware wraps the attach handler (JWT claims, mTLS SAN, …) to the registry key. Returning ("", err) rejects the attach.

Jump to

Keyboard shortcuts

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