localproxy

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultListenAddr                = "127.0.0.1:0"
	DefaultHealthListenAddr          = ""
	DefaultEnabledHealthListenAddr   = "127.0.0.1:0"
	DefaultTunnelID                  = "tunnel_22222222222222222222222222222222"
	DefaultBackend                   = BackendAuto
	DefaultQueueBackend              = QueueBackendInMemory
	DefaultReadinessTimeout          = 10 * time.Second
	DefaultResponseTimeout           = 30 * time.Second
	DefaultClientLastSeenTimeout     = 20 * time.Second
	DefaultControlPlanePollTimeout   = 500 * time.Millisecond
	DefaultControlPlanePollGuardrail = 100 * time.Millisecond
)

Variables

This section is empty.

Functions

func RegisterBackendFactory

func RegisterBackendFactory(factory BackendFactory)

RegisterBackendFactory registers an optional local proxy backend linked into the current binary.

Types

type Backend

type Backend interface {
	Name() BackendName
	InfoBackend() string
	IngressBaseURL() *url.URL
	IngressUnixSocket() string
	ControlPlaneBaseURL() *url.URL
	ControlPlaneUnixSocket() string
	WaitForTunnelClient(context.Context, time.Duration, types.TunnelID) error
	Wait(context.Context) error
	Stop(context.Context) error
}

Backend is the local control plane used by the tunnel-client runtime.

type BackendFactory

type BackendFactory interface {
	Name() BackendName
	StartBackend(context.Context, BackendOptions) (Backend, error)
}

BackendFactory starts a linked local proxy backend.

type BackendName

type BackendName string

BackendName selects the local proxy engine used by Start.

const (
	BackendAuto BackendName = "auto"
	BackendRust BackendName = "rust"
	BackendGo   BackendName = "go"
)

type BackendOptions

type BackendOptions struct {
	ListenAddr             string
	ListenUnixSocket       string
	ControlPlaneUnixSocket string
	TunnelID               types.TunnelID
	APIKey                 string
	EngineQueueBackend     QueueBackendName
	EngineRedisURL         string
	ResponseTimeout        time.Duration
	ClientLastSeenTimeout  time.Duration
	ReadinessTimeout       time.Duration
	Stderr                 io.Writer
}

BackendOptions configures a local proxy backend.

type Info

type Info struct {
	TunnelID               string `json:"tunnel_id"`
	MCPURL                 string `json:"mcp_url"`
	MCPTransport           string `json:"mcp_transport"`
	MCPUnixSocket          string `json:"mcp_unix_socket,omitempty"`
	MCPURLPath             string `json:"mcp_url_path,omitempty"`
	ControlPlaneBaseURL    string `json:"control_plane_base_url"`
	ControlPlaneTransport  string `json:"control_plane_transport"`
	ControlPlaneUnixSocket string `json:"control_plane_unix_socket,omitempty"`
	HealthURL              string `json:"health_url,omitempty"`
	Backend                string `json:"backend"`
}

Info is printed by the CLI and consumed by integration tests.

type Options

type Options struct {
	ListenAddr       string
	ListenUnixSocket string
	TunnelID         types.TunnelID
	MCPServerURLs    []string
	MCPCommands      []string
	Profile          string
	ProfileFile      string
	ProfileDir       string
	// HealthListenAddr optionally starts the embedded tunnel-client health/admin
	// listener. Empty means no health/admin listener.
	HealthListenAddr string
	// HealthURLFile writes the embedded tunnel-client health/admin base URL. If
	// set without HealthListenAddr, Start uses an ephemeral loopback listener.
	HealthURLFile string
	URLFile       string
	// Backend selects the local proxy backend. Empty defaults to auto.
	Backend BackendName
	// EngineQueueBackend selects the queue implementation used by the backend.
	// Empty defaults to inmem. Redis is supported only by linked Rust backends.
	EngineQueueBackend QueueBackendName
	// EngineRedisURL configures the Rust Redis queue backend. The CLI fills this
	// from --engine-redis-url or TUNNEL_ENGINE_REDIS_URL.
	EngineRedisURL string
	// BackendFactories registers optional per-call backends linked into this
	// binary. Process-wide linked backends can also be registered with
	// RegisterBackendFactory.
	BackendFactories []BackendFactory
	// ResponseTimeout bounds how long local MCP ingress waits for a tunnel-client response.
	ResponseTimeout time.Duration
	// ClientLastSeenTimeout is used by readiness and local diagnostics.
	ClientLastSeenTimeout   time.Duration
	ReadinessTimeout        time.Duration
	ControlPlanePollTimeout time.Duration
	PollDeadlineGuardrail   time.Duration
	LookupEnv               func(string) (string, bool)
	Stdout                  io.Writer
	Stderr                  io.Writer
}

Options configures a local control plane plus in-process tunnel-client runtime.

type Proxy

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

Proxy owns the local control plane and in-process tunnel-client.

func Start

func Start(ctx context.Context, opts Options) (*Proxy, error)

Start starts the selected local control plane and tunnel-client runtime.

func (*Proxy) Info

func (p *Proxy) Info() Info

Info returns the local proxy connection details.

func (*Proxy) Stop

func (p *Proxy) Stop(ctx context.Context) error

Stop shuts down the tunnel-client runtime and local control plane.

func (*Proxy) Wait

func (p *Proxy) Wait(ctx context.Context) error

Wait blocks until the context is canceled or the local control plane exits unexpectedly.

type QueueBackendName

type QueueBackendName string

QueueBackendName selects the queue implementation used by a local proxy backend.

const (
	QueueBackendInMemory QueueBackendName = "inmem"
	QueueBackendRedis    QueueBackendName = "redis"
)

Jump to

Keyboard shortcuts

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