1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//! # grindvakt-core
//!
//! The engine of [Grindvakt](https://grindvakt.weirdbrains.com/), 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::Record`]s 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 [`SecretString`]s, 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
//!
//! ```no_run
//! # #[cfg(all(feature = "digitalocean", feature = "public-ip"))]
//! # async fn run(token: grindvakt_core::SecretString, peer: &str) -> grindvakt_core::Result<()> {
//! 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
//! # Ok(()) }
//! ```
//!
//! A complete offline run against an in-memory provider is in the [`plan`](mod@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.
pub use ;
pub use ;
/// Re-exported so callers use the same secret type as the providers and vault.
pub use ;
/// Re-exported so callers can match the crypto crate in use.
pub use weirdnet_keys;
/// Compiles and runs the README's examples as doctests.
;