Name resolver for Yggdrasil. Supports three resolution strategies: .pk.ygg public key mapping, IP literals, and
DNS queries over the Yggdrasil network.
flowchart LR
Name["name"] --> PkYgg{".pk.ygg?"}
PkYgg -->|" yes "| Decode["hex → ed25519 → IPv6"]
PkYgg -->|" no "| IPLit{"IP literal?"}
IPLit -->|" yes "| Return["net.IP"]
IPLit -->|" no "| DNS{"DNS?"}
DNS -->|" hasDNS "| Lookup["LookupIP → ip6"]
DNS -->|" no "| Err["ErrNoNameserver"]
Decode --> Return
Lookup --> Return
r := resolver.New(dialer, "200::1:53") // DNS over Yggdrasil
r := resolver.New(dialer, "") // no DNS, only .pk.ygg and literals| Parameter | Description |
|---|---|
dialer |
proxy.ContextDialer — dialer for DNS queries |
nameserver |
DNS server address (host:port or host, port → 53) |
If nameserver is empty — DNS resolution is disabled, only .pk.ygg and IP literals work.
The resolver uses PreferGo: true (pure Go DNS, no cgo).
ctx, ip, err := r.Resolve(ctx, "home.abc123def456.pk.ygg")Returns net.IP and the original ctx (for passing values through the chain).
Strategies are tried in decreasing order of specificity:
.pk.ygg— if the name ends with.pk.ygg- IP literal — if the name parses as an IP address
- DNS — if a nameserver is configured
The first successful strategy wins.
Suffix: NameMappingSuffix = ".pk.ygg"
<hex-encoded-ed25519-key>.pk.ygg → IPv6 via address.AddrForKey()
Subdomains are allowed — only the last segment before .pk.ygg is used:
subdomain.abc123...def456.pk.ygg → abc123...def456 is taken
The key must be exactly 32 bytes after hex decoding.
IPv4 and IPv6 addresses are returned as-is:
200::1 → net.IP{200::1}
192.168.1.1 → net.IP{192.168.1.1}
IPv6 resolution via the configured nameserver. If no nameserver is set — ErrNoNameserver is returned.
r.resolver.LookupIP(ctx, "ip6", name)Returns the first address found. If no addresses are found — ErrNoAddresses.
| Variable | Description |
|---|---|
ErrNoNameserver |
DNS server is not configured |
ErrNoAddresses |
DNS query returned no addresses |
ErrInvalidKeyLength |
Public key is not 32 bytes |