Documentation
¶
Overview ¶
Package daemon provides APIs for SCION applications to interact with the SCION control plane. It supports two modes of operation:
- Standalone mode: Runs daemon functionality in-process, communicating directly with the control service. No separate daemon process required.
- Remote mode: Connects to a SCION daemon process via gRPC.
Quick Start ¶
Use NewAutoConnector with WithDaemon (for remote daemon) or WithConfigDir (for standalone mode):
// Remote daemon connection
conn, err := daemon.NewAutoConnector(ctx, daemon.WithDaemon("127.0.0.1:30255"))
// Or standalone mode with local config
conn, err := daemon.NewAutoConnector(ctx, daemon.WithConfigDir("/etc/scion"))
if err != nil {
log.Fatal(err)
}
defer conn.Close()
// Query paths to a destination
paths, err := conn.Paths(ctx, dstIA, srcIA, daemon.PathReqFlags{})
If both WithDaemon and WithConfigDir are set, WithDaemon takes priority. Empty string options are ignored, making it safe to pass values from CLI flags:
conn, err := daemon.NewAutoConnector(ctx,
daemon.WithDaemon(daemonAddr), // may be empty
daemon.WithConfigDir(configDir), // may be empty
)
Standalone Mode ¶
Standalone mode runs the daemon logic in-process, which is useful for:
- Deployments without a separate daemon process
- CLI tools that need minimal dependencies
- Testing and development
For more control over standalone mode, use NewStandaloneConnector directly:
// Load topology information
localASInfo, err := daemon.LoadASInfoFromFile("/etc/scion/topology.json")
if err != nil {
log.Fatal(err)
}
// Create standalone connector with options
conn, err := daemon.NewStandaloneConnector(ctx, localASInfo,
daemon.WithCertsDir("/etc/scion/certs"), // TRC certificates location
daemon.WithMetrics(), // Enable Prometheus metrics
daemon.WithPeriodicCleanup(), // Enable path DB cleanup
)
if err != nil {
log.Fatal(err)
}
defer conn.Close()
Standalone mode requires:
- topology.json: Network topology file with control service addresses
- certs/: Directory containing TRC files for segment verification (required via WithCertsDir)
To disable segment verification (NOT recommended for production):
conn, err := daemon.NewStandaloneConnector(ctx, localASInfo,
daemon.WithDisabledSegVerification(),
)
Remote Mode ¶
Remote mode connects to a running SCION daemon via gRPC. Use NewService to create a connection factory:
svc := daemon.NewService("127.0.0.1:30255")
conn, err := svc.Connect(ctx)
if err != nil {
log.Fatal(err)
}
defer conn.Close()
The Connector Interface ¶
The Connector interface is the central abstraction of this package. All connection modes (standalone, remote) implement this interface, allowing applications to work with any backend transparently.
See Connector for all available methods.
Loading Topology ¶
To get topology information (local IA, port range, interfaces) from a connector:
// One-time load topo, err := daemon.LoadTopology(ctx, conn) // Auto-reloading topology (for long-running applications) reloadingTopo, err := daemon.NewReloadingTopology(ctx, conn) go reloadingTopo.Run(ctx, 30*time.Second) topo := reloadingTopo.Topology()
Helper Types ¶
The package provides helper types for common patterns:
// Querier wraps a Connector for path queries
querier := daemon.Querier{Connector: conn, IA: localIA}
paths, err := querier.Query(ctx, dstIA)
// RevHandler adapts Connector for snet.RevocationHandler
revHandler := daemon.RevHandler{Connector: conn}
// TopoQuerier provides topology queries
topoQuerier := daemon.TopoQuerier{Connector: conn}
addr, err := topoQuerier.UnderlayAnycast(ctx, addr.SvcCS)
Index ¶
- Constants
- func LoadASInfoFromFile(topoFile string) (asinfo.LocalASInfo, error)
- func LoadTopology(ctx context.Context, conn Connector) (snet.Topology, error)
- type AutoConnectorOption
- type Connector
- type Metrics
- type Querier
- type ReloadingTopology
- type RevHandler
- type Service
- type StandaloneConnectorOption
- type TopoQuerier
Constants ¶
const ( // DefaultAPIAddress contains the system default for a daemon API socket. DefaultAPIAddress = "127.0.0.1:30255" // DefaultAPIPort contains the default port for a daemon client API socket. DefaultAPIPort = 30255 )
Variables ¶
This section is empty.
Functions ¶
func LoadASInfoFromFile ¶ added in v0.15.0
func LoadASInfoFromFile(topoFile string) (asinfo.LocalASInfo, error)
LoadASInfoFromFile loads local AS Information from a file. The returned struct can be passed to NewStandaloneConnector.
Types ¶
type AutoConnectorOption ¶ added in v0.15.0
type AutoConnectorOption func(*autoConnectorOptions)
AutoConnectorOption is a functional option for NewAutoConnector and overrides the default options.
func WithConfigDir ¶ added in v0.15.0
func WithConfigDir(dir string) AutoConnectorOption
WithConfigDir sets the configuration directory for standalone mode. The directory should contain topology.json and a certs/ subdirectory. If both WithDaemon and WithConfigDir are set, WithDaemon takes priority.
func WithDaemon ¶ added in v0.15.0
func WithDaemon(addr string) AutoConnectorOption
WithDaemon sets the daemon address for a gRPC connector. When set, the connector will connect to the specified daemon via gRPC. If both WithDaemon and WithConfigDir are set, WithDaemon takes priority.
type Connector ¶
type Connector interface {
// LocalIA requests from the daemon the local ISD-AS number.
// TODO: Caching this value to avoid contacting the daemon, since this never changes.
LocalIA(ctx context.Context) (addr.IA, error)
// PortRange returns the beginning and the end of the SCION/UDP endhost port range, configured
// for the local IA.
PortRange(ctx context.Context) (uint16, uint16, error)
// Interfaces returns the map of interface identifiers to the underlay internal address.
Interfaces(ctx context.Context) (map[uint16]netip.AddrPort, error)
// Paths requests from the daemon a set of end to end paths between the source and destination.
Paths(ctx context.Context, dst, src addr.IA, f types.PathReqFlags) ([]snet.Path, error)
// ASInfo requests from the daemon information about AS ia, the zero IA can be
// used to detect the local IA.
ASInfo(ctx context.Context, ia addr.IA) (types.ASInfo, error)
// SVCInfo requests from the daemon information about addresses and ports of
// infrastructure services. Slice svcTypes contains a list of desired
// service types. If unset, a fresh (i.e., uncached) answer containing all
// service types is returned. The reply is a map from service type to a list
// of URIs of the service in the local AS.
SVCInfo(ctx context.Context, svcTypes []addr.SVC) (map[addr.SVC][]string, error)
// RevNotification sends a RevocationInfo message to the daemon.
RevNotification(ctx context.Context, revInfo *path_mgmt.RevInfo) error
// DRKeyGetASHostKey requests a AS-Host Key from the daemon.
DRKeyGetASHostKey(ctx context.Context, meta drkey.ASHostMeta) (drkey.ASHostKey, error)
// DRKeyGetHostASKey requests a Host-AS Key from the daemon.
DRKeyGetHostASKey(ctx context.Context, meta drkey.HostASMeta) (drkey.HostASKey, error)
// DRKeyGetHostHostKey requests a Host-Host Key from the daemon.
DRKeyGetHostHostKey(ctx context.Context, meta drkey.HostHostMeta) (drkey.HostHostKey, error)
// Close shuts down the connection to the daemon.
Close() error
}
A Connector is used to query the SCION daemon. All connector methods block until either an error occurs, or the method successfully returns.
func NewAutoConnector ¶ added in v0.15.0
func NewAutoConnector(ctx context.Context, opts ...AutoConnectorOption) (Connector, error)
NewAutoConnector creates a new Connector based on supplied options.
Priority order:
- If WithDaemon was supplied, return a gRPC connector to the specified daemon.
- If WithConfigDir was supplied, use standalone mode with the specified directory.
- Return error if neither option was provided.
Note: In standalone mode, topology information is loaded once and never reloaded. For dynamic updates, use NewStandaloneConnector with a custom [LocalASInfo].
func NewStandaloneConnector ¶ added in v0.15.0
func NewStandaloneConnector( ctx context.Context, localASInfo asinfo.LocalASInfo, opts ...StandaloneConnectorOption, ) (Connector, error)
NewStandaloneConnector creates a daemon Connector that runs locally without a daemon process. It requires a LocalASInfo (use LoadASInfoFromFile to create one from a file) and accepts functional options for configuration.
The returned Connector can be used directly by SCION applications instead of connecting to a daemon via gRPC.
Example:
localASInfo, err := daemon.LoadASInfoFromFile("/path/to/topology.json")
if err != nil { ... }
conn, err := daemon.NewStandaloneConnector(ctx, localASInfo,
daemon.WithCertsDir("/path/to/certs"),
daemon.WithMetrics(),
)
type Metrics ¶
type Metrics struct {
Connects metrics.Counter
PathsRequests metrics.Counter
ASRequests metrics.Counter
InterfacesRequests metrics.Counter
ServicesRequests metrics.Counter
InterfaceDownNotifications metrics.Counter
}
Metrics can be used to inject metrics counters into the SCION Daemon API. Each counter may be set or unset.
type ReloadingTopology ¶ added in v0.13.0
type ReloadingTopology struct {
// contains filtered or unexported fields
}
ReloadingTopology is a topology that reloads the interface information periodically. It is safe for concurrent use.
func NewReloadingTopology ¶ added in v0.13.0
func NewReloadingTopology(ctx context.Context, conn Connector) (*ReloadingTopology, error)
NewReloadingTopology creates a new ReloadingTopology that reloads the interface information periodically. The Run method must be called for interface information to be populated.
func (*ReloadingTopology) Run ¶ added in v0.13.0
func (t *ReloadingTopology) Run(ctx context.Context, period time.Duration)
func (*ReloadingTopology) Topology ¶ added in v0.13.0
func (t *ReloadingTopology) Topology() snet.Topology
type RevHandler ¶
type RevHandler struct {
Connector Connector
}
RevHandler is an adapter for SCION Daemon connector to implement snet.RevocationHandler.
type Service ¶
type Service struct {
// Address is the address of the SCION daemon to connect to.
Address string
// Metrics are the metric counters that should be incremented when using the
// connector.
Metrics Metrics
}
Service exposes the API to connect to a SCION daemon service.
func NewService ¶
NewService returns a SCION Daemon API connection factory.
type StandaloneConnectorOption ¶ added in v0.15.0
type StandaloneConnectorOption func(*standaloneConnectorOptions)
StandaloneConnectorOption is a functional option for NewStandaloneConnector.
func WithCertsDir ¶ added in v0.15.0
func WithCertsDir(dir string) StandaloneConnectorOption
WithCertsDir sets the directory containing TRC certificates for trust material. This option is required unless segment verification is disabled.
func WithDisabledSegVerification ¶ added in v0.15.0
func WithDisabledSegVerification() StandaloneConnectorOption
WithDisabledSegVerification disables segment verification. WARNING: This should NOT be used in production!
func WithMetrics ¶ added in v0.15.0
func WithMetrics() StandaloneConnectorOption
WithMetrics enables metrics collection for the standalone daemon.
func WithPeriodicCleanup ¶ added in v0.15.0
func WithPeriodicCleanup() StandaloneConnectorOption
WithPeriodicCleanup enables periodic cleanup of path database and revocation cache.
type TopoQuerier ¶
type TopoQuerier struct {
Connector Connector
}
TopoQuerier can be used to get topology information from the SCION Daemon.
func (TopoQuerier) UnderlayAnycast ¶
UnderlayAnycast provides any address for the given svc type.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package fetcher implements path segment fetching, verification and combination logic for SCIOND.
|
Package fetcher implements path segment fetching, verification and combination logic for SCIOND. |
|
mock_fetcher
Package mock_fetcher is a generated GoMock package.
|
Package mock_fetcher is a generated GoMock package. |
|
Package mock_daemon is a generated GoMock package.
|
Package mock_daemon is a generated GoMock package. |
|
private
|
|