Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: move PrivateNetwork to `node::sync`
Fintan Halpenny committed 11 months ago
commit fa9c6cd142b4763df5cd5e422074a44c5fc84f3e
parent cc96b9ed7d7f561ef0c6ed22ebfb99da6e2e2848
3 files changed +48 -30
modified radicle-cli/src/commands/sync.rs
@@ -483,7 +483,7 @@ pub fn fetch(
    let local = profile.id();
    let is_private = profile.storage.repository(rid).ok().and_then(|repo| {
        let doc = repo.identity_doc().ok()?.doc;
-
        sync::fetch::PrivateNetwork::private_repo(&doc)
+
        sync::PrivateNetwork::private_repo(&doc)
    });
    let config = match is_private {
        Some(private) => sync::FetcherConfig::private(private, settings.replicas, *local),
modified radicle/src/node/sync.rs
@@ -1,7 +1,52 @@
pub mod fetch;
-

pub use fetch::{Fetcher, FetcherConfig, FetcherError, FetcherResult};

+
use std::collections::BTreeSet;
+

+
use crate::identity::Visibility;
+
use crate::prelude::Doc;
+

+
use super::NodeId;
+

+
/// A set of nodes that form a private network for fetching from.
+
///
+
/// This could be the set of allowed nodes for a private repository, using
+
/// [`PrivateNetwork::private_repo`]
+
pub struct PrivateNetwork {
+
    allowed: BTreeSet<NodeId>,
+
}
+

+
impl PrivateNetwork {
+
    pub fn private_repo(doc: &Doc) -> Option<Self> {
+
        match doc.visibility() {
+
            Visibility::Public => None,
+
            Visibility::Private { allow } => {
+
                let allowed = doc
+
                    .delegates()
+
                    .iter()
+
                    .chain(allow.iter())
+
                    .map(|did| *did.as_key())
+
                    .collect();
+
                Some(Self { allowed })
+
            }
+
        }
+
    }
+

+
    /// Restrict the set of allowed nodes based on the `predicate`, where `true`
+
    /// keeps the `NodeId` in the allowed set.
+
    ///
+
    /// For example, this can be useful to restrict the set to only connected
+
    /// nodes.
+
    pub fn restrict<P>(self, predicate: P) -> Self
+
    where
+
        P: FnMut(&NodeId) -> bool,
+
    {
+
        Self {
+
            allowed: self.allowed.into_iter().filter(predicate).collect(),
+
        }
+
    }
+
}
+

/// The replication factor of a syncing operation.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ReplicationFactor {
modified radicle/src/node/sync/fetch.rs
@@ -5,11 +5,9 @@
use std::collections::{BTreeSet, VecDeque};
use std::ops::ControlFlow;

-
use crate::identity::Visibility;
use crate::node::{Address, FetchResult, FetchResults, NodeId};
-
use crate::prelude::Doc;

-
use super::ReplicationFactor;
+
use super::{PrivateNetwork, ReplicationFactor};

/// A [`Fetcher`] describes a machine for driving a fetching process.
///
@@ -236,31 +234,6 @@ impl Fetcher {
    }
}

-
/// A set of nodes that form a private network for fetching from.
-
///
-
/// This could be the set of allowed nodes for a private repository, using
-
/// [`PrivateNetwork::private_repo`]
-
pub struct PrivateNetwork {
-
    allowed: BTreeSet<NodeId>,
-
}
-

-
impl PrivateNetwork {
-
    pub fn private_repo(doc: &Doc) -> Option<Self> {
-
        match doc.visibility() {
-
            Visibility::Public => None,
-
            Visibility::Private { allow } => {
-
                let allowed = doc
-
                    .delegates()
-
                    .iter()
-
                    .chain(allow.iter())
-
                    .map(|did| *did.as_key())
-
                    .collect();
-
                Some(Self { allowed })
-
            }
-
        }
-
    }
-
}
-

/// The progress a [`Fetcher`] is making.
#[derive(Clone, Copy, Debug)]
pub struct Progress {