Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Include all nodes we can announce to on sync
cloudhead committed 2 years ago
commit 98b0d55fde56a946ce4d932cb116958ed0e333ae
parent 3535170f2d2683dd3673f1f64536e96356d5357b
3 files changed +25 -12
modified radicle-cli/src/node.rs
@@ -186,7 +186,7 @@ fn announce_<R: ReadRepository>(
) -> Result<AnnounceResult, SyncError> {
    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_<R: ReadRepository>(
            );
            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_<R: ReadRepository>(
        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()),
modified 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(
modified radicle-node/src/test/environment.rs
@@ -308,14 +308,23 @@ impl<G: Signer + cyphernet::Ecdh> NodeHandle<G> {
    pub fn fork<P: AsRef<Path>>(&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<P: AsRef<Path>>(&self, rid: RepoId, cwd: P) -> io::Result<()> {
-
        self.rad("sync", &[rid.to_string().as_str(), "--announce"], cwd)
+
    pub fn announce<P: AsRef<Path>>(&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.