diff --git a/radicle-cli/src/node.rs b/radicle-cli/src/node.rs index 21597579..d7365a83 100644 --- a/radicle-cli/src/node.rs +++ b/radicle-cli/src/node.rs @@ -186,7 +186,7 @@ fn announce_( ) -> Result { let rid = repo.id(); let doc = repo.identity_doc()?; - let settings = settings.with_profile(profile); + let mut settings = settings.with_profile(profile); let unsynced: Vec<_> = if doc.visibility.is_public() { // All seeds. let all = node.seeds(rid)?; @@ -217,8 +217,8 @@ fn announce_( ); return Ok(AnnounceResult::default()); } - // Return nodes we can announce to. - all.connected() + // Return nodes we can announce to. They don't have to be connected directly. + all.iter() .filter(|s| !s.is_synced() && &s.nid != profile.id()) .map(|s| s.nid) .collect() @@ -234,6 +234,10 @@ fn announce_( term::info!(&mut reporting.completion; "No seeds to announce to for {rid}. (see `rad sync status`)"); return Ok(AnnounceResult::default()); } + // Cap the replicas to the maximum achievable. + // Nb. It's impossible to know if a replica follows our node. This means that if we announce + // only our refs, and the replica doesn't follow us, it won't fetch from us. + settings.replicas = settings.replicas.min(unsynced.len()); let mut spinner = term::spinner_to( format!("Found {} seed(s)..", unsynced.len()), diff --git a/radicle-cli/tests/commands.rs b/radicle-cli/tests/commands.rs index 246d0286..f8549945 100644 --- a/radicle-cli/tests/commands.rs +++ b/radicle-cli/tests/commands.rs @@ -332,7 +332,7 @@ fn rad_id() { let events = alice.handle.events(); bob.fork(acme, bob.home.path()).unwrap(); - bob.announce(acme, bob.home.path()).unwrap(); + bob.announce(acme, 2, bob.home.path()).unwrap(); alice.has_inventory_of(&acme, &bob.id); // Alice must have Bob to try add them as a delegate @@ -540,7 +540,7 @@ fn rad_id_conflict() { alice.connect(&bob).converge([&bob]); bob.fork(acme, working.join("bob")).unwrap(); - bob.announce(acme, bob.home.path()).unwrap(); + bob.announce(acme, 2, bob.home.path()).unwrap(); alice.has_inventory_of(&acme, &bob.id); formula(&environment.tmp(), "examples/rad-id-conflict.md") @@ -982,7 +982,7 @@ fn rad_clean() { eve.handle.fetch(acme, alice.id, DEFAULT_TIMEOUT).unwrap(); bob.fork(acme, bob.home.path()).unwrap(); - bob.announce(acme, bob.home.path()).unwrap(); + bob.announce(acme, 1, bob.home.path()).unwrap(); bob.has_inventory_of(&acme, &alice.id); alice.has_inventory_of(&acme, &bob.id); eve.has_inventory_of(&acme, &alice.id); @@ -1116,7 +1116,7 @@ fn rad_clone_all() { // Fork and sync repo. bob.fork(acme, bob.home.path()).unwrap(); - bob.announce(acme, bob.home.path()).unwrap(); + bob.announce(acme, 2, bob.home.path()).unwrap(); bob.has_inventory_of(&acme, &alice.id); alice.has_inventory_of(&acme, &bob.id); @@ -1762,13 +1762,13 @@ fn rad_remote() { bob.connect(&alice); bob.routes_to(&[(rid, alice.id)]); bob.fork(rid, bob.home.path()).unwrap(); - bob.announce(rid, bob.home.path()).unwrap(); + bob.announce(rid, 2, bob.home.path()).unwrap(); alice.has_inventory_of(&rid, &bob.id); eve.connect(&bob); eve.routes_to(&[(rid, alice.id)]); eve.fork(rid, eve.home.path()).unwrap(); - eve.announce(rid, eve.home.path()).unwrap(); + eve.announce(rid, 2, eve.home.path()).unwrap(); alice.has_inventory_of(&rid, &eve.id); test( diff --git a/radicle-node/src/test/environment.rs b/radicle-node/src/test/environment.rs index d89809f9..9e7e17ed 100644 --- a/radicle-node/src/test/environment.rs +++ b/radicle-node/src/test/environment.rs @@ -308,14 +308,23 @@ impl NodeHandle { pub fn fork>(&self, rid: RepoId, cwd: P) -> io::Result<()> { self.clone(rid, &cwd)?; self.rad("fork", &[rid.to_string().as_str()], &cwd)?; - self.announce(rid, &cwd)?; + self.announce(rid, 1, &cwd)?; Ok(()) } /// Announce a repo. - pub fn announce>(&self, rid: RepoId, cwd: P) -> io::Result<()> { - self.rad("sync", &[rid.to_string().as_str(), "--announce"], cwd) + pub fn announce>(&self, rid: RepoId, replicas: usize, cwd: P) -> io::Result<()> { + self.rad( + "sync", + &[ + rid.to_string().as_str(), + "--announce", + "--replicas", + replicas.to_string().as_str(), + ], + cwd, + ) } /// Init a repo.