Milestone 4: LAN discovery, trust gate, auto-sync, rate limits, events
mDNS-style LAN discovery (iroh MdnsDiscovery, discovery flag, default on) feeds a presence tracker; trusted peers that appear trigger fetches of every incomplete pin, and Pin itself now fetches from present trusted peers. Serving is our own ProtocolHandler: trusted NodeIds get the full store, everyone else a filtered view limited to open_lan pins and ticket-exported hashes (plus hashseq children) that answers "not found" for the rest. Ticket export records standing serve-consent for that hash; trust changes take effect on new connections. ShapedStore implements the full iroh-blobs Store trait to charge provider reads to an upload token bucket and downloader writes to a download bucket; upload cap 0 closes incoming connections at accept. Subscribe now streams transfer_progress both ways, peer_joined, and pin_complete. Tests: forged-ticket trust gating (denied untrusted, served after trust), 256 KiB/s upload cap enforced by wall clock, event stream during a transfer, and real-mdns auto-sync between two daemons (skips where multicast is unavailable). Dependencies: n0-future, async-channel, futures-lite, bytes — all already in the tree via iroh; needed directly to name types in iroh-blobs trait signatures and channels. iroh feature discovery-local-network for MdnsDiscovery. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -47,9 +47,15 @@ pub fn spawn_daemon() -> DaemonProc {
|
||||
|
||||
/// Spawn the daemon against an existing directory (for restart tests).
|
||||
pub fn spawn_daemon_at(dir: &Path) -> DaemonProc {
|
||||
spawn_daemon_with_env(dir, &[])
|
||||
}
|
||||
|
||||
/// Spawn the daemon with extra environment variables (config overrides).
|
||||
pub fn spawn_daemon_with_env(dir: &Path, envs: &[(&str, &str)]) -> DaemonProc {
|
||||
let socket = dir.join("varde.sock");
|
||||
let store = dir.join("store");
|
||||
let child = Command::new(env!("CARGO_BIN_EXE_varde-daemon"))
|
||||
let mut command = Command::new(env!("CARGO_BIN_EXE_varde-daemon"));
|
||||
command
|
||||
.arg("--user")
|
||||
.arg("--socket")
|
||||
.arg(&socket)
|
||||
@@ -57,9 +63,11 @@ pub fn spawn_daemon_at(dir: &Path) -> DaemonProc {
|
||||
.arg(&store)
|
||||
// Isolate from any config file on the developer's machine.
|
||||
.env("VARDE_CONFIG", dir.join("no-config.toml"))
|
||||
.env("VARDE_DISCOVERY", "false")
|
||||
.spawn()
|
||||
.expect("spawning varde-daemon");
|
||||
.env("VARDE_DISCOVERY", "false");
|
||||
for (key, value) in envs {
|
||||
command.env(key, value);
|
||||
}
|
||||
let child = command.spawn().expect("spawning varde-daemon");
|
||||
// An explicitly named config must exist for the daemon to start.
|
||||
std::fs::write(dir.join("no-config.toml"), "").expect("writing empty config");
|
||||
|
||||
@@ -129,6 +137,13 @@ impl Client {
|
||||
serde_json::from_str(&reply).expect("parsing reply envelope")
|
||||
}
|
||||
|
||||
/// Bound how long reads may block (applies to the shared socket).
|
||||
pub fn set_read_timeout(&mut self, timeout: Duration) {
|
||||
self.writer
|
||||
.set_read_timeout(Some(timeout))
|
||||
.expect("setting read timeout");
|
||||
}
|
||||
|
||||
/// Read one line of the event stream (after Subscribe).
|
||||
pub fn read_event_line(&mut self) -> Option<String> {
|
||||
let mut line = String::new();
|
||||
|
||||
Reference in New Issue
Block a user