Skip to main content

Crate grindvakt_core

Crate grindvakt_core 

Source
Expand description

§grindvakt-core

The engine of Grindvakt, the dynamic DNS updater, as a library you embed. It keeps A, AAAA, TXT and CNAME records on DNSimple or DigitalOcean pointed at where your machine is, including the libp2p _dnsaddr TXT record a peer-to-peer node publishes and aliases such as www (record::Record::cname):

  1. ip::discover finds your public IPv4 and IPv6 addresses separately, from several HTTPS sources that must agree, and says Error::NoGlobalAddress when there is nothing worth publishing (CGNAT, private-only, no IPv6). Or pass addresses you already know.
  2. plan() compares the record::Records you want with the zone, through a provider::DnsProvider, and returns a plan::Plan: no change, create, update, or refuse because it is ambiguous. The plan is the dry run.
  3. apply() writes it. Running it again changes nothing.

The caller owns everything around that: tokens arrive as SecretStrings, every file path is an argument, and when to sync is up to you; there is no scheduler, CLI, prompt or global state in the crate. Errors are typed (Error::Auth, Error::RateLimited, Error::Ambiguous, Error::NoGlobalAddress, Error::Network, Error::Provider) so a UI can explain them.

§Example

use grindvakt_core::{apply, ip, plan, provider, record::Record};

let dns = provider::digitalocean(&token)?; // or provider::dnsimple(&token, None)?
let addrs = ip::discover(ip::Family::Both, &ip::Sources::default()).await?;

let mut want = vec![Record::txt(
    "_dnsaddr.home",
    format!("dnsaddr=/dns4/home.example.com/tcp/4747/p2p/{peer}"),
)];
if let Some(v4) = addrs.v4 { want.push(Record::a("home", v4)); }
if let Some(v6) = addrs.v6 { want.push(Record::aaaa("home", v6)); }

let p = plan(&dns, "example.com", &want).await?;
println!("{p}");       // show the dry run
apply(&dns, &p).await?; // then write it

A complete offline run against an in-memory provider is in the plan module docs and in examples/.

§Features

featuredefaultadds
dnsimpleyesprovider::DnsimpleProvider (official dnsimple crate, rustls)
digitaloceanyesprovider::DigitalOceanProvider (reqwest, rustls)
public-ipyesip::discover (reqwest, rustls)
vaultnovault: encrypted token file (Argon2id password and 24-word recovery phrase, XChaCha20-Poly1305 via weirdnet_keys)
standalonenoThe standalone Grindvakt app’s config::AppConfig, paths, single-record sync, and standalone::find_conflicts

With default-features = false the crate makes no network calls at all; plug in your own provider::DnsProvider and addresses. Every feature builds for Android and iOS (rustls only, no OpenSSL). On Android, initialize rustls-platform-verifier from your app before the first HTTPS call, as that crate documents.

§What is not here

Everything that ties Grindvakt to a machine stays in the Grindvakt app: the command line and prompts, schedules and timers, the systemd/launchd/Windows services, the unattended credential stores (systemd-creds, Keychain, DPAPI), installers and logging.

§Platforms and MSRV

Linux, macOS, Windows, Android and iOS; Rust 1.99 or newer (edition 2024). The network features need a Tokio runtime.

§Versioning

grindvakt-core is released in lockstep with the Grindvakt app: crate version X.Y.Z is the library inside Grindvakt vX.Y.Z, and is published to crates.io before that app release is tagged. Semver applies to the public API. The vault and config formats are stable; a format change would come with a major version and a migration path.

Re-exports§

pub use plan::apply;
pub use plan::plan;
pub use weirdnet_keys;vault

Modules§

cname
Where a CNAME record’s content comes from: a fixed target name, or a Weirdnet resource link whose authority is the target (feature weirdnet).
config
Provider names, record-name helpers, and (feature standalone) the Grindvakt app’s own config file.
fs
Private directories and atomic private file writes.
ip
Public address discovery, IPv4 and IPv6 separately, by strict-majority agreement between independent HTTPS echo sources.
lock
A single-instance lock: an exclusive advisory lock on a file.
pathsstandalone
The standalone Grindvakt app’s default locations (feature standalone).
plan
Plan, then apply: decide what to change for a set of wanted records, show it, write it.
provider
DNS providers: a small trait plus DNSimple and DigitalOcean implementations.
record
DNS records: what you want published (Record) and what a provider has (ExistingRecord).
standalonestandalone
Living next to a standalone Grindvakt (feature standalone).
syncstandalone
The standalone Grindvakt app’s sync pass (feature standalone): one A record (or, with record = "cname", one CNAME) from an AppConfig, with the app’s log lines. It is a thin wrapper over crate::plan() and crate::apply(); embedding apps usually call those directly.
vaultvault
The encrypted token vault (vault.json, format version 1).

Enums§

Error
Everything that can go wrong in grindvakt-core.

Traits§

ExposeSecret
Re-exported so callers use the same secret type as the providers and vault. Expose a reference to an inner secret

Type Aliases§

Result
Result with Error.
SecretString
Re-exported so callers use the same secret type as the providers and vault. Secret string type.