Documentation
¶
Overview ¶
Package tunnel implements the WebSocket tunnel binding (SPEC 9) and the enrollment client.
Index ¶
- Constants
- Variables
- func Enroll(ctx context.Context, opts Options, req protocol.EnrollRequest) (*protocol.EnrollResponse, error)
- type BinaryHandler
- type Conn
- func (c *Conn) Call(ctx context.Context, method string, p, result any) error
- func (c *Conn) Close() error
- func (c *Conn) Done() <-chan struct{}
- func (c *Conn) Err() error
- func (c *Conn) Handle(h client.Handler)
- func (c *Conn) HandleBinary(h BinaryHandler)
- func (c *Conn) Notify(ctx context.Context, method string, p any) error
- func (c *Conn) SendBinary(ctx context.Context, frame []byte) error
- type ConnOptions
- type Options
- type Transport
Constants ¶
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 ¶
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 ¶
func Enroll(ctx context.Context, opts Options, req protocol.EnrollRequest) (*protocol.EnrollResponse, error)
Enroll is a convenience wrapper that builds a Transport for one enrollment.
Types ¶
type BinaryHandler ¶
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 ¶
Call sends a request and waits for its response. An error response is a *protocol.RPCError.
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) HandleBinary ¶
func (c *Conn) HandleBinary(h BinaryHandler)
HandleBinary installs the binary frame handler; install it before Handle.
type ConnOptions ¶
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 (*Transport) Enroll ¶
func (t *Transport) Enroll(ctx context.Context, req protocol.EnrollRequest) (*protocol.EnrollResponse, error)
Enroll exchanges an enrollment token for a credential (SPEC 9.2).