client

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package client implements the otun tunnel client.

Index

Constants

View Source
const (
	// HeartbeatInterval is how often to send heartbeat messages.
	HeartbeatInterval = 30 * time.Second
)

Variables

View Source
var (
	// ErrShutdown indicates the client was shut down intentionally (e.g., via context cancellation).
	ErrShutdown = errors.New("client shutdown")

	// ErrPermanentFailure indicates an error that should not trigger reconnection.
	ErrPermanentFailure = errors.New("permanent failure")

	// ErrSubdomainTaken indicates the requested subdomain is already in use.
	ErrSubdomainTaken = errors.New("subdomain already in use")

	// ErrMaxRetriesExceeded indicates the maximum number of reconnection attempts was reached.
	ErrMaxRetriesExceeded = errors.New("maximum reconnection attempts exceeded")
)

Sentinel errors for client operations.

Functions

This section is empty.

Types

type Backoff added in v0.2.0

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

Backoff tracks retry state and calculates delays.

func NewBackoff added in v0.2.0

func NewBackoff(config BackoffConfig) *Backoff

NewBackoff creates a new Backoff with the given configuration.

func (*Backoff) Attempt added in v0.2.0

func (b *Backoff) Attempt() int

Attempt returns the current attempt number (0 = no attempts yet).

func (*Backoff) MaxRetriesReached added in v0.2.0

func (b *Backoff) MaxRetriesReached() bool

MaxRetriesReached returns true if max retries has been exceeded. Always returns false if MaxRetries is 0 (unlimited).

func (*Backoff) NextDelay added in v0.2.0

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

NextDelay returns the delay for the next retry attempt. Call this after a failed attempt to get the delay before retrying.

func (*Backoff) Reset added in v0.2.0

func (b *Backoff) Reset()

Reset resets the backoff state after a successful connection.

type BackoffConfig added in v0.2.0

type BackoffConfig struct {
	// InitialDelay is the starting delay (default: 1s)
	InitialDelay time.Duration

	// MaxDelay is the maximum delay between retries (default: 60s)
	MaxDelay time.Duration

	// Multiplier is the factor to increase delay by (default: 2.0)
	Multiplier float64

	// Jitter adds randomness to delays (0.0-1.0, default: 0.25 = 25%)
	Jitter float64

	// MaxRetries is the maximum number of retries (0 = unlimited)
	MaxRetries int
}

BackoffConfig configures the exponential backoff behavior.

func DefaultBackoffConfig added in v0.2.0

func DefaultBackoffConfig() BackoffConfig

DefaultBackoffConfig returns sensible defaults for reconnection.

type Client

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

Client is the otun tunnel client.

func New

func New(serverAddr, localAddr string) *Client

New creates a new tunnel client.

func (*Client) Close

func (c *Client) Close() error

Close closes the client session.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run connects to the server and handles incoming streams. It returns when the connection is closed or the context is cancelled.

func (*Client) RunWithReconnect added in v0.2.0

func (c *Client) RunWithReconnect(ctx context.Context) error

RunWithReconnect runs the client with automatic reconnection on transient failures.

func (*Client) Subdomain

func (c *Client) Subdomain() string

Subdomain returns the assigned subdomain.

func (*Client) TunnelURL

func (c *Client) TunnelURL() string

TunnelURL returns the public URL for the tunnel.

func (*Client) WithBackoff added in v0.2.0

func (c *Client) WithBackoff(config BackoffConfig) *Client

WithBackoff sets the backoff configuration for reconnection.

func (*Client) WithInspector added in v0.3.0

func (c *Client) WithInspector(store inspect.Store, opts inspect.Options) *Client

WithInspector attaches a request inspector. Every incoming HTTP request will be parsed, forwarded to the local service, and stored for review via the webui. Passing a nil store disables inspection.

func (*Client) WithMaxRetries added in v0.2.0

func (c *Client) WithMaxRetries(maxRetries int) *Client

WithMaxRetries sets the maximum number of reconnection attempts.

func (*Client) WithReconnect added in v0.2.0

func (c *Client) WithReconnect(enabled bool) *Client

WithReconnect enables or disables automatic reconnection.

func (*Client) WithSubdomain

func (c *Client) WithSubdomain(subdomain string) *Client

WithSubdomain sets a preferred subdomain for the tunnel.

func (*Client) WithToken added in v0.2.0

func (c *Client) WithToken(token string) *Client

WithToken sets the API key for authentication.

Jump to

Keyboard shortcuts

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