tunnel

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package tunnel implements the WebSocket tunnel binding (SPEC 9) and the enrollment client.

Index

Constants

View Source
const (
	DefaultPingInterval = 20 * time.Second
	DefaultDeadAfter    = 60 * time.Second
	// DefaultReadLimit admits a 16 MiB record batch payload plus frame and compression overhead.
	DefaultReadLimit = protocol.MaxFramePayload + 1<<20
)

Keepalive defaults (SPEC 9.1).

Variables

View Source
var (
	ErrDead   = errors.New("tunnel: no traffic within the dead interval")
	ErrClosed = errors.New("tunnel: connection closed")
)

Errors reported by a Conn.

Functions

func Enroll

Enroll is a convenience wrapper that builds a Transport for one enrollment.

Types

type BinaryHandler

type BinaryHandler func(ctx context.Context, frame []byte)

BinaryHandler receives binary frames in arrival order.

type Conn

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

Conn multiplexes JSON-RPC 2.0 text frames and binary record frames; notifications and frames dispatch in order once Handle is called.

func Accept

func Accept(w http.ResponseWriter, r *http.Request, opts ConnOptions) (*Conn, error)

Accept upgrades an HTTP request to a tunnel connection (control plane side).

func (*Conn) Call

func (c *Conn) Call(ctx context.Context, method string, p, result any) error

Call sends a request and waits for its response. An error response is a *protocol.RPCError.

func (*Conn) Close

func (c *Conn) Close() error

Close ends the connection with a normal closure.

func (*Conn) Done

func (c *Conn) Done() <-chan struct{}

Done is closed once the connection has ended and every handler invocation has returned.

func (*Conn) Err

func (c *Conn) Err() error

Err returns the reason the connection ended, or nil while it is open.

func (*Conn) Handle

func (c *Conn) Handle(h client.Handler)

Handle installs the request and notification handler and starts dispatch.

func (*Conn) HandleBinary

func (c *Conn) HandleBinary(h BinaryHandler)

HandleBinary installs the binary frame handler; install it before Handle.

func (*Conn) Notify

func (c *Conn) Notify(ctx context.Context, method string, p any) error

Notify sends a notification.

func (*Conn) SendBinary

func (c *Conn) SendBinary(ctx context.Context, frame []byte) error

SendBinary sends one binary frame.

type ConnOptions

type ConnOptions struct {
	PingInterval time.Duration
	DeadAfter    time.Duration
	ReadLimit    int64
}

ConnOptions tunes keepalive and message limits.

type Options

type Options struct {
	// Endpoint is host[:port] or an https:// URL with an optional path prefix.
	Endpoint string
	// Credential returns the current bearer credential; it is read on every dial.
	Credential func() string
	// CAFile adds a PEM bundle to the system roots.
	CAFile string
	// Proxy selects a proxy per request; the default honors HTTPS_PROXY and NO_PROXY.
	Proxy func(*http.Request) (*url.URL, error)
	// DialContext overrides TCP dialing.
	DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
	Conn        ConnOptions
	UserAgent   string
}

Options configures the writer side of the tunnel.

type Transport

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

Transport dials tunnel sessions; it implements client.Transport.

func New

func New(opts Options) (*Transport, error)

New validates options and builds the HTTP client.

func (*Transport) Dial

func (t *Transport) Dial(ctx context.Context) (client.Conn, error)

Dial opens a tunnel session with the current credential.

func (*Transport) Enroll

Enroll exchanges an enrollment token for a credential (SPEC 9.2).

Jump to

Keyboard shortcuts

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