api

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const ConnectionNotFoundMessage = "Connection not found"

ConnectionNotFoundMessage is the body the relay sends with 404 when it holds no connection under the requested ID. Callers must match on it rather than on the bare status: the relay's mux answers 404 for unregistered paths too, so a newer client talking to an older relay that lacks an endpoint would otherwise read "this route does not exist" as "my connection is gone".

View Source
const TunnelPathMTU = 1500

TunnelPathMTU is the assumed underlay path MTU between an agent and a relay. Both sides derive the inner tunnel MTU from it via icx.MTU(TunnelPathMTU), which subtracts the IPv6+UDP+Geneve+AES encapsulation overhead. It must stay large enough that the derived inner MTU is at least the IPv6 minimum link MTU (1280): the overlay is IPv6 ULA, and Linux refuses to run IPv6 on a device below 1280. icx.MTU(1500) = 1392, comfortably above that floor.

Variables

This section is empty.

Functions

func IsConnectionUnknown

func IsConnectionUnknown(err error) bool

IsConnectionUnknown reports whether err is the relay saying it does not know the connection the request named — a definitive rejection: the relay restarted or garbage-collected the connection, and no amount of retrying brings it back. The only remedy is a fresh Connect.

func IsRelayDraining

func IsRelayDraining(err error) bool

IsRelayDraining reports whether err is a request failing because the relay is gracefully shutting down: either the connection closed with H3_NO_ERROR, or the http3 client refused to open a stream past a received GOAWAY (its unexported errGoAway, matched by message as there is no exported value). Such failures are expected while a drain is in progress and carry no signal beyond the drain itself.

func IsStatus

func IsStatus(err error, code int) bool

IsStatus reports whether err is a *StatusError with the given status code.

Types

type Client

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

func NewClient

func NewClient(opts ClientOptions) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) (*ConnectResponse, error)

Connect to the relay and establish a new tunnel connection.

func (*Client) Disconnect

func (c *Client) Disconnect(ctx context.Context, id string) error

Disconnect from the relay and close the tunnel connection.

func (*Client) Draining

func (c *Client) Draining() <-chan struct{}

Draining is closed when the relay gracefully closes the control connection. The http3 client reacts to a relay GOAWAY on an idle control connection by closing it with H3_NO_ERROR, so from this side a drain announcement is observed as a graceful close — as opposed to an idle timeout, reset, or refused dial, which all mean the relay died. Only connections dialed via a caller-supplied PacketConn are watched (the transport's default dial path offers no hook), which covers every agent session.

func (*Client) RTT added in v0.22.0

func (c *Client) RTT() time.Duration

RTT returns the smoothed round-trip time QUIC has measured on the control connection, or 0 before the first measurement.

func (*Client) Routes

func (c *Client) Routes(ctx context.Context, id string) (*RoutesResponse, error)

Routes fetches the connection's current route set from the relay.

func (*Client) UpdateKeys

func (c *Client) UpdateKeys(ctx context.Context, id string) (*UpdateKeysResponse, error)

UpdateKeys requests new encryption keys for the tunnel connection.

type ClientOptions

type ClientOptions struct {
	// BaseURL of the relay.
	BaseURL string
	// Agent is the agent name that will be sent in requests.
	Agent string
	// TunnelName is the name of the tunnel.
	TunnelName string
	// Token is the bearer token for authenticating to the relay.
	Token string
	// TLS config for HTTP/3. Provide RootCAs or InsecureSkipVerify if you're
	// talking to a dev relay with a self-signed cert (only for development).
	TLSConfig *tls.Config
	// Timeout for each request. Defaults to 10s if not set.
	Timeout time.Duration
	// PacketConn is an optional UDP PacketConn to use for QUIC connections.
	// If nil, a new UDP socket will be created for each connection.
	PacketConn net.PacketConn
	// MetricsPort is the port the agent's Prometheus metrics server listens on.
	// Advertised to the relay so it can scrape metrics through the overlay.
	MetricsPort int
	// Labels are agent-declared labels used for service selection.
	Labels map[string]string
	// AdvertisedRoutes are CIDRs reachable behind this agent.
	AdvertisedRoutes []string
	// AgentInstance is a stable per-process UUID identifying the agent instance.
	AgentInstance string
}

type ConnectRequest

type ConnectRequest struct {
	// Agent is the name of the agent.
	Agent string `json:"agent"`
	// MetricsPort is the port the agent's Prometheus metrics server listens on.
	// 0 means the agent does not expose metrics.
	MetricsPort int `json:"metricsPort,omitempty"`
	// Labels are agent-declared labels used for service selection. The relay
	// rejects labels outside the credential's allowed label sets.
	Labels map[string]string `json:"labels,omitempty"`
	// AdvertisedRoutes are CIDRs reachable behind this connection. The relay
	// rejects routes outside the credential's allowed CIDRs.
	AdvertisedRoutes []string `json:"advertisedRoutes,omitempty"`
	// AgentInstance is a stable per-process UUID identifying the agent instance.
	AgentInstance string `json:"agentInstance,omitempty"`
}

type ConnectResponse

type ConnectResponse struct {
	// ID is the unique ID of the connection.
	ID string `json:"id"`
	// VNI is the virtual network identifier assigned to the connection.
	VNI uint `json:"vni"`
	// MTU is the maximum transmission unit for the connection.
	MTU int `json:"mtu"`
	// Keys contains the symmetric keys for sending and receiving packets.
	Keys Keys `json:"keys"`
	// Addresses is a list of overlay addresses assigned to the connection.
	Addresses []string `json:"addresses"`
	// Routes is a list of routes to configure for the connection.
	Routes []Route `json:"routes,omitempty"`
	// DNS contains DNS configuration for the connection.
	DNS *DNS `json:"dns,omitempty"`
}

type DNS

type DNS struct {
	// Servers is a list of nameservers to use.
	Servers []string `json:"servers,omitempty"`
	// SearchDomains is a list of search domains to use.
	SearchDomains []string `json:"searchDomains,omitempty"`
	// NDots is the number of dots in name to trigger absolute lookup.
	NDots *int `json:"ndots,omitempty"`
}

type Keys

type Keys struct {
	// Epoch is the key generation for this connection; it starts at 1 and
	// strictly increases on every rotation. Each side maps it onto mirrored
	// per-direction SPIs (psp.EpochSPIs: relay = Responder, agent = Initiator)
	// and the handler derives that epoch's keys from the master secret.
	Epoch uint32 `json:"epoch"`
	// MasterSecret is the connection's PSP master secret (base64-encoded). It is
	// minted once per connection; rotations advance Epoch under the same master.
	MasterSecret MasterSecret `json:"masterSecret"`
	// ExpiresAt is the expiration time for the keys, when this is exceeded, the agent
	// should issue an update keys request.
	ExpiresAt time.Time `json:"expiresAt"`
}

type MasterSecret

type MasterSecret [32]byte

MasterSecret is the 32-byte PSP master secret a connection's per-epoch AES-GCM data keys derive from. The icx handler performs the derivation on each side (psp.DeriveSAKey over the epoch's role-partitioned SPIs), so no finished data key ever crosses the wire or the handler API boundary.

func (MasterSecret) MarshalJSON

func (m MasterSecret) MarshalJSON() ([]byte, error)

func (*MasterSecret) UnmarshalJSON

func (m *MasterSecret) UnmarshalJSON(data []byte) error

type Request

type Request struct {
	// Agent is the name of the agent.
	Agent string `json:"agent"`
	// ID is the unique ID of the connection.
	ID string `json:"id"`
}

type Route

type Route struct {
	// Destination is the destination CIDR for the route.
	Destination string `json:"destination"`
}

type RoutesResponse

type RoutesResponse struct {
	// Routes is the full route set the agent should have installed.
	Routes []Route `json:"routes,omitempty"`
}

RoutesResponse is the connection's current route set. Agents poll this to pick up CIDRs advertised by connections established after their own ConnectResponse snapshot.

type StatusError

type StatusError struct {
	Method string
	URL    string
	Code   int
	Status string
	Body   string
}

StatusError is returned when the relay answers with an unexpected HTTP status. It carries the code so callers can distinguish a definitive rejection (e.g. 404: the relay does not know this connection, which no amount of retrying will fix) from a transient one.

func (*StatusError) Error

func (e *StatusError) Error() string

type UpdateKeysResponse

type UpdateKeysResponse struct {
	// Keys contains the symmetric keys for sending and receiving packets.
	Keys Keys `json:"keys"`
}

Jump to

Keyboard shortcuts

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