ingress

package
v0.35.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package ingress is fuse-proxy: stable public tcp ports in front of guests that dial in over internal/tunnel.

a route is a public port that belongs to an owner (a vm id) and leads to one port inside that owner's guest. the port is the stable thing. which owner it belongs to can change, and that is the whole of what a migrate does here: the new vm adopts the old vm's ports, and the url every client holds keeps working without any of them learning that anything moved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminHandler

func AdminHandler(p *Proxy, cfg AdminConfig) http.Handler

AdminHandler serves the admin api.

Types

type AdminConfig

type AdminConfig struct {
	Token string
	// PublicHost is the name or address clients and guests reach this machine
	// by. TunnelPort is the udp port guests dial.
	PublicHost    string
	TunnelPort    int
	ServerCertPEM string
}

AdminConfig is what the admin api needs beyond the proxy itself.

type Client

type Client struct {
	BaseURL string
	Token   string
	HTTP    *http.Client
}

Client is the orchestrator's end of the admin api.

func NewClient

func NewClient(baseURL, token string) *Client

NewClient returns a client with a timeout suited to small control calls.

func (*Client) Lookup

func (c *Client) Lookup(ctx context.Context, owner string) (orchestrator.IngressGrant, error)

Lookup implements orchestrator.IngressProxy.

func (*Client) Publish

Publish implements orchestrator.IngressProxy.

func (*Client) Unpublish

func (c *Client) Unpublish(ctx context.Context, owner string) error

Unpublish implements orchestrator.IngressProxy.

type Config

type Config struct {
	// StatePath is where owners and routes are persisted. routes have to
	// outlive the process: a proxy that came back with different ports would
	// have broken every url it exists to keep stable.
	StatePath string
	// PortMin and PortMax bound the public ports handed out, inclusive.
	PortMin, PortMax int
	// BindHost is the address public listeners bind, "" for all.
	BindHost string
	// HoldTimeout is how long a client connection waits for its guest to be
	// reachable before it is closed.
	HoldTimeout time.Duration
	Logger      *slog.Logger
}

Config tunes a Proxy.

type Opener

type Opener interface {
	Open(ctx context.Context, owner string, port int) (net.Conn, error)
	Drop(owner string)
}

Opener is the part of tunnel.Server the proxy uses.

type PortSpec

type PortSpec struct {
	Name      string `json:"name"`
	GuestPort int    `json:"guest_port"`
}

PortSpec is one port of a Publish.

type Proxy

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

Proxy owns the routes and their listeners.

func New

func New(cfg Config) (*Proxy, error)

New loads the state file and reopens every route's listener.

func (*Proxy) Authenticate

func (p *Proxy) Authenticate(owner, token string) bool

Authenticate is the tunnel server's authenticator.

func (*Proxy) Close

func (p *Proxy) Close()

Close stops every listener.

func (*Proxy) Publish

func (p *Proxy) Publish(owner, token string, ports []PortSpec, adoptFrom string) ([]Route, error)

Publish creates or updates owner so that it has exactly ports, and returns its routes.

a route that already exists under the same name keeps its public port, so publishing again is how a token is rotated without the url moving. with adoptFrom, each name takes the public port of the same name under adoptFrom, and adoptFrom loses it. connections already running to the old guest are left alone: they are streams on the old guest's tunnel and end when it does.

func (*Proxy) Remove

func (p *Proxy) Remove(owner string) (bool, error)

Remove deletes owner, closes its ports and disconnects its guest.

func (*Proxy) Routes

func (p *Proxy) Routes(owner string) ([]Route, bool)

Routes returns owner's routes.

func (*Proxy) Start

func (p *Proxy) Start(t Opener)

Start attaches the tunnel and opens the listeners for every known route. it is separate from New because the tunnel server's authenticator is this proxy's Authenticate, so each needs the other to exist first.

type Route

type Route struct {
	Name       string `json:"name"`
	GuestPort  int    `json:"guest_port"`
	PublicPort int    `json:"public_port"`
}

Route is one published port.

Jump to

Keyboard shortcuts

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