Repository navigation
feat(node): decdn node evict and decdn node announce (#279, #280) - #371
Conversation
Adds two operator-facing CLI subcommands for the loopback admin RPC surface (ADR 025), plus the supporting plumbing. `decdn node evict <hex-hash> [--re-pin]` (closes #279) - New `admin_v1_evict` RPC. Logical eviction in `CacheEngine`: a hash in `Inner.evicted` is reported absent by `has` and surfaces as `NotFound` from `get`, so the node stops serving immediately for DMCA / corruption use cases. The bytes remain on disk because iroh-blobs 0.99 keeps `Blobs::delete` `pub(crate)` for the GC task — reclaim is a follow-up tied to issue #233. - `--re-pin` clears the flag and re-pulls from the configured origin in one round trip; on origin failure the engine is re-evicted so a half-fetched copy isn't served. - Hex parsing goes through `alloy::primitives::hex` rather than `Hash::from_str` because the latter falls through to a base32 path that **panics** on short inputs (data-encoding buffer mismatch). `decdn node announce` (closes #280) - New `admin_v1_announce` RPC and `AnnounceTrigger` (Notify-backed) on the gossip publisher. The publisher task now selects between its interval ticker and the trigger so an operator-driven manual announce fires within one select boundary. - `GossipService::spawn` returns `GossipHandles { tasks, announce_trigger }`; `announce_trigger` is `None` in subscribe-only mode (no region) and the RPC method maps that to a `PUBLISHER_DISABLED` error so the operator gets a specific message rather than a generic failure. Admin server bind happens early (preserves the startup-fail-fast property on port collisions), but `serve` is now spawned after gossip so the new state has the announce trigger available. Test coverage: - 3 cache-engine tests (evict blocks, unevict re-arms, evict-unknown). - 4 admin RPC tests (evict round-trip, bad-hex rejection, announce fires the underlying notify, announce-without-publisher returns the right error code). 283/283 workspace tests pass; clippy & fmt clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds new operator-facing node CLI subcommands (decdn node evict, decdn node announce) by extending the node’s loopback admin JSON-RPC surface and wiring a manual announce trigger into the gossip publisher.
Changes:
- Introduces admin RPC methods for cache eviction and one-shot gossip announce, plus matching CLI commands and argument parsing.
- Implements logical blob eviction in
CacheEngine(guardedHashSet) so evicted blobs immediately stop being served without requiring physical deletion. - Adds a
Notify-backedAnnounceTriggerreturned fromGossipService::spawn, allowing immediate publishes outside the periodic interval.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/tests/admin_peers.rs | Updates admin tests to construct AdminState with a cache engine dependency. |
| crates/node/src/runtime/mod.rs | Binds admin listener early, spawns admin server after gossip to include optional announce trigger in state. |
| crates/node/src/commands/node.rs | Adds node evict and node announce command implementations calling new admin RPC methods. |
| crates/node/src/cli/node.rs | Adds clap argument structs and help text for Evict and Announce subcommands. |
| crates/node/src/cli/mod.rs | Re-exports new CLI arg types. |
| crates/node/src/admin.rs | Extends admin RPC trait + server implementation with evict and announce, adds request/response DTOs and error codes. |
| crates/gossip/src/service.rs | Adds AnnounceTrigger + GossipHandles, and wires Notify into publisher task via tokio::select!. |
| crates/gossip/src/lib.rs | Re-exports new gossip types (AnnounceTrigger, GossipHandles). |
| crates/cache/src/engine.rs | Adds logical eviction tracking and updates has/get semantics; adds unit tests for eviction/unevict behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request introduces logical cache eviction and manual gossip announcement triggers to support administrative actions like content takedowns and configuration updates. It adds new RPC methods and CLI commands, along with the necessary backend logic in the cache and gossip modules. Feedback points out that the eviction set is currently non-durable across node restarts and suggests improving the robustness of hex hash parsing by handling the '0x' prefix in a case-insensitive manner.
- cargo doc: disambiguate `Hash` intra-doc link to `[`struct@Hash`]` (`Hash` is also a derive macro at crate root — broken-intra-doc-links fired on the workspace doc job). - Drop `--re-pin` flag from `decdn node evict` / `admin_v1_evict`. With logical eviction, `unevict + cache.get()` reads the local store (bytes never left iroh-blobs), so `repinned=true` could be reported even with the origin down. iroh-blobs 0.99 doesn't expose a way to force an origin-only fetch, so the flag can't be implemented honestly in v1. Re-add when issue #233 lands a public delete API. - `0x` / `0X` hex prefix tolerated in `parse_hash_arg` (case-insensitive strip). - Persist evicted set to `<cache_dir>/evicted.log`. DMCA takedowns and corruption-recovery evicts now survive `decdn run` restarts. The log is append-only with one lowercase-hex hash per line (POSIX append atomicity covers the 65-byte writes), `fsync`'d before evict() returns. Malformed lines are warn-logged + skipped rather than failing the whole open. `evict()` now returns CacheResult<()> so a failed fsync surfaces to the operator instead of silently degrading to in-memory-only. - Removed `unevict()` from the public CacheEngine API since the `--re-pin` path was its only caller and unevict can't be persisted cleanly without a log-rewrite scheme outside this PR's scope. - New tests: evict persists across open/close, evicted.log skips malformed lines, admin_evict accepts uppercase `0X` prefix. 231/231 tests pass; cargo doc, clippy, fmt clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…fast) Critical correctness: - `CacheEngine::evict` / `is_evicted` now use `unwrap_or_else(PoisonError::into_inner)` instead of `if let Ok(...) = lock()` / `lock().ok()`. A poisoned mutex on the evicted set previously made `is_evicted` return false silently — the worst possible failure mode for a DMCA takedown, since the node would keep serving an evicted blob until restart. Now poison-recovers the guard so the in-memory commit always lands. - `gossip::publisher_task` per-topic broadcast failure logged at `warn!` rather than `debug!`. A manual `decdn node announce` whose broadcast failed on every topic was previously invisible at default log levels while the CLI happily printed `triggered=true`. - CLI now prints `announce_queued=` instead of `announce_triggered=` to match the doc-stated "queued, not delivered" semantic. The `AnnounceResponse.triggered` doc-comment also rewritten. - Stripped all references to a `--re-pin` flag and a `Self::unevict` method that don't exist in the code (left over from fb33b82's partial revert) — `cli/node.rs`, `commands/node.rs`, `admin.rs` trait + error-code doc, `engine.rs::get` doc (was a broken intra-doc link). Defensive bounds: - New `MAX_EVICTED_ENTRIES = 1_000_000` cap on the evicted set, with `CacheError::EvictionLimitExceeded`. Bounds in-memory growth and on-disk `evicted.log` size against an automation gone wrong. - `evict()` is now idempotent at the persistence layer too: a `contains()` short-circuit at the top means re-evicting the same hash doesn't append a duplicate log line. - `parse_hex_hash` (evicted.log loader) now accepts uppercase, matching `parse_hash_arg` (admin RPC). Hand-edited entries from operators pasting hashes from access logs / takedown notices used to silently drop on next open. Persisted format is canonically lowercase via `Hash::Display::to_hex()`, so this is read-path leniency only. - Variable names in `parse_hex_hash` corrected: first nibble is the high nibble of the byte (was inverted). Gossip startup: - `GossipService::spawn` returns `Result<GossipHandles, GossipSpawnError>`. Intentional subscribe-only mode (no global, no region) still returns `Ok` with empty handles. "Every topic subscribe failed" now returns `AllSubscribesFailed` and the runtime fails fast via `?` instead of soldiering on into a state where `admin_v1_announce` would later return `PUBLISHER_DISABLED` for the wrong reason. Comment fixes: - Publisher select-loop and CLI `Announce` doc-comments no longer cite `rate_per_mb` (lives in `ProbeResponse`, not `NodeAnnounceBody`) or imply `region` is hot-reloadable (it's captured by-value at task spawn and requires a restart to change). - Test-helper `from_notify` reference in admin.rs corrected to `for_test`. Adjacent paragraph rewritten. - `test_cache` doc says "tempdir-backed" instead of "in-memory". New tests (8): - cache: idempotent re-evict produces 1 log line; uppercase hex in evicted.log loads correctly; persistence-failure (directory at evicted.log path) returns Err and leaves the in-memory set untouched. - gossip: `AnnounceTrigger::announce_now` wakes a parked `notified()`; back-to-back triggers coalesce into one permit (locks Notify's stored-permit semantics that publisher_task depends on). - node integration: connection-refused + zero-timeout coverage for `cli evict` and `cli announce`, mirroring the existing `cli health` / `cli peers` patterns. 294/294 tests pass; cargo fmt, clippy --workspace --all-targets clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Adds two operator-facing CLI subcommands and the supporting admin RPC plumbing.
decdn node evictsubcommand that removes a specific blob hash from the local cache and optionally re-pins it from the configured origin #279. Forcibly stops the node from serving a single blob (DMCA takedown / corruption recovery). `--re-pin` re-pulls from the configured origin in the same round trip.decdn node announceone-shot subcommand that publishes a single NodeAnnounce to the gossip network and exits, useful for scripted re-registration after config changes #280. Triggers an immediate `NodeAnnounce` broadcast outside the periodic publisher interval — useful right after editing `rate_per_mb` / `region` in config.Implementation notes
Test plan
Manual end-to-end suggestions for reviewer
```
decdn run --config &
decdn node evict # status=evicted (or not present), no re-pin
decdn node evict --re-pin # status=evicted repinned=ok
decdn node announce # announce_triggered=true; observable via `decdn node peers` on a peer
```
Closes #279
Closes #280
🤖 Generated with Claude Code