radicle: Distinguish seeding policy types
We create a separate type for the default seeding policy, that serializes differently and is only used in the node configuraiton.
This commit is contained in:
parent
bbb292c8e6
commit
f7d8f1b8da
|
|
@ -6,6 +6,7 @@ use radicle::git;
|
||||||
use radicle::node;
|
use radicle::node;
|
||||||
use radicle::node::address::Store as _;
|
use radicle::node::address::Store as _;
|
||||||
use radicle::node::config::seeds::{RADICLE_COMMUNITY_NODE, RADICLE_TEAM_NODE};
|
use radicle::node::config::seeds::{RADICLE_COMMUNITY_NODE, RADICLE_TEAM_NODE};
|
||||||
|
use radicle::node::config::DefaultSeedingPolicy;
|
||||||
use radicle::node::routing::Store as _;
|
use radicle::node::routing::Store as _;
|
||||||
use radicle::node::Handle as _;
|
use radicle::node::Handle as _;
|
||||||
use radicle::node::UserAgent;
|
use radicle::node::UserAgent;
|
||||||
|
|
@ -17,7 +18,7 @@ use radicle::storage::{ReadStorage, RefUpdate, RemoteRepository};
|
||||||
use radicle::test::fixtures;
|
use radicle::test::fixtures;
|
||||||
|
|
||||||
use radicle_cli_test::TestFormula;
|
use radicle_cli_test::TestFormula;
|
||||||
use radicle_node::service::policy::{Scope, SeedingPolicy};
|
use radicle_node::service::policy::Scope;
|
||||||
use radicle_node::service::Event;
|
use radicle_node::service::Event;
|
||||||
use radicle_node::test::environment::{Config, Environment, Node};
|
use radicle_node::test::environment::{Config, Environment, Node};
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
|
|
@ -773,7 +774,7 @@ fn rad_node() {
|
||||||
Address::from(net::SocketAddr::from(([41, 12, 98, 112], 8776))),
|
Address::from(net::SocketAddr::from(([41, 12, 98, 112], 8776))),
|
||||||
Address::from_str("seed.cloudhead.io:8776").unwrap(),
|
Address::from_str("seed.cloudhead.io:8776").unwrap(),
|
||||||
],
|
],
|
||||||
seeding_policy: SeedingPolicy::Block,
|
seeding_policy: DefaultSeedingPolicy::Block,
|
||||||
..Config::test(Alias::new("alice"))
|
..Config::test(Alias::new("alice"))
|
||||||
});
|
});
|
||||||
let working = tempfile::tempdir().unwrap();
|
let working = tempfile::tempdir().unwrap();
|
||||||
|
|
@ -1232,7 +1233,7 @@ fn rad_unseed() {
|
||||||
fn rad_block() {
|
fn rad_block() {
|
||||||
let mut environment = Environment::new();
|
let mut environment = Environment::new();
|
||||||
let alice = environment.node(Config {
|
let alice = environment.node(Config {
|
||||||
seeding_policy: SeedingPolicy::permissive(),
|
seeding_policy: DefaultSeedingPolicy::permissive(),
|
||||||
..Config::test(Alias::new("alice"))
|
..Config::test(Alias::new("alice"))
|
||||||
});
|
});
|
||||||
let working = tempfile::tempdir().unwrap();
|
let working = tempfile::tempdir().unwrap();
|
||||||
|
|
@ -1551,7 +1552,7 @@ fn rad_init_sync_preferred() {
|
||||||
let mut environment = Environment::new();
|
let mut environment = Environment::new();
|
||||||
let mut alice = environment
|
let mut alice = environment
|
||||||
.node(Config {
|
.node(Config {
|
||||||
seeding_policy: SeedingPolicy::permissive(),
|
seeding_policy: DefaultSeedingPolicy::permissive(),
|
||||||
..Config::test(Alias::new("alice"))
|
..Config::test(Alias::new("alice"))
|
||||||
})
|
})
|
||||||
.spawn();
|
.spawn();
|
||||||
|
|
@ -1583,7 +1584,7 @@ fn rad_init_sync_timeout() {
|
||||||
let mut environment = Environment::new();
|
let mut environment = Environment::new();
|
||||||
let mut alice = environment
|
let mut alice = environment
|
||||||
.node(Config {
|
.node(Config {
|
||||||
seeding_policy: SeedingPolicy::Block,
|
seeding_policy: DefaultSeedingPolicy::Block,
|
||||||
..Config::test(Alias::new("alice"))
|
..Config::test(Alias::new("alice"))
|
||||||
})
|
})
|
||||||
.spawn();
|
.spawn();
|
||||||
|
|
@ -1926,7 +1927,7 @@ fn test_replication_via_seed() {
|
||||||
let alice = environment.node(config::relay("alice"));
|
let alice = environment.node(config::relay("alice"));
|
||||||
let bob = environment.node(config::relay("bob"));
|
let bob = environment.node(config::relay("bob"));
|
||||||
let seed = environment.node(Config {
|
let seed = environment.node(Config {
|
||||||
seeding_policy: SeedingPolicy::permissive(),
|
seeding_policy: DefaultSeedingPolicy::permissive(),
|
||||||
..config::relay("seed")
|
..config::relay("seed")
|
||||||
});
|
});
|
||||||
let working = environment.tmp().join("working");
|
let working = environment.tmp().join("working");
|
||||||
|
|
@ -2174,7 +2175,7 @@ fn rad_patch_open_explore() {
|
||||||
let mut environment = Environment::new();
|
let mut environment = Environment::new();
|
||||||
let seed = environment
|
let seed = environment
|
||||||
.node(Config {
|
.node(Config {
|
||||||
seeding_policy: SeedingPolicy::permissive(),
|
seeding_policy: DefaultSeedingPolicy::permissive(),
|
||||||
..config::seed("seed")
|
..config::seed("seed")
|
||||||
})
|
})
|
||||||
.spawn();
|
.spawn();
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ impl Runtime {
|
||||||
let clock = LocalTime::now();
|
let clock = LocalTime::now();
|
||||||
let timestamp = clock.into();
|
let timestamp = clock.into();
|
||||||
let storage = Storage::open(home.storage(), git::UserInfo { alias, key: id })?;
|
let storage = Storage::open(home.storage(), git::UserInfo { alias, key: id })?;
|
||||||
let policy = config.seeding_policy;
|
let policy = config.seeding_policy.into();
|
||||||
|
|
||||||
for (key, _) in &config.extra {
|
for (key, _) in &config.extra {
|
||||||
log::warn!(target: "node", "Unused or deprecated configuration attribute {:?}", key);
|
log::warn!(target: "node", "Unused or deprecated configuration attribute {:?}", key);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use localtime::LocalDuration;
|
||||||
use serde_json as json;
|
use serde_json as json;
|
||||||
|
|
||||||
use crate::node;
|
use crate::node;
|
||||||
use crate::node::policy::SeedingPolicy;
|
use crate::node::policy::{Scope, SeedingPolicy};
|
||||||
use crate::node::{Address, Alias, NodeId};
|
use crate::node::{Address, Alias, NodeId};
|
||||||
|
|
||||||
/// Peer-to-peer protocol version.
|
/// Peer-to-peer protocol version.
|
||||||
|
|
@ -260,6 +260,42 @@ pub enum AddressConfig {
|
||||||
Forward,
|
Forward,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Default seeding policy. Applies when no repository policies for the given repo are found.
|
||||||
|
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase", tag = "default")]
|
||||||
|
pub enum DefaultSeedingPolicy {
|
||||||
|
/// Allow seeding.
|
||||||
|
Allow {
|
||||||
|
/// Seeding scope.
|
||||||
|
#[serde(default)]
|
||||||
|
scope: Scope,
|
||||||
|
},
|
||||||
|
/// Block seeding.
|
||||||
|
#[default]
|
||||||
|
Block,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultSeedingPolicy {
|
||||||
|
/// Is this an "allow" policy.
|
||||||
|
pub fn is_allow(&self) -> bool {
|
||||||
|
matches!(self, Self::Allow { .. })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Seed everything from anyone.
|
||||||
|
pub fn permissive() -> Self {
|
||||||
|
Self::Allow { scope: Scope::All }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<DefaultSeedingPolicy> for SeedingPolicy {
|
||||||
|
fn from(policy: DefaultSeedingPolicy) -> Self {
|
||||||
|
match policy {
|
||||||
|
DefaultSeedingPolicy::Block => Self::Block,
|
||||||
|
DefaultSeedingPolicy::Allow { scope } => Self::Allow { scope },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Service configuration.
|
/// Service configuration.
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
|
@ -303,7 +339,7 @@ pub struct Config {
|
||||||
pub workers: usize,
|
pub workers: usize,
|
||||||
/// Default seeding policy.
|
/// Default seeding policy.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub seeding_policy: SeedingPolicy,
|
pub seeding_policy: DefaultSeedingPolicy,
|
||||||
/// Extra fields that aren't supported.
|
/// Extra fields that aren't supported.
|
||||||
#[serde(flatten, skip_serializing)]
|
#[serde(flatten, skip_serializing)]
|
||||||
pub extra: json::Map<String, json::Value>,
|
pub extra: json::Map<String, json::Value>,
|
||||||
|
|
@ -331,7 +367,7 @@ impl Config {
|
||||||
limits: Limits::default(),
|
limits: Limits::default(),
|
||||||
workers: DEFAULT_WORKERS,
|
workers: DEFAULT_WORKERS,
|
||||||
log: defaults::log(),
|
log: defaults::log(),
|
||||||
seeding_policy: SeedingPolicy::default(),
|
seeding_policy: DefaultSeedingPolicy::default(),
|
||||||
extra: json::Map::default(),
|
extra: json::Map::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,9 @@ pub struct FollowPolicy {
|
||||||
pub policy: Policy,
|
pub policy: Policy,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default seeding policy. Applies when no repository policies for the given repo are found.
|
/// Seeding policy of a node or repo.
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
#[serde(rename_all = "camelCase", tag = "default")]
|
#[serde(rename_all = "camelCase", tag = "policy")]
|
||||||
pub enum SeedingPolicy {
|
pub enum SeedingPolicy {
|
||||||
/// Allow seeding.
|
/// Allow seeding.
|
||||||
Allow {
|
Allow {
|
||||||
|
|
@ -50,11 +50,6 @@ pub enum SeedingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SeedingPolicy {
|
impl SeedingPolicy {
|
||||||
/// Seed everything from anyone.
|
|
||||||
pub fn permissive() -> Self {
|
|
||||||
Self::Allow { scope: Scope::All }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Is this an "allow" policy.
|
/// Is this an "allow" policy.
|
||||||
pub fn is_allow(&self) -> bool {
|
pub fn is_allow(&self) -> bool {
|
||||||
matches!(self, Self::Allow { .. })
|
matches!(self, Self::Allow { .. })
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,11 @@ use crate::crypto::ssh::agent::Agent;
|
||||||
use crate::crypto::ssh::{keystore, Keystore, Passphrase};
|
use crate::crypto::ssh::{keystore, Keystore, Passphrase};
|
||||||
use crate::crypto::{PublicKey, Signer};
|
use crate::crypto::{PublicKey, Signer};
|
||||||
use crate::explorer::Explorer;
|
use crate::explorer::Explorer;
|
||||||
|
use crate::node::config::DefaultSeedingPolicy;
|
||||||
use crate::node::policy::config::store::Read;
|
use crate::node::policy::config::store::Read;
|
||||||
use crate::node::{
|
use crate::node::{
|
||||||
notifications, policy,
|
notifications, policy,
|
||||||
policy::{Policy, Scope, SeedingPolicy},
|
policy::{Policy, Scope},
|
||||||
Alias, AliasStore, Handle as _, Node, UserAgent,
|
Alias, AliasStore, Handle as _, Node, UserAgent,
|
||||||
};
|
};
|
||||||
use crate::prelude::{Did, NodeId, RepoId};
|
use crate::prelude::{Did, NodeId, RepoId};
|
||||||
|
|
@ -254,8 +255,8 @@ impl Config {
|
||||||
) {
|
) {
|
||||||
log::warn!(target: "radicle", "Overwriting `seedingPolicy` configuration");
|
log::warn!(target: "radicle", "Overwriting `seedingPolicy` configuration");
|
||||||
cfg.node.seeding_policy = match policy {
|
cfg.node.seeding_policy = match policy {
|
||||||
Policy::Allow => SeedingPolicy::Allow { scope },
|
Policy::Allow => DefaultSeedingPolicy::Allow { scope },
|
||||||
Policy::Block => SeedingPolicy::Block,
|
Policy::Block => DefaultSeedingPolicy::Block,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -415,7 +416,7 @@ impl Profile {
|
||||||
pub fn policies(&self) -> Result<policy::config::Config<Read>, policy::store::Error> {
|
pub fn policies(&self) -> Result<policy::config::Config<Read>, policy::store::Error> {
|
||||||
let path = self.node().join(node::POLICIES_DB_FILE);
|
let path = self.node().join(node::POLICIES_DB_FILE);
|
||||||
let config = policy::config::Config::new(
|
let config = policy::config::Config::new(
|
||||||
self.config.node.seeding_policy,
|
self.config.node.seeding_policy.into(),
|
||||||
policy::store::Store::reader(path)?,
|
policy::store::Store::reader(path)?,
|
||||||
);
|
);
|
||||||
Ok(config)
|
Ok(config)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue