Yggdrasil node with a userspace TCP/UDP stack. Wraps yggcore.Core and gVisor netstack, providing standard
Go interfaces for networking: net.Conn, net.Listener, net.PacketConn.
- Overview
- Initialization
- Network operations
- Node information
- Peer management
- Components
- Shutdown
- Errors
flowchart TB
subgraph Obj["Obj — Yggdrasil node"]
direction TB
New["New(cfg)"]
Dial["DialContext(ctx, net, addr)"]
Lis["Listen(net, addr)"]
LisP["ListenPacket(net, addr)"]
Peers["AddPeer / RemovePeer / GetPeers"]
MC["EnableMulticast / DisableMulticast"]
Adm["EnableAdmin / DisableAdmin"]
Close["Close()"]
end
subgraph Netstack["netstackObj — gVisor"]
TCP["TCP"]
UDP["UDP"]
end
subgraph NIC["nicObj — LinkEndpoint"]
RW["ipv6rwc"]
end
subgraph Core["yggcore.Core"]
Routing["routing"]
end
Dial --> Netstack
Lis --> TCP
LisP --> UDP
Netstack --> NIC
NIC --> Core
Layers from bottom to top:
- yggcore.Core — routing and peer management
- ipv6rwc — packet I/O between Yggdrasil and NIC
- nicObj — implements gVisor
stack.LinkEndpoint, bridges ipv6rwc and netstack - netstackObj — TCP/UDP protocols on top of gVisor
- Obj — public API, lifecycle, component management
obj, err := core.New(core.ConfigObj{
Config: nodeCfg, // *config.NodeConfig; nil — random keys
Logger: logger, // nil — logs are discarded
CoreStopTimeout: 5 * time.Second,
RSTQueueSize: 100, // 0 → 100 by default
})
defer obj.Close()New creates a yggcore.Core, then sets up netstack with gVisor. After successful creation the node is ready to accept
connections and connect to peers.
All methods are compatible with standard Go interfaces. Supported networks: tcp, tcp6, udp, udp6.
DialContext(ctx context.Context, network, address string) (net.Conn, error)Connects to an Yggdrasil address. Compatible with http.Transport.DialContext.
Listen(network, address string) (net.Listener, error)Creates a TCP listener. Address format: :port or [ipv6]:port. The listener is automatically closed on Close().
ListenPacket(network, address string) (net.PacketConn, error)Creates a UDP listener. Address format is the same as Listen. Automatically closed on Close().
| Method | Returns | Description |
|---|---|---|
Address() |
net.IP |
Node's IPv6 address in the 200::/7 range |
Subnet() |
net.IPNet |
Routable /64 subnet |
PublicKey() |
ed25519.PublicKey |
Node's public key (32 bytes) |
MTU() |
uint64 |
Network interface MTU |
RSTDropped() |
int64 |
Number of dropped RST packets |
obj.AddPeer("tls://203.0.113.55:443")
obj.RemovePeer("tls://203.0.113.55:443")
peers := obj.GetPeers() // []yggcore.PeerInfoURI formats: tcp://, tls://, quic://, ws://, wss://.
Multicast and Admin socket are toggleable components with double-enable protection. Each component
is thread-safe
and supports the Enable → Disable → Enable cycle.
obj.EnableMulticast(logger) // mDNS discovery on the local network
obj.DisableMulticast()Interfaces for discovery are taken from NodeConfig.MulticastInterfaces. Interface patterns are compiled as
regular
expressions.
obj.EnableAdmin("unix:///tmp/ygg.sock")
obj.EnableAdmin("tcp://127.0.0.1:9001")
obj.DisableAdmin()Once enabled, registers handlers for inter-component communication.
err := obj.Close() // safe for repeated callsShutdown order:
flowchart LR
A["DisableMulticast"] --> B["DisableAdmin"]
B --> C["Close listeners"]
C --> D["Stop yggcore.Core"]
D --> E["Close netstack"]
If CoreStopTimeout is set and the core does not stop within that time — ErrCloseTimedOut is returned.
| Variable | Description |
|---|---|
ErrNotAvailable |
Netstack is not initialized |
ErrCloseTimedOut |
Core did not stop within CoreStopTimeout |
ErrAlreadyEnabled |
Component is already enabled |
ErrAdminDisabled |
Admin socket is not active |
ErrUnsupportedNetwork |
Unsupported network type (not tcp/udp) |
ErrPortOutOfRange |
Port is out of the 0–65535 range |
ErrInvalidAddress |
Invalid IP address |