render

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 33 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package render is the bdns renderer: a daemon beside an overlay host that follows the zones its operator names, verifies every state itself, and writes configuration for an ordinary DNS server (docs/render.md).

Index

Constants

View Source
const (
	ReasonRefused     = "refused"       // the refusal list names it; its files are withdrawn
	ReasonUnreachable = "unreachable"   // no overlay host answered
	ReasonNoChain     = "no-chain"      // no host holds a state it believes of the origin
	ReasonVerify      = "verify"        // what a host answered does not verify from seq 0
	ReasonNotOrigin   = "not-origin"    // the identifier is not an origin's
	ReasonKey         = "key"           // the origin's genesis key is not the pinned one
	ReasonNoRecordSet = "no-record-set" // no host holds a state it believes of the origin's record set
	ReasonNotAccepted = "not-accepted"  // the record set's latest state does not list the origin's commitment
	ReasonCritical    = "critical"      // a state has a critical extension this version does not know
	ReasonLapsed      = "lapsed"        // every state read is unmined and past its lapse
	ReasonCheck       = "check"         // what the origin answers breaks a check (spec section 8)
	ReasonSerial      = "serial"        // the origin's serial plus the record set's seq passes 4,294,967,295
	ReasonBackend     = "backend"       // a back end could not write it
)

The reasons a zone is not rendered: the values of the reason label, and of a zone's outcome. A zone that is rendered has none.

View Source
const DefaultCatalogZone = "bdns.catalog.invalid"

DefaultCatalogZone is a catalog zone's name when none is set. The invalid top-level domain is never delegated (RFC 6761).

View Source
const HealthPath = "/health"

HealthPath answers 200: the renderer runs. It does not say a zone is rendered; the metrics do.

Variables

Reasons are every value of the reason label.

Functions

func CatalogFile

func CatalogFile(name string, serial uint32, members map[string][32]byte) []byte

CatalogFile is a catalog zone (RFC 9432, version 2) of the member zones, by domain: its SOA and NS, which a catalog needs and nobody reads, the version, and one PTR for each member.

func CatalogLabel

func CatalogLabel(origin [32]byte) string

CatalogLabel is a member zone's unique label in a catalog zone: the 28 letters of the origin's topic, so a domain that moves to another origin is a new member, and its server starts it afresh (RFC 9432 section 5.4).

func HostsFile

func HostsFile(z *Zone) (file []byte, skipped int)

HostsFile is the zone's addresses as a hosts file: the marker, then one line for each A and AAAA record, the name in full. It also returns how many record sets it leaves out: every other type, a wildcard name, which a hosts file cannot hold, and an address record that is not an address.

func MasterFile

func MasterFile(z *Zone) (file []byte, noNS bool)

MasterFile is the zone as an RFC 1035 master file: the marker, $ORIGIN, the SOA the renderer synthesizes, then every leaf's records in key order, each on a line with its TTL. The same zone gives the same bytes. A zone with no NS record at its apex is written all the same; the second result says so.

Types

type Backend

type Backend interface {
	Name() string
	Reconcile(zones []ZoneConfig) error
	Render(z *Zone) error
	Remove(domain string) error
	Flush(ctx context.Context) error
}

Backend writes zones as one DNS server's configuration. Render and Remove change files; Flush finishes a pass: it writes what spans zones and tells the server, only when a file changed. A back end is used from one goroutine.

Reconcile runs once at start: it withdraws the files of zones no longer configured, by the marker the back end wrote into each, and nothing else in its directory.

A back end never replaces a file it did not write: Render fails with an *ForeignFile when the zone's file is there without the marker.

type BackendConfig

type BackendConfig struct {
	// Kind is "knot" (RFC 1035 master files, and a catalog zone) or
	// "dnsmasq" (hosts files).
	Kind string `json:"kind"`
	// Dir is where a knot back end writes <domain>.zone.
	Dir string `json:"dir,omitempty"`
	// Catalog has a knot back end keep a catalog zone (RFC 9432) of the
	// zones it wrote; CatalogZone is its name (default
	// bdns.catalog.invalid).
	Catalog     bool   `json:"catalog,omitempty"`
	CatalogZone string `json:"catalog_zone,omitempty"`
	// Reload is the command a knot back end runs after a file changed
	// (default ["knotc", "zone-reload"]); an empty list runs nothing.
	Reload *[]string `json:"reload,omitempty"`
	// ReloadTimeoutSeconds bounds one run of the reload command (default
	// 60).
	ReloadTimeoutSeconds int `json:"reload_timeout_seconds,omitempty"`
	// HostsDir is where a dnsmasq back end writes <domain>.hosts.
	HostsDir string `json:"hostsdir,omitempty"`
}

BackendConfig is one back end.

type Config

type Config struct {
	// Hosts are the overlay hosts whose lookup service is asked, in order:
	// the first that answers a chain is read.
	Hosts []string `json:"hosts"`
	// Headers is the header source proofs are checked against (bcommon
	// headers: woc:main, chaintracks:URL, bhs:URL, arcade:URL, or the URL
	// of an overlay bridge). Network is main, test or regtest when the
	// source does not imply it.
	Headers string `json:"headers"`
	Network string `json:"network,omitempty"`
	// Chain is a chain view (bcommon nodeapi: woc:main, woc:test,
	// asset:URL) asked for the proof of a state the host answers without
	// one, each proof checked against Headers. Optional: without it a
	// state is known mined only by the proof a host's answer carries.
	Chain string `json:"chain,omitempty"`
	// Engine names the overlay engine on the same host. With a URL the
	// renderer asks it to carry each zone's topics. Optional.
	Engine EngineConfig `json:"engine,omitzero"`
	// Zones are the zones rendered, each by its operator's word: a domain,
	// the origin's identifier and the origin's genesis key.
	Zones []ZoneConfig `json:"zones"`
	// Backends are the DNS servers written for; every zone goes to each.
	Backends []BackendConfig `json:"backends"`
	// RefuseFile is the refusal list (see Refusals). Optional.
	RefuseFile string `json:"refuse_file,omitempty"`
	// Listen is an address the metrics (/metrics) and the health path
	// (/health) are served on. Optional.
	Listen string `json:"listen,omitempty"`
	// PollMS is how often each zone's chains are read again (default 2000).
	PollMS int `json:"poll_ms,omitempty"`
	// Workers is how many zones are read and judged at once (default 8).
	Workers int `json:"workers,omitempty"`
	// ZoneTimeoutSeconds bounds the read of one zone's chains in one pass
	// (default 30): a host or a zone that is slow does not hold the others
	// back longer.
	ZoneTimeoutSeconds int `json:"zone_timeout_seconds,omitempty"`
}

Config is the renderer's configuration file.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig reads and checks a configuration file. A member the file names that this version does not know is an error.

type Dnsmasq

type Dnsmasq struct {
	// contains filtered or unexported fields
}

Dnsmasq is the back end for dnsmasq: one hosts file a zone, <hostsdir>/<domain>.hosts, holding the zone's A and AAAA records. On Linux dnsmasq reads a file of --hostsdir when it changes, so nothing is signaled.

func NewDnsmasq

func NewDnsmasq(c BackendConfig, skipped func(domain string, n int)) *Dnsmasq

NewDnsmasq is a dnsmasq back end over c. skipped may be nil.

func (*Dnsmasq) Flush

func (d *Dnsmasq) Flush(context.Context) error

func (*Dnsmasq) Name

func (d *Dnsmasq) Name() string

func (*Dnsmasq) Reconcile

func (d *Dnsmasq) Reconcile(zones []ZoneConfig) error

Reconcile removes the hosts files of zones no longer configured.

func (*Dnsmasq) Remove

func (d *Dnsmasq) Remove(domain string) error

func (*Dnsmasq) Render

func (d *Dnsmasq) Render(z *Zone) error

type EngineConfig

type EngineConfig struct {
	// URL is the engine's base URL, such as http://127.0.0.1:8280.
	URL string `json:"url,omitempty"`
	// AskTTLSeconds is an ask's lifetime (default 600); it is asked again
	// at half of it. An engine refuses one above its own bound.
	AskTTLSeconds int `json:"ask_ttl_seconds,omitempty"`
}

EngineConfig names the overlay engine asked for topics.

type ForeignFile

type ForeignFile struct{ Path string }

ForeignFile is a file in a back end's directory, at a path the back end writes, that does not carry the back end's marker for what it would write there. It is never replaced.

func (*ForeignFile) Error

func (e *ForeignFile) Error() string

type Knot

type Knot struct {
	// contains filtered or unexported fields
}

Knot is the back end for Knot DNS, and for any server that loads RFC 1035 master files: one file a zone, <dir>/<domain>.zone, and with a catalog one more, <dir>/<catalog zone>.zone, that lists them.

func NewKnot

func NewKnot(c BackendConfig, logf func(string, ...any)) *Knot

NewKnot is a knot back end over c.

func (*Knot) Flush

func (k *Knot) Flush(ctx context.Context) error

Flush writes the catalog when its members changed and runs the reload command when any file changed. The files of withdrawn zones are deleted once the catalog no longer lists them: after the reload, so the server is not sent looking for a file that is gone, and all the same when the reload fails or is waiting to be tried again. A reload that fails is run again after 1 s, doubling to a minute, not at every pass.

func (*Knot) Name

func (k *Knot) Name() string

func (*Knot) Reconcile

func (k *Knot) Reconcile(zones []ZoneConfig) error

Reconcile takes the files of configured zones as the catalog's members, so a zone stays on the state it was last rendered at across a restart, and withdraws the files of zones no longer configured as a running renderer does: at the first Flush the catalog stops listing them, the server reloads, and then they are deleted.

func (*Knot) Remove

func (k *Knot) Remove(domain string) error

Remove withdraws a zone: the catalog stops listing it, so the server drops it at the reload, and its file is removed. Without a catalog only the file goes: a server that has the zone loaded answers it until its operator takes it out of the server's configuration, and that is said.

func (*Knot) Render

func (k *Knot) Render(z *Zone) error

Render writes the zone's master file when it differs from the one there.

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

Metrics are the renderer's metrics, in Prometheus form. Every method is safe on a nil Metrics.

func NewMetrics

func NewMetrics(version string) *Metrics

NewMetrics are metrics for one renderer, with the Go runtime's and the process's own.

func (*Metrics) Handler

func (m *Metrics) Handler() http.Handler

Handler serves the metrics.

type Refusals

type Refusals struct {
	// contains filtered or unexported fields
}

Refusals is what a renderer refuses to render: a zone by its origin's identifier, by its domain, or by an owner key. One entry a line, "origin:<hex>", "domain:<name>" or "key:<hex>"; blank lines and lines starting with # are skipped, and so is what follows " #" on a line. The file is read again when it changes.

A domain entry refuses that domain and every domain under it. A key entry refuses a zone whose origin or record set has that genesis key or that owner now.

A line that is not an entry is not dropped in silence: it is a problem of the list (Problems), and every other line applies.

func OpenRefusals

func OpenRefusals(path string) (*Refusals, error)

OpenRefusals reads a refusal list; an empty path is a list that refuses nothing. A file that cannot be read is an error; a line that is not an entry is a problem of the list.

func (*Refusals) Has

func (d *Refusals) Has(kind, value string) bool

Has reports whether kind:value is refused.

func (*Refusals) HasDomain

func (d *Refusals) HasDomain(domain string) bool

HasDomain reports whether domain, or a domain it is under, is refused.

func (*Refusals) Problems

func (d *Refusals) Problems() int

Problems is how many lines of the list in force are not entries, or 1 when the file could not be read.

func (*Refusals) Refresh

func (d *Refusals) Refresh()

Refresh loads the file again when its time or size changed. A file that cannot be read leaves the last list in force, with that as a problem: a refusal list never fails open.

func (*Refusals) Report

func (d *Refusals) Report() []string

Report returns the problems once for each load: nil until the list is read again.

type Renderer

type Renderer struct {

	// Metrics is optional.
	Metrics *Metrics
	// Now is the clock a state's lapse is judged by.
	Now func() time.Time
	// Logf reports a change; nil logs nothing.
	Logf func(format string, args ...any)
	// contains filtered or unexported fields
}

Renderer follows the configured zones and writes them to the back ends.

Each pass reads every zone's origin chain and the record set chain it names from the lookup service, verifies both from seq 0 (chainread, as bdns show does), and judges the latest state it believes itself: a host's word that a state is mined, believed or renderable is never taken. A zone whose state does not pass is not written: its files stay as the last pass that did left them. A refused zone's files are removed.

func New

func New(c *Config) (*Renderer, error)

New is a renderer over c, with a back end for each c names and the refusal list read.

func (*Renderer) Backends

func (r *Renderer) Backends() []Backend

Backends are the renderer's back ends, in the configuration's order.

func (*Renderer) Handler

func (r *Renderer) Handler() http.Handler

Handler serves /metrics (when the renderer has metrics) and the health path.

func (*Renderer) ListProblems

func (r *Renderer) ListProblems() int

ListProblems is how many lines of the refusal list in force are not entries (1 when the list cannot be read).

func (*Renderer) Once

func (r *Renderer) Once(ctx context.Context) (map[string]string, error)

Once renders every zone once and returns the zones not rendered, each with its reason.

func (*Renderer) Pass

func (r *Renderer) Pass(ctx context.Context) (asked bool)

Pass reads, judges and writes every zone once, then flushes the back ends. Zones are read and judged several at once (workers), each under its own deadline (zone_timeout_seconds), so a host or a zone that is slow holds no other back longer than that; the back ends are written from this goroutine alone, in the configuration's order. It reports whether an ask to the engine changed.

func (*Renderer) Reasons

func (r *Renderer) Reasons() map[string]string

Reasons are the zones not rendered at the last pass, by domain.

func (*Renderer) Run

func (r *Renderer) Run(ctx context.Context) error

Run reconciles, serves the metrics and the health path when the configuration names an address, and renders until ctx is done.

func (*Renderer) Start

func (r *Renderer) Start() error

Start reconciles every back end's directory with the configured zones. It runs once, before the first pass.

type SOAConfig

type SOAConfig struct {
	// MName defaults to the first apex NS record's target, or ns.<domain>
	// when the zone has none; RName to hostmaster.<domain>. Both are full
	// names, with or without the trailing dot.
	MName string `json:"mname,omitempty"`
	RName string `json:"rname,omitempty"`
	// TTL is the SOA record's own (default 3600).
	TTL     uint32 `json:"ttl,omitempty"`
	Refresh uint32 `json:"refresh,omitempty"` // default 3600
	Retry   uint32 `json:"retry,omitempty"`   // default 600
	Expire  uint32 `json:"expire,omitempty"`  // default 604800
	Minimum uint32 `json:"minimum,omitempty"` // default 300
}

SOAConfig is the SOA record's fields other than the serial, which is the origin state's. A zero or empty field takes its default.

type Skipped

type Skipped struct {
	Leaf *zonerec.Leaf
	// Why is "a name would pass 255 bytes under the domain" or "its data
	// is not data of its type".
	Why string
}

Skipped is a leaf left out of a zone, and why.

func Fit

func Fit(leaves []*zonerec.Leaf, domain string) (kept []*zonerec.Leaf, skipped []Skipped)

Fit splits leaves into those written under a domain and those left out: a leaf whose name, or a name in its data, would pass 255 bytes on the wire under the domain is not answered there (spec section 6), and neither is a leaf with a record that is not data of its type, which a DNS server would refuse the whole zone for.

type Zone

type Zone struct {
	// Domain is the zone's name in lower case, with no trailing dot.
	Domain string
	// Origin is the origin's identifier.
	Origin [32]byte
	// Serial is the SOA serial: the origin state's serial plus the record
	// set state's seq.
	Serial uint32
	// SOA is the configured SOA fields; an empty or zero one is defaulted.
	SOA SOAConfig
	// Leaves are what the origin answers, in key order, each fitting
	// under Domain (Fit).
	Leaves []*zonerec.Leaf
}

Zone is one zone as a back end is given it: what its origin answers, verified and checked, under the domain its operator configured.

type ZoneConfig

type ZoneConfig struct {
	Domain string `json:"domain"`
	// Origin is the origin's identifier, 64 lower-case hex digits.
	Origin string `json:"origin"`
	// Key is the origin's genesis key, 66 hex digits. It is pinned: an
	// origin chain of another genesis key is never rendered.
	Key string `json:"key"`
	// SOA overrides the SOA record the renderer writes. Optional.
	SOA SOAConfig `json:"soa,omitzero"`
	// contains filtered or unexported fields
}

ZoneConfig is one zone.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL