From 9577375ff7710d3c72366132b1a51f2be47a1a36 Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Tue, 15 Sep 2026 21:43:47 -0500 Subject: [PATCH] docs(homelab): introduce pluggable DDNS connector architecture for Cloudflare and Dynu Update dynu-monitor plan and discussion to define the decoupled DdnsConnector trait, supporting both Dynu and Cloudflare providers. --- ...-monitor-polling-and-language-tradeoffs.md | 33 +++++++++++++++++-- .../homelab/plans/dynu-monitor-rust-daemon.md | 21 ++++++------ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/projects/homelab/discussions/dynu-monitor-polling-and-language-tradeoffs.md b/projects/homelab/discussions/dynu-monitor-polling-and-language-tradeoffs.md index 8b696c9..f0ad067 100644 --- a/projects/homelab/discussions/dynu-monitor-polling-and-language-tradeoffs.md +++ b/projects/homelab/discussions/dynu-monitor-polling-and-language-tradeoffs.md @@ -56,6 +56,35 @@ Rather than merging the intermediate Python rewrite into `Core`, the preferred a ## 4. Architectural Invariants for the Rust Implementation -1. **Gatekeeper Pattern**: `dynu-monitor` only triggers `ddclient.service` when a public IP change is verified. -2. **Update Confirmation**: `last_ip` in `state.json` is updated **only after** `ddclient` exits successfully. A failed update preserves the previous IP so retries continue. +1. **Gatekeeper Pattern**: `ddns-monitor` only triggers the configured DDNS provider connector when a public IP change is verified. +2. **Update Confirmation**: `last_ip` in `state.json` is updated **only after** the provider update succeeds. A failed update preserves the previous IP so retries continue. 3. **Graceful Resolver Failover**: If the current provider in the round-robin sequence fails or times out (5s), the daemon falls back to the next provider immediately without failing the tick. + +--- + +## 5. Provider Decoupling & Rebrand to `ddns-monitor` + +### The Catalyst: Dynu Quota Constraints vs. Cloudflare +During the Homelab email server and DKIM setup, a fundamental upstream constraint was encountered: **Dynu limits free accounts to 4 custom CNAME/alias records**. While sufficient for minimal setups, scaling the homelab with service subdomains, transactional email relays (Brevo/SES), and verification tokens creates friction unless paying for Dynu Membership ($9.99/yr). + +In contrast, **Cloudflare DNS** provides: +* 100% free, unlimited DNS records, CNAMEs, and TXT entries. +* Global anycast sub-second DNS propagation. +* Robust public REST API (native Traefik DNS-01 and DDNS automation). + +### The Connector Pattern Architecture +Rather than hardcoding the daemon to Dynu, the project is renamed from `dynu-monitor` to **`ddns-monitor`** and implements a pluggable **Connector / Adapter pattern**: + +```mermaid +flowchart TD + Core["ddns-monitor (Domain Core)
• 30s Polling Loop
• 5-Provider Echo Rotation
• State Tracking (last_ip)"] -->|Trait Contract| Trait["Box"] + Trait --> Dynu["DynuConnector
(Dynu REST API / ddclient)"] + Trait --> Cloudflare["CloudflareConnector
(Cloudflare API v4)"] + Trait --> Mock["MockConnector
(In-memory Test Double)"] +``` + +### Benefits of the Decoupled Design +1. **Zero-Downtime Provider Migration**: Switching from Dynu to Cloudflare simply requires swapping the connector in configuration without altering IP detection, history tracking, or systemd daemon structure. +2. **Isolated Credentials**: Each connector manages its own authentication (e.g. `DynuCredentials` vs `CloudflareApiToken`), passed cleanly via SOPS templates. +3. **Multi-Provider Sync**: The core can support a `CompositeConnector` that simultaneously updates multiple DNS zones across providers if dual-routing is required. + diff --git a/projects/homelab/plans/dynu-monitor-rust-daemon.md b/projects/homelab/plans/dynu-monitor-rust-daemon.md index a7726c8..4e8a63a 100644 --- a/projects/homelab/plans/dynu-monitor-rust-daemon.md +++ b/projects/homelab/plans/dynu-monitor-rust-daemon.md @@ -10,13 +10,13 @@ tags: - migration --- -# 🦀 Rust Daemon Migration Plan: Standalone `dynu-monitor` +# 🦀 Rust Daemon Migration Plan: Standalone `ddns-monitor` (formerly `dynu-monitor`) ## 🎯 Goal Description -Migrate the dynamic DNS gatekeeper daemon from the current Python script to a native, statically compiled **Rust daemon** located at `/home/kiskaadee/Projects/active/dynu-monitor`. +Migrate the dynamic DNS gatekeeper daemon from the current Python script to a native, statically compiled **Rust daemon** located at `/home/kiskaadee/Projects/active/ddns-monitor`. -This implementation introduces high-frequency 30-second polling and stateful round-robin resolver rotation across 5 public echo providers while eliminating Python interpreter overhead on the headless server. +This implementation introduces high-frequency 30-second polling and stateful round-robin resolver rotation across 5 public echo providers while eliminating Python interpreter overhead on the headless server. Crucially, it decouples the DDNS update mechanism behind a pluggable `DdnsConnector` trait to support both **Dynu** and **Cloudflare** (overcoming Dynu's free-tier 4-alias quota limit). --- @@ -36,12 +36,12 @@ This implementation introduces high-frequency 30-second polling and stateful rou │ ┌────────────────┼────────────────┐ ▼ ▼ ▼ - Box Box Box + Box Box Box │ │ │ ▼ ▼ ▼ - HttpEchoPool StateFile Systemctl - (5 endpoints) (state.json) (ddclient.service) - │ + HttpEchoPool StateFile [Pluggable Connectors] + (5 endpoints) (state.json) ├── DynuConnector (REST / ddclient) + │ └── CloudflareConnector (API v4) ▼ HistoryFile (ip_history.jsonl) @@ -63,17 +63,18 @@ This implementation introduces high-frequency 30-second polling and stateful rou ### Milestone 1: Domain Entities & In-Memory Logic *(In Progress)* - [x] Define domain types: `Ipv4Addr`, `ProviderId`, `MonitorEvent`. - [ ] Implement `IpMonitorService` pure business logic. -- [ ] Mock traits `MockIpResolver`, `MockStateRepository`, `MockDdnsUpdater`. +- [ ] Mock traits `MockIpResolver`, `MockStateRepository`, `MockDdnsConnector`. - [ ] Unit tests verifying: - No change detected $\rightarrow$ zero updater calls. - Change detected $\rightarrow$ updater triggered $\rightarrow$ state updated. - Updater fails $\rightarrow$ state remains unchanged. -### Milestone 2: Infrastructure Adapters (HTTP, File, Systemd) +### Milestone 2: Infrastructure Adapters & Provider Connectors - [ ] Implement `ReqwestIpResolver` with 5-endpoint pool (`ipify`, `icanhazip`, `ifconfig.me`, `checkip.dynu`, `wtfismyip`). - [ ] Implement `JsonStateRepository` with atomic write (write to `.tmp` then rename). - [ ] Implement `JsonlHistoryRepository` for append-only audit logs. -- [ ] Implement `SystemdDdnsUpdater` calling `systemctl start ddclient.service`. +- [ ] Implement `DynuConnector` calling `systemctl start ddclient.service` or Dynu REST API. +- [ ] Implement `CloudflareConnector` querying Cloudflare API v4 for zero-quota DNS record updates. ### Milestone 3: Nix Packaging & Flake Integration - [ ] Write `flake.nix` in `Projects/active/dynu-monitor` producing a static package.