Documentation
¶
Overview ¶
Package client implements the otun tunnel client.
Index ¶
- Constants
- Variables
- type Backoff
- type BackoffConfig
- type Client
- func (c *Client) Close() error
- func (c *Client) Run(ctx context.Context) error
- func (c *Client) RunWithReconnect(ctx context.Context) error
- func (c *Client) Subdomain() string
- func (c *Client) TunnelURL() string
- func (c *Client) WithBackoff(config BackoffConfig) *Client
- func (c *Client) WithInspector(store inspect.Store, opts inspect.Options) *Client
- func (c *Client) WithMaxRetries(maxRetries int) *Client
- func (c *Client) WithReconnect(enabled bool) *Client
- func (c *Client) WithSubdomain(subdomain string) *Client
- func (c *Client) WithToken(token string) *Client
Constants ¶
const ( // HeartbeatInterval is how often to send heartbeat messages. HeartbeatInterval = 30 * time.Second )
Variables ¶
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
Attempt returns the current attempt number (0 = no attempts yet).
func (*Backoff) MaxRetriesReached ¶ added in v0.2.0
MaxRetriesReached returns true if max retries has been exceeded. Always returns false if MaxRetries is 0 (unlimited).
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 (*Client) Run ¶
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
RunWithReconnect runs the client with automatic reconnection on transient failures.
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
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
WithMaxRetries sets the maximum number of reconnection attempts.
func (*Client) WithReconnect ¶ added in v0.2.0
WithReconnect enables or disables automatic reconnection.
func (*Client) WithSubdomain ¶
WithSubdomain sets a preferred subdomain for the tunnel.