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):
ip::discoverfinds your public IPv4 and IPv6 addresses separately, from several HTTPS sources that must agree, and saysError::NoGlobalAddresswhen there is nothing worth publishing (CGNAT, private-only, no IPv6). Or pass addresses you already know.plan()compares therecord::Records you want with the zone, through aprovider::DnsProvider, and returns aplan::Plan: no change, create, update, or refuse because it is ambiguous. The plan is the dry run.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 itA complete offline run against an in-memory provider is in the plan module docs and
in examples/.
§Features
| feature | default | adds |
|---|---|---|
dnsimple | yes | provider::DnsimpleProvider (official dnsimple crate, rustls) |
digitalocean | yes | provider::DigitalOceanProvider (reqwest, rustls) |
public-ip | yes | ip::discover (reqwest, rustls) |
vault | no | vault: encrypted token file (Argon2id password and 24-word recovery phrase, XChaCha20-Poly1305 via weirdnet_keys) |
standalone | no | The 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
CNAMErecord’s content comes from: a fixed target name, or a Weirdnet resource link whose authority is the target (featureweirdnet). - 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.
- paths
standalone - 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). - standalone
standalone - Living next to a standalone Grindvakt (feature
standalone). - sync
standalone - The standalone Grindvakt app’s sync pass (feature
standalone): oneArecord (or, withrecord = "cname", oneCNAME) from anAppConfig, with the app’s log lines. It is a thin wrapper overcrate::plan()andcrate::apply(); embedding apps usually call those directly. - vault
vault - The encrypted token vault (
vault.json, format version 1).
Enums§
- Error
- Everything that can go wrong in
grindvakt-core.
Traits§
- Expose
Secret - Re-exported so callers use the same secret type as the providers and vault. Expose a reference to an inner secret
Type Aliases§
- Result
ResultwithError.- Secret
String - Re-exported so callers use the same secret type as the providers and vault. Secret string type.