Documentation
¶
Overview ¶
Package wireguard is CION's WireGuard application: wireguard-go embedded in the CION binary, carrying the tailnet's hosts and the node-to-node mesh. Hosts are tailnet clients of their node behind one shared UDP port — one device whose peers the registry's host entries program — nodes tunnel to each other through a WireGuard transport (conn.Bind) on the path library's SCION socket, and an in-process router forwards between the tunnels over packet pipes, the surface a resident service application borrows. The application publishes its entry to the directory the core node's application serves, authenticated by TRC-anchored certificate chains.
Index ¶
- Constants
- Variables
- func AssignSlice(ia addr.IA, entries []Entry) (netip.Prefix, error)
- type App
- func (a *App) Close()
- func (a *App) Counters() []any
- func (a *App) Directory(ctx context.Context) (Directory, error)
- func (a *App) DirectoryHandler() http.Handler
- func (a *App) HTTPSHandler() http.Handler
- func (a *App) HostPeers() []HostEntry
- func (a *App) HostPort() uint16
- func (a *App) MeshPeers() []addr.IA
- func (a *App) PublicKey() PublicKey
- func (a *App) Registry() Registry
- func (a *App) Router() Router
- func (a *App) Run(ctx context.Context) error
- func (a *App) Subnet(ctx context.Context) (netip.Prefix, error)
- type Config
- type DERPConfig
- type Directory
- type DirectoryService
- type DirectoryStore
- type Engine
- type Entry
- type HostEntry
- type Paths
- type PrivateKey
- type PublicKey
- type Registry
- type Router
Constants ¶
const ( // SvcWireguard is the mesh transport service. Every node's application // registers its mesh socket under this value in its own AS. SvcWireguard addr.SVC = 0x7ff1 // SvcDirectory is the core's directory service. The core node's // application registers its directory socket under this value. SvcDirectory addr.SVC = 0x7ff2 )
CION's private SCION service values. The drafts' registry names the low values — DS 0x0001, CS 0x0002, the wildcard 0x0010 — and the SVC type's top bit is the multicast flag, so CION's own services take a private slice above both, 0x7ff1 through 0x7fff. The drafts define no WireGuard service: the values are CION's to allocate, the convention proto/wireguard/v1 is.
const ( // PublishInterval is the re-publication cadence. PublishInterval = time.Hour // RefreshInterval is the directory re-fetch cadence. RefreshInterval = 30 * time.Second // PublishRetry is how long publication waits before retrying — a chain // the enrollment loop has not produced yet, or a core that has not // answered. PublishRetry = 10 * time.Second )
Directory cadence: the application owns its publication rhythm. Publication begins once enrollment has produced the node's chain, re-publishes on a constant — enrollment renews daily, so hourly is a reasonable rate — and a refresh constant re-fetches the directory between; a fresh node's tunnels come up as soon as its first publish lands and its first fetch returns the others.
const ( // SwitchRatio is the fraction of the incumbent's declared sum a // challenger must beat — a challenger a fifth faster. SwitchRatio = 0.8 // SwitchWindows is the consecutive windows the same challenger must // lead before the switch lands. SwitchWindows = 2 )
The route pick's hysteresis — the selection loop's promotion shape scaled to route choice. Two near-equal routes trade the lead back and forth as their declared sums move, and every trade costs in-flight datagrams their place in line: one ratio a challenger must beat, one streak of consecutive windows naming the same challenger.
const CountersInterval = time.Minute
CountersInterval is how often the application logs its counters — the overlay's substitute for the operating system's tooling, which cannot see in-process forwarding.
const KeyFile = "wireguard.key"
KeyFile holds the node's WireGuard private key inside the application's state directory, hex-encoded with restrictive permissions.
const OverlayMTU = 1280
OverlayMTU is the overlay's maximum inner packet: an inner packet of 1280 bytes plus WireGuard's data overhead (~32), the outer IPv4 and UDP headers (28), and a worst-case SCION header stack (~156 for a long composed path) stays within a standard 1500-byte MTU. The router enforces the constant — no kernel TUN exists to do it.
const PersistentKeepalive = 25 * time.Second
PersistentKeepalive is the mesh peers' keepalive interval, a code constant set so sessions and paths stay warm enough that path rotation is exercised rather than discovered at first use.
Variables ¶
var ( AuthenticatedIA = peeria.AuthenticatedIA Authenticate = peeria.Authenticate )
AuthenticatedIA returns the ISD-AS of the peer whose certificate chain the channel verified, and Authenticate peers it into the request context — the peer-identity middleware of the SCION-native channel, consumed here for the publisher's identity.
var Tailnet = netip.MustParsePrefix("100.64.0.0/10")
Tailnet is the overlay's host space, the range every node's slice is a slice of: the tunnel carries it and nothing else — no default route is advertised anywhere.
Functions ¶
func AssignSlice ¶
AssignSlice places one publisher's slice of the tailnet range over the entries the store holds: the slice its ISD-AS already holds, else the first free /24 of the range by address order — unique by construction, stable per ISD-AS, idempotent to repeat, nothing ever freed. A publisher cannot take another node's slice; it cannot take any slice, only receive its own.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the WireGuard application: the mesh transport and directory, the one host-facing device behind its shared port — programmed from the host entries the directory distributes — and the in-process router between the tunnels, the surface a resident service application borrows. The node running it holds unprivileged UDP sockets and its own state, and nothing else.
func New ¶
New assembles the application: it loads or creates the node's WireGuard key pair, binds the mesh socket on an ephemeral port and registers it under the wireguard service in its own AS, binds the shared host-facing port, creates one host device per offered exit with the configured peers, builds the router, and wires the directory surfaces: the core's store it serves over its own registered service socket, the route every other node publishes and fetches through. Run serves it.
func (*App) Close ¶
func (a *App) Close()
Close releases what New bound: the devices close, the sockets retire with their service registrations and the interface-down receiver, and the store closes last; no operating-system provisioning exists to undo. It runs once Run has returned, or alone when Run never ran, and a second call releases nothing.
func (*App) Counters ¶
Counters snapshots the application's counters — the overlay's substitute for the operating system's tooling.
func (*App) Directory ¶
Directory fetches the node's view of the registry: the core's own store beside it, every other node's fetched copy.
func (*App) DirectoryHandler ¶
DirectoryHandler is the core's directory HTTP handler: the ConnectRPC service registered on a connect server, connecthttp.Mount spreading it over a private mux, behind the middleware that peers each request's verified chain into its context.
func (*App) HTTPSHandler ¶
HTTPSHandler is nil: the application's surfaces are its own registered sockets and the handlers it serves over them, and it mounts nothing on the node's HTTPS server.
func (*App) HostPeers ¶
HostPeers snapshots the host entries the node owns — the peers the one host device holds, programmed from the fetched directory.
func (*App) HostPort ¶
HostPort returns the shared host-facing UDP port — the one port every host dials.
func (*App) MeshPeers ¶
MeshPeers snapshots the ISD-ASes the directory has produced mesh devices for.
func (*App) PublicKey ¶
PublicKey returns the node's WireGuard public key — the public key a host's client configuration peers with.
func (*App) Registry ¶
Registry returns the coordination surface of the core's store — nil on every other node, which fetches the directory over the core's route instead.
func (*App) Router ¶
Router returns the overlay routing a resident service application borrows: the reply path its produced packets ride and the delivery installation for the address it serves on. Without this application there is nothing to borrow.
func (*App) Run ¶
Run serves the application until the context is canceled: the sockets' readers, the host device's drain, the relay presence, the directory — served by the core, published and fetched by everyone — and the counters log. It returns once every goroutine it started has returned, the mesh peers' drains among them, and leaves what New bound to Close.
type Config ¶
type Config struct {
// IA is the node's ISD-AS.
IA addr.IA
// ListenHost is the underlay host the shared host-facing UDP port binds.
ListenHost netip.Addr
// ListenPort is the shared host-facing UDP port — hosts are plain
// internet clients with a single endpoint to reach.
ListenPort uint16
// PublishedHost resolves the host the entry's host-facing endpoint
// prefers at each publication: the learned host, the founding core's
// identity. An answer that names none leaves the bind host — a wildcard
// bind naming neither holds the publication for the cadence's retry.
PublishedHost func(ctx context.Context) netip.Addr
// DERP is the relay presence the node holds: received datagrams feed
// the shared host port and sends carry the replies, so a host on a
// network where UDP to the node cannot pass still reaches its node.
// Nil runs no presence, and the node serves its hosts over UDP alone.
DERP *DERPConfig
// StateDir is the application's own state directory: the WireGuard key
// pair's home.
StateDir string
// Paths resolves the paths mesh datagrams ride and enumerates the
// candidates the route warm-up ranks.
Paths Paths
// Engine provides the node's chain for the directory channel.
Engine *Engine
// Store is the directory store the core node's application serves, and
// publishes and fetches through locally; nil on every other node, which
// reaches the core's over CoreRoute instead.
Store DirectoryStore
// CoreRoute resolves the core's directory endpoint — its ISD-AS named by
// the directory service — on non-core nodes.
CoreRoute func() *scion.Addr
// NewConn binds a SCION connection of this node on an ephemeral port:
// the socket the mesh transport serves on, the one the core's directory
// serves on beside it, and the one every other node's client publishes
// and fetches through.
NewConn func() (*scion.Conn, error)
// RegisterSvc registers one of the application's sockets as a SCION
// service in this AS — the same registration discovery makes for the CS
// service over the data plane's provider — so the router delivers
// service-addressed packets to the socket's port. Close deregisters
// through UnregisterSvc.
RegisterSvc func(svc addr.SVC, port uint16) error
// UnregisterSvc deregisters a socket RegisterSvc registered.
UnregisterSvc func(svc addr.SVC, port uint16) error
// InterfaceDown is the node's shared negative cache of SCMP
// interface-down signals; the mesh transport drops the cached path of
// the destination a signal's quote names, so its next send re-resolves
// through the filtered composition. Nil leaves the failure-and-refresh
// behavior alone.
InterfaceDown *scion.InterfaceDownCache
// Cadence overrides for tests; zero means the package constant.
PublishInterval time.Duration
RefreshInterval time.Duration
PublishRetry time.Duration
}
Config configures the application.
type DERPConfig ¶
type DERPConfig struct {
// URL is the relay's HTTPS address, "https://host[:port]" — the core's
// coordination endpoint on its own identity.
URL string
// IPv4 optionally dials the relay by address instead of DNS — the
// harness's stand-in for resolution.
IPv4 string
// CertName optionally pins the certificate the relay presents, in the
// DERP map's grammar — the harness's stand-in for the WebPKI.
CertName string
}
DERPConfig configures the node's relay presence: the address of the core's relay and the stands-ins the integration harness needs.
type Directory ¶
type Directory struct {
// Nodes holds one entry per publishing node.
Nodes []Entry
// Hosts holds one entry per registered host.
Hosts []HostEntry
}
Directory is one fetch of the directory: node entries beside host entries, the same authenticated snapshot every node programs itself from.
type DirectoryService ¶
type DirectoryService struct {
// Store persists the directory.
Store DirectoryStore
// Cnt counts accepted publications.
Cnt *counters
}
DirectoryService is the core node's application's own service: Publish records the publisher's entry on the application's authenticated channel, List serves the directory to every node. The channel is the SCION-native mTLS: the publisher identified by its verified certificate chain, so a node can only publish its own entry — the claimed entry's ISD-AS is ignored in favor of the authenticated one.
func (*DirectoryService) List ¶
func (s *DirectoryService) List( ctx context.Context, req *wireguardv1.ListRequest, ) (*wireguardv1.ListResponse, error)
List returns every published entry, nodes and hosts together.
func (*DirectoryService) Publish ¶
func (s *DirectoryService) Publish( ctx context.Context, req *wireguardv1.PublishRequest, ) (*wireguardv1.PublishResponse, error)
Publish records the caller's entry. The entry's ISD-AS is the authenticated one; a claim of another ISD-AS is recorded under the authenticated one all the same. The store assigns the slice — a claimed overlay never enters — and the response answers with it.
type DirectoryStore ¶
type DirectoryStore interface {
// Publish records the entry, keyed by its ISD-AS, placing the
// publisher's slice should its ISD-AS hold none: the first free /24 of
// the tailnet range by address order, the claimed overlay ignored. It
// returns the recorded entry, whose slice is unique by construction,
// stable per ISD-AS, and idempotent to repeat.
Publish(ctx context.Context, entry Entry) (Entry, error)
// PublishHost records the host entry, keyed by its public key. Host
// entries enter the store locally, through the coordination application
// the core alone runs — never through the node-authenticated publish.
PublishHost(ctx context.Context, entry HostEntry) error
// List returns every published entry, nodes and hosts together.
List(ctx context.Context) (Directory, error)
Close() error
}
DirectoryStore is the core's persisted directory, following the trust DB's pattern of a pure interface and shared contract tests.
type Engine ¶
Engine is the trust surface the application consumes: the chain that authenticates the directory channel.
type Entry ¶
type Entry struct {
// IA is the publisher's ISD-AS.
IA addr.IA
// PublicKey is the node's WireGuard public key.
PublicKey PublicKey
// Overlay is the node's overlay subnet, its slice of the tailnet range —
// the slice the directory's store assigned at the node's first
// publication, which never moves.
Overlay netip.Prefix
// HostEndpoint is the host-facing endpoint — the underlay address and shared
// port a host's client dials. The mesh needs it not; the coordination
// service's netmap names it.
HostEndpoint netip.AddrPort
}
Entry is one node's publication: everything another node needs to establish a mesh tunnel to it, and a host's client needs to dial it. The ISD-AS comes from the authenticated publisher's certificate chain, never from the claimed entry, and the slice is the directory's assignment, never the claim. A mesh peer is its ISD-AS, its key, and its subnet: the mesh transport is a SCION service, so no reachability data rides the entry for the mesh's own sake.
type HostEntry ¶
type HostEntry struct {
// PublicKey is the host's WireGuard public key.
PublicKey PublicKey
// MachineKey is the machine key the noise channel authenticated when the
// registration arrived: the record names the machine its node key
// belongs to, and the register answer and the map refuse any other.
// Zero on a record from before the fact — the first machine to present
// such a record binds it.
MachineKey PublicKey
// Addr is the tailnet address the coordination service allocated.
Addr netip.Addr
// IA is the owning node, whose slice of the tailnet range the address
// came from. The record never moves: a re-registering host changes
// nothing.
IA addr.IA
// Note is the approving plugin's own account of its decision.
Note string
}
HostEntry is one host's registry entry: the record the coordination service's gate allocates and the directory distributes. The host's key is its identity — the same key re-registering meets the same entry — and the address, the owning node, the presenting machine, and the approving plugin's note ride beside it.
type Paths ¶
type Paths interface {
Enumerate(ctx context.Context, dst addr.IA) ([]scion.Candidate, error)
LocalPath(dst addr.IA) (*spath.Decoded, error)
}
Paths is the node's path resolution the application calls: the composed candidates the route warm-up ranks, and the path from local state its sends and its directory channel ride.
type PrivateKey ¶
type PrivateKey [32]byte
PrivateKey is the node's WireGuard (curve25519) private key, generated on first start and persisted in the application's own state — never in the configuration file.
func LoadOrCreateKey ¶
func LoadOrCreateKey(stateDir string) (PrivateKey, error)
LoadOrCreateKey returns the application's WireGuard private key, generating and persisting a new one on first start in the application's own state directory.
func (PrivateKey) PublicKey ¶
func (k PrivateKey) PublicKey() PublicKey
PublicKey derives the public key of the private key.
type PublicKey ¶
type PublicKey [32]byte
PublicKey is a WireGuard peer public key.
func ParsePublicKey ¶
ParsePublicKey decodes a peer public key from its hexadecimal form.
type Registry ¶
type Registry interface {
List(ctx context.Context) (Directory, error)
PublishHost(ctx context.Context, entry HostEntry) error
}
Registry is the coordination surface of the core's store: node entries read for the netmap and allocation, host entries written at admission. The store stays this application's; the coordination application borrows the view beside it, never the file.
type Router ¶
type Router interface {
// Route sends one plaintext packet the service produced — a reply or a
// relay — on by its destination, dropping it when it exceeds the overlay
// MTU or nothing claims the destination. It never takes a default.
Route(pkt []byte)
// Deliver hands packets addressed to addr to deliver; the returned
// function uninstalls the delivery, the address counting unroutable
// again once it runs. The delivery is address-exact, never a covering
// prefix.
Deliver(addr netip.Addr, deliver func(pkt []byte)) func()
}
Router is the overlay routing surface the application lends a resident service application: Route carries a plaintext packet the service produced toward its overlay destination, and Deliver installs one address the service serves on — the router handing packets addressed to it to the delivery — for as long as the returned function stands uncalled. The SOCKS application is the shape's first borrower, the way the coordination application borrows the store.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
impl
|
|
|
bbolt
Package bbolt is the application directory's bbolt store, following the trust DB's pattern: a small file, values marshaled beside their keys — node entries keyed by ISD-AS, host entries by public key.
|
Package bbolt is the application directory's bbolt store, following the trust DB's pattern: a small file, values marshaled beside their keys — node entries keyed by ISD-AS, host entries by public key. |
|
dbtest
Package dbtest holds the application directory store's contract tests, shared by every implementation the way the trust DB's are.
|
Package dbtest holds the application directory store's contract tests, shared by every implementation the way the trust DB's are. |