Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
node: store Scope in tracking config
Fintan Halpenny committed 3 years ago
commit b82584617b4b6595d958e678502a99f405e70a11
parent 5902236d0a4b2ee92058ffc7f4294d5fa526eb5d
6 files changed +27 -13
modified radicle-cli/tests/commands.rs
@@ -11,7 +11,7 @@ use radicle::storage::{ReadRepository, ReadStorage};
use radicle::test::fixtures;

use radicle_cli_test::TestFormula;
-
use radicle_node::service::tracking::Policy;
+
use radicle_node::service::tracking::{Policy, Scope};
use radicle_node::test::{
    environment::{Config, Environment},
    logger,
@@ -444,6 +444,7 @@ fn test_replication_via_seed() {
    let mut bob = bob.spawn(Config::default());
    let seed = seed.spawn(Config {
        policy: Policy::Track,
+
        scope: Scope::All,
        ..Config::default()
    });

modified radicle-node/src/runtime.rs
@@ -116,7 +116,7 @@ impl<G: Signer + Ecdh + 'static> Runtime<G> {

        log::info!(target: "node", "Opening tracking policy table {}..", tracking_db.display());
        let tracking = tracking::Store::open(tracking_db)?;
-
        let tracking = tracking::Config::new(config.policy, tracking);
+
        let tracking = tracking::Config::new(config.policy, config.scope, tracking);

        log::info!(target: "node", "Default tracking policy set to '{}'", &config.policy);
        log::info!(target: "node", "Initializing service ({:?})..", network);
modified radicle-node/src/service/config.rs
@@ -2,7 +2,7 @@ use localtime::LocalDuration;

use radicle::node::Address;

-
use crate::service::tracking::Policy;
+
use crate::service::tracking::{Policy, Scope};
use crate::service::NodeId;

/// Peer-to-peer network.
@@ -47,6 +47,8 @@ pub struct Config {
    pub limits: Limits,
    /// Default tracking policy.
    pub policy: Policy,
+
    /// Default tracking scope.
+
    pub scope: Scope,
}

impl Default for Config {
@@ -58,6 +60,7 @@ impl Default for Config {
            relay: true,
            limits: Limits::default(),
            policy: Policy::default(),
+
            scope: Scope::default(),
        }
    }
}
modified radicle-node/src/service/tracking.rs
@@ -14,25 +14,32 @@ pub use store::Error;
#[derive(Debug)]
pub struct Config {
    /// Default policy, if a policy for a specific node or repository was not found.
-
    default: Policy,
+
    policy: Policy,
+
    #[allow(dead_code)]
+
    /// Default scope, if a scope for a specific repository was not found.
+
    scope: Scope,
    /// Underlying configuration store.
    store: store::Config,
}

impl Config {
    /// Create a new tracking configuration.
-
    pub fn new(default: Policy, store: store::Config) -> Self {
-
        Self { default, store }
+
    pub fn new(policy: Policy, scope: Scope, store: store::Config) -> Self {
+
        Self {
+
            policy,
+
            scope,
+
            store,
+
        }
    }

    /// Check if a repository is tracked.
    pub fn is_repo_tracked(&self, id: &Id) -> Result<bool, Error> {
-
        self.repo_policy(id).map(|policy| policy == Policy::Track)
+
        self.repo_policy(id).map(|entry| entry == Policy::Track)
    }

    /// Check if a node is tracked.
    pub fn is_node_tracked(&self, id: &NodeId) -> Result<bool, Error> {
-
        self.node_policy(id).map(|policy| policy == Policy::Track)
+
        self.node_policy(id).map(|entry| entry == Policy::Track)
    }

    /// Get a node's tracking information.
@@ -41,7 +48,7 @@ impl Config {
        if let Some((_, policy)) = self.store.node_entry(id)? {
            return Ok(policy);
        }
-
        Ok(self.default)
+
        Ok(self.policy)
    }

    /// Get a repository's tracking information.
@@ -50,7 +57,7 @@ impl Config {
        if let Some((_, policy)) = self.store.repo_entry(id)? {
            return Ok(policy);
        }
-
        Ok(self.default)
+
        Ok(self.policy)
    }
}

modified radicle-node/src/test/peer.rs
@@ -16,7 +16,7 @@ use crate::prelude::*;
use crate::service;
use crate::service::message::*;
use crate::service::reactor::Io;
-
use crate::service::tracking::Policy;
+
use crate::service::tracking::{Policy, Scope};
use crate::service::*;
use crate::storage::git::transport::remote;
use crate::storage::{RemoteId, WriteStorage};
@@ -92,6 +92,7 @@ pub struct Config<G: Signer + 'static> {
    pub addrs: address::Book,
    pub local_time: LocalTime,
    pub policy: Policy,
+
    pub scope: Scope,
    pub signer: G,
    pub rng: fastrand::Rng,
}
@@ -106,6 +107,7 @@ impl Default for Config<MockSigner> {
            addrs: address::Book::memory().unwrap(),
            local_time: LocalTime::now(),
            policy: Policy::Block,
+
            scope: Scope::default(),
            signer,
            rng,
        }
@@ -125,7 +127,7 @@ where
    ) -> Self {
        let routing = routing::Table::memory().unwrap();
        let tracking = tracking::Store::memory().unwrap();
-
        let tracking = tracking::Config::new(config.policy, tracking);
+
        let tracking = tracking::Config::new(config.policy, config.scope, tracking);
        let id = *config.signer.public_key();
        let service = Service::new(
            config.config,
modified radicle/src/node/tracking.rs
@@ -90,9 +90,10 @@ impl TryFrom<&sqlite::Value> for Policy {
}

/// Tracking scope of a repository tracking policy.
-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
+
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum Scope {
    /// Track remotes of nodes that are already tracked.
+
    #[default]
    Trusted,
    /// Track all remotes.
    All,