Documentation
¶
Index ¶
- Variables
- func GenerateKey() ([]byte, string, error)
- func HostFromKey(pemPath string) (string, error)
- func ResolveName(configured string, domain string, host string) string
- func ValidateInfoConfig(info stconf.InfoObj) error
- func ValidateYggConfig(yg stconf.YggObj) error
- func WriteKeyFile(filePath string, pemBytes []byte) error
- type NodeInterface
- type Obj
- func (obj *Obj) Address() net.IP
- func (obj *Obj) Close(ctx context.Context) error
- func (obj *Obj) DialContext(ctx context.Context, network, address string) (net.Conn, error)
- func (obj *Obj) Enabled() bool
- func (obj *Obj) Host() string
- func (obj *Obj) ListenerFor(transport TransportType) (net.Listener, error)
- func (obj *Obj) OwnsHost(host string) bool
- func (obj *Obj) PeerList() ([]PeerSnapshotObj, bool)
- func (obj *Obj) RegisterMetrics(meterObj metric.Meter) error
- func (obj *Obj) Snapshot() (SnapshotObj, bool)
- type PeerSnapshotObj
- type SnapshotObj
- type TransportType
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDisabled means a ygg operation was requested with empty yggdrasil.pem_key. ErrDisabled = errors.New("yggdrasil mesh is disabled (yggdrasil.pem_key is empty)") )
Functions ¶
func GenerateKey ¶
GenerateKey creates a random node private key and returns its PKCS#8 PEM plus ygg host. One random ed25519 key is already unique enough; the full node identity keeps the whole key through host and certificate.
func HostFromKey ¶
HostFromKey derives the ygg host directly from a PEM key without starting a node. Rebuild-cache/self-test uses it to rebuild host-sensitive artifacts under the same entry host as serving, without network boot.
func ResolveName ¶
ResolveName returns final info.Name: configured value, normalized domain or ygg host, then stable target.Name fallback. The result is always valid for the info sigil.
func ValidateInfoConfig ¶
ValidateInfoConfig checks the identity card by ratatoskr info-sigil rules, including field and value limits. Empty Name is allowed because runtime supplies a default.
func ValidateYggConfig ¶ added in v0.4.0
ValidateYggConfig checks ygg.peers against ratatoskr peermgr rules so that --validate-config rejects configurations node startup would reject. Pre-existing deployments must keep starting: checks on fields that existed before v1 stay warn-or-clamp at runtime, hard errors apply only to the new fields and to configurations the library itself would reject. A disabled mesh (empty pem_key) skips the checks entirely because the peer list is inert. Invalid or duplicate URIs follow the library contract: they are dropped with startup warnings, and only a list with no usable candidate fails, because node startup would fail on it anyway.
func WriteKeyFile ¶
WriteKeyFile writes a private key PEM with secret permissions: 0o600, explicit Chmod, and O_NOFOLLOW. The caller decides whether the file may already exist or be overwritten.
Types ¶
type NodeInterface ¶
type NodeInterface interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
ListenerFor(transport TransportType) (net.Listener, error)
Host() string
Address() net.IP
OwnsHost(host string) bool
Enabled() bool
PeerList() ([]PeerSnapshotObj, bool)
Close(ctx context.Context) error
}
NodeInterface is the ygg node transport boundary and the only contract for source/server.
type Obj ¶
type Obj struct {
// contains filtered or unexported fields
}
Obj owns the node. In disabled mode node==nil and enabled==false.
func New ¶
New starts a node when pem_key is set and returns a disabled Obj when it is empty. The node lifetime is owned by Close, never by a caller context: tying it to the signal context would begin mesh self-shutdown at SIGTERM, before the HTTP listeners drain ygg requests. With a logger, ratatoskr events go through the shared pipeline; otherwise library noise is discarded.
func (*Obj) Close ¶
Close stops the resolver, then the node, within ctx budget; it is idempotent and concurrent-safe, and disabled mode is a no-op. Teardown runs once; every caller observes the same result through closeDone. The node bounds its own teardown by the configured CloseTimeout and finishes it in the background when that budget expires, so an early ctx exit never strands shutdown.
func (*Obj) DialContext ¶
DialContext resolves host (<hex>.pk.ygg or IPv6 literal) into a 200::/7 transport address and opens a connection through the node netstack. It can be used as http.Transport.DialContext and net/rpc dialer.
func (*Obj) ListenerFor ¶
func (obj *Obj) ListenerFor(transport TransportType) (net.Listener, error)
ListenerFor returns the ygg-entry listener on the node address, port 80.
func (*Obj) OwnsHost ¶
OwnsHost reports whether host belongs to the ygg naming scheme. This is a static naming fact and remains true for disabled nodes; reachability is gated separately by Enabled.
func (*Obj) PeerList ¶ added in v0.4.0
func (obj *Obj) PeerList() ([]PeerSnapshotObj, bool)
PeerList returns the detailed peer list: credential-redacted, deterministically sorted, and capped at cPeerListMax entries. Results are cached for the telemetry snapshot interval, so request pressure costs at most one live node read per interval. Callers must treat the returned slice as read-only. ok is false on a disabled or closing node.
func (*Obj) RegisterMetrics ¶ added in v0.4.0
RegisterMetrics publishes flat ygg aggregates; a disabled node registers nothing. Per-peer series stay out of the exposition on purpose: inbound peers are foreign input and would grow label cardinality without bound. Traffic sums are gauges, not counters, because a disconnected peer drops out of the sum and makes it non-monotonic.
func (*Obj) Snapshot ¶ added in v0.4.0
func (obj *Obj) Snapshot() (SnapshotObj, bool)
Snapshot returns cheap peer aggregates; ok is false on a disabled or closing node. It runs every telemetry collect interval, so it sums counters without building per-peer DTOs. The snapMu read lock pairs with the Close write barrier: the library does not guard node state reads after Close, so no snapshot may overlap node teardown.
type PeerSnapshotObj ¶ added in v0.4.0
type PeerSnapshotObj struct {
URI string
Up bool
Inbound bool
PublicKey string
LatencyNanos int64
Cost uint64
RXBytes uint64
TXBytes uint64
UptimeSeconds float64
LastError string
LastErrorTime time.Time
}
PeerSnapshotObj is one peer connection at snapshot time.
type SnapshotObj ¶ added in v0.4.0
type SnapshotObj struct {
PeersKnown int
PeersUp int
PeersInbound int
ActiveSelected int
RXBytes uint64
TXBytes uint64
BestLatencyNanos int64
// NoReachableNotifications counts observed isolation notifications. The library delivers them
// best-effort into a capacity-one channel, so rapid bursts coalesce: treat it as a lower bound.
NoReachableNotifications uint64
}
SnapshotObj carries the cheap ygg aggregates for the metrics group.
type TransportType ¶
type TransportType uint8
TransportType identifies which listener mod/server requests.
const ( // TransportYgg is the ygg-entry listener, the only mesh transport. TransportYgg TransportType = iota + 1 )