reachability

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package reachability owns demand-bounded gateway leases, never ICE attempts.

Index

Constants

View Source
const (
	DefaultCapacity         = 64
	DefaultDemandTTL        = 60 * time.Second
	DefaultLeaseTTL         = 120 * time.Second
	DefaultHeadStart        = 2 * time.Second
	DefaultGrace            = 3 * time.Second
	DefaultOperationTimeout = 2 * time.Second
)

Variables

View Source
var (
	ErrInvalid         = errors.New("invalid reachability request")
	ErrCapacity        = errors.New("reachability capacity exhausted")
	ErrUnavailable     = errors.New("gateway capability unavailable")
	ErrInvalidResponse = errors.New("invalid gateway response")
	ErrClosed          = errors.New("reachability authority closed")
	// ErrLeaseLost means a renewal no longer authorizes the previous endpoint.
	// Other errors retain the previous lease only until its original expiry.
	ErrLeaseLost = errors.New("gateway lease lost")
)

Functions

func PublicAddress

func PublicAddress(address netip.Addr) bool

PublicAddress is deliberately stricter than netip.IsGlobalUnicast, which includes private and documentation addresses that cannot establish reachability.

Types

type Authority

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

func New

func New(config Config) *Authority

func (*Authority) Changes

func (a *Authority) Changes() <-chan struct{}

func (*Authority) Close

func (a *Authority) Close(ctx context.Context)

func (*Authority) Facts

func (a *Authority) Facts() []Fact

func (*Authority) Reconcile

func (a *Authority) Reconcile(ctx context.Context)

Reconcile is invoked by the connectivity owner's background maintenance worker. Each pass services at most one gateway step per resource, concurrently: a slow discovery must not hold unrelated renewal or revocation deadlines. Capacity bounds the number of workers; serialized passes preserve single-flight.

func (*Authority) RefreshUnavailable

func (a *Authority) RefreshUnavailable()

RefreshUnavailable consumes a discovery-catalog change, not a retry timer. Only resources with live content demand and no successful lease are eligible; the next background maintenance pass remains bounded by normal gateway limits.

func (*Authority) Retire

func (a *Authority) Retire(generation uint64)

func (*Authority) SetDemand

func (a *Authority) SetDemand(d Demand) error

func (*Authority) Withdraw

func (a *Authority) Withdraw(id string)

type Config

type Config struct {
	Now              func() time.Time
	Gateways         []Gateway
	Capacity         int
	DemandTTL        time.Duration
	LeaseTTL         time.Duration
	HeadStart        time.Duration
	Grace            time.Duration
	OperationTimeout time.Duration
	Observe          func(Event)
}

type Demand

type Demand struct {
	ID          string
	Endpoint    Endpoint
	Scope       Scope
	Until       time.Time
	Content     bool
	Direct      bool
	RetainLease bool
}

type Endpoint

type Endpoint struct {
	Generation uint64
	Egress     string
	Local      netip.AddrPort
	Protocol   Protocol
}

type Event

type Event struct {
	Kind            string
	Endpoint        Endpoint
	Scope           Scope
	GatewayID       string
	Error           error
	ServerEpoch     uint32
	ServerRestarted bool
}

type Fact

type Fact struct {
	Endpoint  Endpoint
	Scope     Scope
	External  netip.AddrPort
	ExpiresAt time.Time
	Kind      string
	GatewayID string
}

type Gateway

type Gateway interface {
	Create(context.Context, Request) (Lease, error)
	Renew(context.Context, Request, Lease) (Lease, error)
	Delete(context.Context, Request, Lease) error
}

Gateway implementations must respect context cancellation and support calls for independent resources concurrently. Renewal errors wrap ErrLeaseLost only when the previous mapping has been revoked or is known to be absent.

type Lease

type Lease struct {
	External        netip.AddrPort
	Lifetime        time.Duration
	GatewayID       string
	ResourceID      string
	Kind            string
	Token           any
	ServerEpoch     uint32
	ServerRestarted bool
}

type Protocol

type Protocol uint8
const (
	TCP Protocol = 6
	UDP Protocol = 17
)

type Request

type Request struct {
	Endpoint Endpoint
	Scope    Scope
	Lifetime time.Duration
}

type Scope

type Scope struct{ Remote netip.AddrPort }

A zero Remote permits every peer. Restricted and wildcard permissions cannot be merged even when they expose the same external endpoint.

Directories

Path Synopsis
Package gateway implements bounded, egress-bound gateway control protocols.
Package gateway implements bounded, egress-bound gateway control protocols.

Jump to

Keyboard shortcuts

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