dyndns

package
v0.60.14 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package dyndns implements a dynamic-DNS daemon that periodically detects a host's public IP and pushes updates to a DNS provider when the IP changes.

Per docs/plans/2026-05-20-dns-providers.md T14..T16.

The package is intentionally provider-agnostic: callers supply an Updater closure that talks to their DNS driver of choice (DO, Namecheap, Hover, etc.) via wfctl's existing infra.dns surface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Detectors quorum the public IP. Default: HTTPDetector against
	// icanhazip.com + ifconfig.me + ipify.org (need ≥ 2 agreeing).
	Detectors []IPDetector

	// PollInterval is the steady-state interval between IP checks.
	// Default 5m. Must be >= 30s.
	PollInterval time.Duration

	// QuorumSize is the number of detectors that must agree before
	// an update fires. Default = (len(Detectors)+1)/2 — simple
	// majority. Set to 1 for single-source mode.
	QuorumSize int

	// MaxBackoff caps the exponential backoff applied after
	// consecutive Update failures. Default 1h.
	MaxBackoff time.Duration

	// Update is the callback that applies a new IP to DNS.
	Update Updater

	// Now is injectable for tests. Defaults to time.Now.
	Now func() time.Time

	// Sleep is injectable for tests. Defaults to time.Sleep.
	Sleep func(time.Duration)
}

Config controls the daemon loop.

type Daemon

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

Daemon runs the detect → diff → update loop.

func New

func New(cfg Config) (*Daemon, error)

New builds a Daemon. Returns an error if Config is missing fields.

func (*Daemon) Current

func (d *Daemon) Current() net.IP

Current returns the most recently confirmed IP. Empty until first successful detection.

func (*Daemon) Run

func (d *Daemon) Run(ctx context.Context) error

Run blocks until ctx is cancelled, ticking every PollInterval. Backoff applies after consecutive failures.

func (*Daemon) Tick

func (d *Daemon) Tick(ctx context.Context) error

Tick executes one detect/diff/update cycle. Tests call this directly to bypass the timer; Run() invokes it in a loop.

func (*Daemon) TotalUpdates

func (d *Daemon) TotalUpdates() int

TotalUpdates reports the cumulative count of successful Update calls.

type HTTPDetector

type HTTPDetector struct {
	URL   string
	Label string
	HTTP  *http.Client
}

HTTPDetector queries a simple "what's my IP" HTTP endpoint.

func (HTTPDetector) Detect

func (h HTTPDetector) Detect(ctx context.Context) (net.IP, error)

Detect implements IPDetector.

func (HTTPDetector) Name

func (h HTTPDetector) Name() string

Name implements IPDetector.

type IPDetector

type IPDetector interface {
	Detect(ctx context.Context) (net.IP, error)
	Name() string
}

IPDetector returns the public IP this host appears to be reaching the internet from. Implementations should be lightweight; a single HTTPS GET is the canonical shape.

func DefaultDetectors

func DefaultDetectors() []IPDetector

DefaultDetectors returns the three-source quorum used when no detectors are configured.

type Updater

type Updater func(ctx context.Context, ip net.IP) error

Updater applies the new IP to a DNS record. Implementations talk to a DNS provider (DO/Namecheap/Hover) via the wfctl IaC ResourceDriver.

Called only when the detected IP differs from the previously-known value; idempotent re-runs are still safe.

Jump to

Keyboard shortcuts

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