conn

package
v0.2.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0, Apache-2.0 Imports: 11 Imported by: 0 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 conn is the worker WebSocket dialer, backoff, and frame IO.

Vendored from bot-agent internal/agent/conn (Apache-2.0, see ../NOTICE). DD changes: the read limit, envelope and version come from internal/workerproto; frames are encoded with encoding/json; DialStatus returns the HTTP status of a refused upgrade.

Index

Constants

This section is empty.

Variables

View Source
var ErrForbidden = errors.New("forbidden")

ErrForbidden stops reconnects until the process is restarted.

View Source
var ErrReconnect = errors.New("reconnect")

ErrReconnect means enrollment finished and the caller should dial again.

View Source
var ErrUnauthenticated = errors.New("unauthenticated")

ErrUnauthenticated asks the caller to back off to 30s and keep trying.

Functions

func Dial

func Dial(ctx context.Context, rawURL, bearer string) (*websocket.Conn, error)

Dial opens a text WebSocket. bearer is sent only when non-empty.

func DialStatus

func DialStatus(ctx context.Context, rawURL, bearer string) (*websocket.Conn, int, error)

DialStatus is Dial that also returns the HTTP status of a refused upgrade (0 when there was no response), so the caller can tell a revoked credential (401) from a network failure. DD addition.

func ReadFrame

func ReadFrame(ctx context.Context, c *websocket.Conn) (string, []byte, error)

ReadFrame returns the type and the raw JSON object.

func Safe

func Safe(err error, secrets ...string) string

Safe redacts known secrets from an error string before it is logged.

func WriteJSON

func WriteJSON(ctx context.Context, c *websocket.Conn, v any) error

WriteJSON writes one text frame.

func WriteRaw

func WriteRaw(ctx context.Context, c *websocket.Conn, b []byte) error

WriteRaw writes an already-encoded frame.

Types

type Backoff

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

Backoff is 1s, doubling, capped at 30s. Take applies ±20% jitter.

func NewBackoff

func NewBackoff() Backoff

NewBackoff starts at 1s.

func (*Backoff) Next

func (b *Backoff) Next() time.Duration

Next is the delay that the following Take will jitter, before Take advances it.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset runs after hello_ok so the next failure waits about 1s.

func (*Backoff) Set

func (b *Backoff) Set(d time.Duration)

Set replaces the next delay. Values above 30s are capped.

func (*Backoff) Take

func (b *Backoff) Take() time.Duration

Take returns the jittered delay and advances the sequence.

Jump to

Keyboard shortcuts

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