node: store Scope in tracking config
The tracking configuration has no way of consulting for a configured scope. This change allows the storing of this scope inside the tracking `Config` -- currently unused. The default Scope is chosen as Trusted, so that nodes do not implicitly track any other node. If this behaviour is desired -- for example, for seed nodes -- then All should be chosen. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
5902236d0a
commit
b82584617b
|
|
@ -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()
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue