diff --git a/radicle-cli/examples/rad-clone-all.md b/radicle-cli/examples/rad-clone-all.md index 300e5969..aa99a89f 100644 --- a/radicle-cli/examples/rad-clone-all.md +++ b/radicle-cli/examples/rad-clone-all.md @@ -1,6 +1,6 @@ ``` $ rad clone rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --scope all -✓ Tracking relationship established for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all' +✓ Seeding policy updated for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all' ✓ Fetching rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji from z6MknSL…StBU8Vi.. ✓ Forking under z6Mkux1…nVhib7Z.. ✓ Creating checkout in ./heartwood.. diff --git a/radicle-cli/examples/rad-clone-connect.md b/radicle-cli/examples/rad-clone-connect.md index 799059aa..02883783 100644 --- a/radicle-cli/examples/rad-clone-connect.md +++ b/radicle-cli/examples/rad-clone-connect.md @@ -3,7 +3,7 @@ automatically connect to the necessary seeds. ``` $ rad clone rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji -✓ Tracking relationship established for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all' +✓ Seeding policy updated for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all' ✓ Connecting to z6MknSL…StBU8Vi@[..] ✓ Fetching rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji from z6MknSL…StBU8Vi.. ✓ Connecting to z6Mkt67…v4N1tRk@[..] diff --git a/radicle-cli/examples/rad-clone-unknown.md b/radicle-cli/examples/rad-clone-unknown.md index 1bfe7b19..8ce39d88 100644 --- a/radicle-cli/examples/rad-clone-unknown.md +++ b/radicle-cli/examples/rad-clone-unknown.md @@ -2,6 +2,6 @@ Trying to clone a repository that is not in our routing table returns an error: ``` (fail) $ rad clone rad:zVNuptPuk5XauitpCWSNVCXGGfXW --scope followed -✓ Tracking relationship established for rad:zVNuptPuk5XauitpCWSNVCXGGfXW with scope 'followed' +✓ Seeding policy updated for rad:zVNuptPuk5XauitpCWSNVCXGGfXW with scope 'followed' ✗ Error: no seeds found for rad:zVNuptPuk5XauitpCWSNVCXGGfXW ``` diff --git a/radicle-cli/examples/rad-clone.md b/radicle-cli/examples/rad-clone.md index 7b382e1d..14d3cfa2 100644 --- a/radicle-cli/examples/rad-clone.md +++ b/radicle-cli/examples/rad-clone.md @@ -3,7 +3,7 @@ To create a local copy of a repository on the radicle network, we use the ``` $ rad clone rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --scope followed -✓ Tracking relationship established for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'followed' +✓ Seeding policy updated for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'followed' ✓ Fetching rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji from z6MknSL…StBU8Vi.. ✓ Forking under z6Mkt67…v4N1tRk.. ✓ Creating checkout in ./heartwood.. diff --git a/radicle-cli/examples/rad-patch-pull-update.md b/radicle-cli/examples/rad-patch-pull-update.md index 62c3ffc1..769ba261 100644 --- a/radicle-cli/examples/rad-patch-pull-update.md +++ b/radicle-cli/examples/rad-patch-pull-update.md @@ -20,7 +20,7 @@ To push changes, run `git push`. ``` ~bob $ rad clone rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK -✓ Tracking relationship established for rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK with scope 'all' +✓ Seeding policy updated for rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK with scope 'all' ✓ Fetching rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK from z6MknSL…StBU8Vi.. ✓ Forking under z6Mkt67…v4N1tRk.. ✓ Creating checkout in ./heartwood.. diff --git a/radicle-cli/src/commands/clone.rs b/radicle-cli/src/commands/clone.rs index 5ae9c9dc..7b2e4d2a 100644 --- a/radicle-cli/src/commands/clone.rs +++ b/radicle-cli/src/commands/clone.rs @@ -12,7 +12,7 @@ use radicle::git::raw; use radicle::identity::doc; use radicle::identity::doc::{DocError, Id}; use radicle::node; -use radicle::node::tracking::Scope; +use radicle::node::policy::Scope; use radicle::node::{Handle as _, Node}; use radicle::prelude::*; use radicle::rad; @@ -39,7 +39,7 @@ Usage Options - --scope Tracking scope (default: all) + --scope Follow scope (default: all) --no-announce Do not announce our new refs to the network --help Print help @@ -219,7 +219,7 @@ pub fn clone( // Track. if node.seed(id, scope)? { term::success!( - "Tracking relationship established for {} with scope '{scope}'", + "Seeding policy updated for {} with scope '{scope}'", term::format::tertiary(id) ); } diff --git a/radicle-cli/src/commands/follow.rs b/radicle-cli/src/commands/follow.rs index bdac1bb3..f2e7a891 100644 --- a/radicle-cli/src/commands/follow.rs +++ b/radicle-cli/src/commands/follow.rs @@ -2,8 +2,7 @@ use std::ffi::OsString; use anyhow::anyhow; -use radicle::node::tracking::Alias; -use radicle::node::{Handle, NodeId}; +use radicle::node::{Alias, Handle, NodeId}; use radicle::{prelude::*, Node}; use crate::terminal as term; diff --git a/radicle-cli/src/commands/init.rs b/radicle-cli/src/commands/init.rs index 4891bac2..88110b23 100644 --- a/radicle-cli/src/commands/init.rs +++ b/radicle-cli/src/commands/init.rs @@ -12,7 +12,7 @@ use serde_json as json; use radicle::crypto::{ssh, Verified}; use radicle::git::RefString; use radicle::identity::Visibility; -use radicle::node::tracking::Scope; +use radicle::node::policy::Scope; use radicle::node::{Handle, NodeId}; use radicle::prelude::Doc; use radicle::{profile, Node}; @@ -37,7 +37,7 @@ Options --name Name of the project --description Description of the project --default-branch The default branch of the project - --scope Tracking scope (default: all) + --scope Repository follow scope (default: all) --private Set repository visibility to *private* --public Set repository visibility to *public* -u, --set-upstream Setup the upstream of the default branch diff --git a/radicle-cli/src/commands/inspect.rs b/radicle-cli/src/commands/inspect.rs index b2e540ad..7085e9fc 100644 --- a/radicle-cli/src/commands/inspect.rs +++ b/radicle-cli/src/commands/inspect.rs @@ -9,7 +9,7 @@ use chrono::prelude::*; use radicle::identity::Id; use radicle::identity::Identity; -use radicle::node::tracking::Policy; +use radicle::node::policy::Policy; use radicle::node::AliasStore as _; use radicle::storage::refs::RefsAt; use radicle::storage::{ReadRepository, ReadStorage}; diff --git a/radicle-cli/src/commands/node/policies.rs b/radicle-cli/src/commands/node/policies.rs index 3b761c6a..d3f1a797 100644 --- a/radicle-cli/src/commands/node/policies.rs +++ b/radicle-cli/src/commands/node/policies.rs @@ -1,5 +1,5 @@ use radicle::crypto::PublicKey; -use radicle::node::{tracking, AliasStore}; +use radicle::node::{policy, AliasStore}; use radicle::prelude::Did; use radicle::Profile; @@ -16,7 +16,7 @@ pub fn seeding(profile: &Profile) -> anyhow::Result<()> { ]); t.divider(); - for tracking::Repo { id, scope, policy } in store.repo_policies()? { + for policy::Repo { id, scope, policy } in store.repo_policies()? { let id = id.to_string(); let scope = scope.to_string(); let policy = policy.to_string(); @@ -43,7 +43,7 @@ pub fn following(profile: &Profile) -> anyhow::Result<()> { ]); t.divider(); - for tracking::Node { id, alias, policy } in store.node_policies()? { + for policy::Node { id, alias, policy } in store.node_policies()? { t.push([ term::format::highlight(Did::from(id).to_string()), match alias { diff --git a/radicle-cli/src/commands/seed.rs b/radicle-cli/src/commands/seed.rs index bb03ec73..0c5b0082 100644 --- a/radicle-cli/src/commands/seed.rs +++ b/radicle-cli/src/commands/seed.rs @@ -3,7 +3,7 @@ use std::time; use anyhow::anyhow; -use radicle::node::tracking::Scope; +use radicle::node::policy::Scope; use radicle::node::Handle; use radicle::{prelude::*, Node}; diff --git a/radicle-cli/src/project.rs b/radicle-cli/src/project.rs index 71e99f16..81ad950b 100644 --- a/radicle-cli/src/project.rs +++ b/radicle-cli/src/project.rs @@ -2,7 +2,7 @@ use radicle::prelude::*; use crate::git; use radicle::git::RefStr; -use radicle::node::tracking::Scope; +use radicle::node::policy::Scope; use radicle::node::{Handle, NodeId}; use radicle::Node; diff --git a/radicle-cli/tests/commands.rs b/radicle-cli/tests/commands.rs index 8aa5b590..0ba652bc 100644 --- a/radicle-cli/tests/commands.rs +++ b/radicle-cli/tests/commands.rs @@ -14,7 +14,7 @@ use radicle::storage::{ReadStorage, RemoteRepository}; use radicle::test::fixtures; use radicle_cli_test::TestFormula; -use radicle_node::service::tracking::{Policy, Scope}; +use radicle_node::service::policy::{Policy, Scope}; use radicle_node::service::Event; use radicle_node::test::environment::{Config, Environment}; #[allow(unused_imports)] diff --git a/radicle-fetch/src/handle.rs b/radicle-fetch/src/handle.rs index ddcff453..c2898218 100644 --- a/radicle-fetch/src/handle.rs +++ b/radicle-fetch/src/handle.rs @@ -86,7 +86,7 @@ impl Handle { pub mod error { use std::io; - use radicle::node::tracking; + use radicle::node::policy; use radicle::prelude::Id; use radicle::{git, storage}; use thiserror::Error; @@ -96,7 +96,7 @@ pub mod error { #[error(transparent)] Io(#[from] io::Error), #[error(transparent)] - Tracking(#[from] tracking::config::Error), + Tracking(#[from] policy::config::Error), } #[derive(Debug, Error)] @@ -105,7 +105,7 @@ pub mod error { FailedPolicy { rid: Id, #[source] - err: tracking::store::Error, + err: policy::store::Error, }, #[error("cannot fetch {rid} as it is not tracked")] BlockedPolicy { rid: Id }, @@ -113,7 +113,7 @@ pub mod error { FailedNodes { rid: Id, #[source] - err: tracking::store::Error, + err: policy::store::Error, }, #[error(transparent)] diff --git a/radicle-fetch/src/tracking.rs b/radicle-fetch/src/tracking.rs index 788ec996..c34b293a 100644 --- a/radicle-fetch/src/tracking.rs +++ b/radicle-fetch/src/tracking.rs @@ -1,11 +1,11 @@ use std::collections::HashSet; use radicle::crypto::PublicKey; -use radicle::node::tracking::config::Config; -use radicle::node::tracking::store::Read; +use radicle::node::policy::config::Config; +use radicle::node::policy::store::Read; use radicle::prelude::Id; -pub use radicle::node::tracking::{Policy, Scope}; +pub use radicle::node::policy::{Policy, Scope}; #[derive(Clone, Debug)] pub enum Tracked { @@ -70,14 +70,14 @@ impl BlockList { } pub mod error { - use radicle::node::tracking; + use radicle::node::policy; use radicle::prelude::Id; use radicle::storage; use thiserror::Error; #[derive(Debug, Error)] #[error(transparent)] - pub struct Blocked(#[from] tracking::config::Error); + pub struct Blocked(#[from] policy::config::Error); #[derive(Debug, Error)] pub enum Tracking { @@ -85,7 +85,7 @@ pub mod error { FailedPolicy { rid: Id, #[source] - err: tracking::store::Error, + err: policy::store::Error, }, #[error("cannot fetch {rid} as it is not tracked")] BlockedPolicy { rid: Id }, @@ -93,7 +93,7 @@ pub mod error { FailedNodes { rid: Id, #[source] - err: tracking::store::Error, + err: policy::store::Error, }, #[error(transparent)] diff --git a/radicle-httpd/src/api.rs b/radicle-httpd/src/api.rs index dcf3200f..15c5a2cd 100644 --- a/radicle-httpd/src/api.rs +++ b/radicle-httpd/src/api.rs @@ -18,8 +18,8 @@ use tower_http::cors::{self, CorsLayer}; use radicle::cob::{issue, Uri}; use radicle::cob::{patch, Embed}; use radicle::identity::{DocAt, Id}; +use radicle::node::policy::Scope; use radicle::node::routing::Store; -use radicle::node::tracking::Scope; use radicle::node::{Handle, NodeId}; use radicle::storage::{Oid, ReadRepository, ReadStorage}; use radicle::{Node, Profile}; diff --git a/radicle-httpd/src/api/error.rs b/radicle-httpd/src/api/error.rs index b46c868a..e5c2ac4e 100644 --- a/radicle-httpd/src/api/error.rs +++ b/radicle-httpd/src/api/error.rs @@ -72,7 +72,7 @@ pub enum Error { /// Tracking store error. #[error(transparent)] - TrackingStore(#[from] radicle::node::tracking::store::Error), + TrackingStore(#[from] radicle::node::policy::store::Error), /// Node database error. #[error(transparent)] diff --git a/radicle-httpd/src/api/v1/node.rs b/radicle-httpd/src/api/v1/node.rs index f1e47944..c9f5c1ec 100644 --- a/radicle-httpd/src/api/v1/node.rs +++ b/radicle-httpd/src/api/v1/node.rs @@ -7,7 +7,7 @@ use hyper::StatusCode; use serde_json::json; use radicle::identity::Id; -use radicle::node::{tracking, Handle, DEFAULT_TIMEOUT}; +use radicle::node::{policy, Handle, DEFAULT_TIMEOUT}; use radicle::Node; use crate::api::error::Error; @@ -20,7 +20,7 @@ pub fn router(ctx: Context) -> Router { .route("/node/policies/repos", get(node_policies_repos_handler)) .route( "/node/policies/repos/:rid", - put(node_policies_track_handler).delete(node_policies_untrack_handler), + put(node_policies_seed_handler).delete(node_policies_unseed_handler), ) .with_state(ctx) } @@ -57,7 +57,7 @@ async fn node_policies_repos_handler(State(ctx): State) -> impl IntoRes let tracking = ctx.profile.tracking()?; let mut repos = Vec::new(); - for tracking::Repo { id, scope, policy } in tracking.repo_policies()? { + for policy::Repo { id, scope, policy } in tracking.repo_policies()? { repos.push(json!({ "id": id, "scope": scope, @@ -70,7 +70,7 @@ async fn node_policies_repos_handler(State(ctx): State) -> impl IntoRes /// Track a new repo. /// `PUT /node/policies/repos/:rid` -async fn node_policies_track_handler( +async fn node_policies_seed_handler( State(ctx): State, AuthBearer(token): AuthBearer, Path(project): Path, @@ -78,7 +78,8 @@ async fn node_policies_track_handler( ) -> impl IntoResponse { api::auth::validate(&ctx, &token).await?; let mut node = Node::new(ctx.profile.socket()); - node.track_repo(project, qs.scope.unwrap_or_default())?; + node.seed(project, qs.scope.unwrap_or_default())?; + if let Some(from) = qs.from { let results = node.fetch(project, from, DEFAULT_TIMEOUT)?; return Ok::<_, Error>(( @@ -86,20 +87,19 @@ async fn node_policies_track_handler( Json(json!({ "success": true, "results": results })), )); } - Ok::<_, Error>((StatusCode::OK, Json(json!({ "success": true })))) } /// Untrack a repo. /// `DELETE /node/policies/repos/:rid` -async fn node_policies_untrack_handler( +async fn node_policies_unseed_handler( State(ctx): State, AuthBearer(token): AuthBearer, Path(project): Path, ) -> impl IntoResponse { api::auth::validate(&ctx, &token).await?; let mut node = Node::new(ctx.profile.socket()); - node.untrack_repo(project)?; + node.unseed(project)?; Ok::<_, Error>((StatusCode::OK, Json(json!({ "success": true })))) } diff --git a/radicle-node/src/control.rs b/radicle-node/src/control.rs index 59b0050e..4110eeba 100644 --- a/radicle-node/src/control.rs +++ b/radicle-node/src/control.rs @@ -228,7 +228,7 @@ mod tests { use crate::identity::Id; use crate::node::Handle; use crate::node::{Alias, Node, NodeId}; - use crate::service::tracking::Scope; + use crate::service::policy::Scope; use crate::test; #[test] diff --git a/radicle-node/src/runtime.rs b/radicle-node/src/runtime.rs index c5b65b1c..8e9b9651 100644 --- a/radicle-node/src/runtime.rs +++ b/radicle-node/src/runtime.rs @@ -26,7 +26,7 @@ use crate::control; use crate::crypto::Signer; use crate::node::{routing, NodeId}; use crate::service::message::NodeAnnouncement; -use crate::service::{gossip, tracking, Event}; +use crate::service::{gossip, policy, Event}; use crate::wire::Wire; use crate::wire::{self, Decode}; use crate::worker; @@ -46,7 +46,7 @@ pub enum Error { Database(#[from] node::db::Error), /// A tracking database error. #[error("tracking database error: {0}")] - Tracking(#[from] tracking::Error), + Tracking(#[from] policy::Error), /// A gossip database error. #[error("gossip database error: {0}")] Gossip(#[from] gossip::Error), @@ -147,7 +147,7 @@ impl Runtime { log::info!(target: "node", "Opening tracking policy configuration.."); let tracking = home.tracking_mut()?; - let tracking = tracking::Config::new(policy, scope, tracking); + let tracking = policy::Config::new(policy, scope, tracking); log::info!(target: "node", "Default tracking policy set to '{}'", &policy); log::info!(target: "node", "Initializing service ({:?})..", network); diff --git a/radicle-node/src/runtime/handle.rs b/radicle-node/src/runtime/handle.rs index a74bee98..7adee047 100644 --- a/radicle-node/src/runtime/handle.rs +++ b/radicle-node/src/runtime/handle.rs @@ -14,7 +14,7 @@ use crate::node::{Alias, Command, FetchResult}; use crate::profile::Home; use crate::runtime::Emitter; use crate::service; -use crate::service::tracking; +use crate::service::policy; use crate::service::NodeId; use crate::service::{CommandError, Config, QueryState}; use crate::service::{Event, Events}; @@ -213,7 +213,7 @@ impl radicle::node::Handle for Handle { receiver.recv().map_err(Error::from) } - fn seed(&mut self, id: Id, scope: tracking::Scope) -> Result { + fn seed(&mut self, id: Id, scope: policy::Scope) -> Result { let (sender, receiver) = chan::bounded(1); self.command(service::Command::TrackRepo(id, scope, sender))?; receiver.recv().map_err(Error::from) diff --git a/radicle-node/src/service.rs b/radicle-node/src/service.rs index 87cc30bc..467fa4c5 100644 --- a/radicle-node/src/service.rs +++ b/radicle-node/src/service.rs @@ -45,7 +45,7 @@ use crate::runtime::Emitter; use crate::service::gossip::Store as _; use crate::service::message::{Announcement, AnnouncementMessage, Info, Ping}; use crate::service::message::{NodeAnnouncement, RefsAnnouncement}; -use crate::service::tracking::{store::Write, Scope}; +use crate::service::policy::{store::Write, Policy, Scope}; use crate::storage; use crate::storage::refs::RefsAt; use crate::storage::ReadRepository; @@ -59,12 +59,12 @@ pub use crate::node::{config::Network, Config, NodeId}; pub use crate::service::message::{Message, ZeroBytes}; pub use crate::service::session::Session; -pub use radicle::node::tracking::config as tracking; +pub use radicle::node::policy::config as policy; use self::io::Outbox; use self::limitter::RateLimiter; use self::message::{InventoryAnnouncement, RefsStatus}; -use self::tracking::NamespacesError; +use self::policy::NamespacesError; /// How often to run the "idle" task. pub const IDLE_INTERVAL: LocalDuration = LocalDuration::from_secs(30); @@ -140,7 +140,7 @@ pub enum Error { #[error(transparent)] Seeds(#[from] seed::Error), #[error(transparent)] - Tracking(#[from] tracking::Error), + Tracking(#[from] policy::Error), #[error(transparent)] Repository(#[from] radicle::storage::RepositoryError), #[error("namespaces error: {0}")] @@ -213,7 +213,7 @@ pub enum CommandError { #[error(transparent)] Routing(#[from] routing::Error), #[error(transparent)] - Tracking(#[from] tracking::Error), + Tracking(#[from] policy::Error), } /// Error returned by [`Service::try_fetch`]. @@ -305,7 +305,7 @@ pub struct Service { /// Node database. db: Stores, /// Tracking policy configuration. - tracking: tracking::Config, + tracking: policy::Config, /// Peer sessions, currently or recently connected. sessions: Sessions, /// Clock. Tells the time. @@ -364,7 +364,7 @@ where clock: LocalTime, db: Stores, storage: S, - tracking: tracking::Config, + tracking: policy::Config, signer: G, rng: Rng, node: NodeAnnouncement, @@ -404,7 +404,7 @@ where /// Track a repository. /// Returns whether or not the tracking policy was updated. - pub fn track_repo(&mut self, id: &Id, scope: Scope) -> Result { + pub fn track_repo(&mut self, id: &Id, scope: Scope) -> Result { let updated = self.tracking.track_repo(id, scope)?; self.filter.insert(id); @@ -415,7 +415,7 @@ where /// Returns whether or not the tracking policy was updated. /// Note that when untracking, we don't announce anything to the network. This is because by /// simply not announcing it anymore, it will eventually be pruned by nodes. - pub fn untrack_repo(&mut self, id: &Id) -> Result { + pub fn untrack_repo(&mut self, id: &Id) -> Result { let updated = self.tracking.untrack_repo(id)?; // Nb. This is potentially slow if we have lots of projects. We should probably // only re-compute the filter when we've untracked a certain amount of projects @@ -425,13 +425,13 @@ where self.filter = Filter::new( self.tracking .repo_policies()? - .filter_map(|t| (t.policy == tracking::Policy::Allow).then_some(t.id)), + .filter_map(|t| (t.policy == Policy::Allow).then_some(t.id)), ); Ok(updated) } /// Check whether we are tracking a certain repository. - pub fn is_tracking(&self, id: &Id) -> Result { + pub fn is_tracking(&self, id: &Id) -> Result { self.tracking.is_repo_tracked(id) } @@ -464,7 +464,7 @@ where } /// Get the tracking policy. - pub fn tracking(&self) -> &tracking::Config { + pub fn tracking(&self) -> &policy::Config { &self.tracking } @@ -570,7 +570,7 @@ where self.filter = Filter::new( self.tracking .repo_policies()? - .filter_map(|t| (t.policy == tracking::Policy::Allow).then_some(t.id)), + .filter_map(|t| (t.policy == Policy::Allow).then_some(t.id)), ); // Try to establish some connections. self.maintain_connections(); @@ -1266,7 +1266,7 @@ where "Service::handle_announcement: error accessing repo tracking configuration", ); - if repo_entry.policy == tracking::Policy::Allow { + if repo_entry.policy == Policy::Allow { let (fresh, stale) = match self.refs_status_of(message, &repo_entry.scope) { Ok(RefsStatus { fresh, stale }) => (fresh, stale), Err(e) => { @@ -1411,7 +1411,7 @@ where fn refs_status_of( &self, message: &RefsAnnouncement, - scope: &tracking::Scope, + scope: &policy::Scope, ) -> Result { let mut refs = message.refs_status(&self.storage)?; @@ -1423,8 +1423,8 @@ where // Second, check the scope. match scope { - tracking::Scope::All => Ok(refs), - tracking::Scope::Followed => { + policy::Scope::All => Ok(refs), + policy::Scope::Followed => { match self.tracking.namespaces_for(&self.storage, &message.rid) { Ok(Namespaces::All) => Ok(refs), Ok(Namespaces::Followed(mut followed)) => { @@ -1817,7 +1817,7 @@ where /// Return a new filter object, based on our tracking policy. fn filter(&self) -> Filter { - if self.config.policy == tracking::Policy::Allow { + if self.config.policy == Policy::Allow { // TODO: Remove bits for blocked repos. Filter::default() } else { @@ -1920,7 +1920,7 @@ where let missing = self .tracking .repo_policies()? - .filter_map(|t| (t.policy == tracking::Policy::Allow).then_some(t.id)) + .filter_map(|t| (t.policy == Policy::Allow).then_some(t.id)) .filter(|rid| !inventory.contains(rid)); for rid in missing { diff --git a/radicle-node/src/test/environment.rs b/radicle-node/src/test/environment.rs index b677a937..234cef42 100644 --- a/radicle-node/src/test/environment.rs +++ b/radicle-node/src/test/environment.rs @@ -18,8 +18,8 @@ use radicle::crypto::{KeyPair, Seed, Signer}; use radicle::git; use radicle::git::refname; use radicle::identity::{Id, Visibility}; +use radicle::node::policy::store as policy; use radicle::node::routing::Store; -use radicle::node::tracking::store as tracking; use radicle::node::Database; use radicle::node::{Alias, TRACKING_DB_FILE}; use radicle::node::{ConnectOptions, Handle as _}; @@ -82,7 +82,7 @@ impl Environment { let signer = MemorySigner::load(&profile.keystore, None).unwrap(); let tracking_db = profile.home.node().join(TRACKING_DB_FILE); - let tracking = tracking::Config::open(tracking_db).unwrap(); + let tracking = policy::Config::open(tracking_db).unwrap(); let db = profile.database_mut().unwrap(); let db = service::Stores::from(db); @@ -122,7 +122,7 @@ impl Environment { ) .unwrap(); - tracking::Config::open(tracking_db).unwrap(); + policy::Config::open(tracking_db).unwrap(); home.database_mut().unwrap(); // Just create the database. transport::local::register(storage.clone()); @@ -149,7 +149,7 @@ pub struct Node { pub storage: Storage, pub config: Config, pub db: service::Stores, - pub tracking: tracking::Config, + pub tracking: policy::Config, } /// Handle to a running node. @@ -420,7 +420,7 @@ impl + Signer + Clone> Node { assert!(self .tracking - .track_repo(&id, node::tracking::Scope::Followed) + .track_repo(&id, node::policy::Scope::Followed) .unwrap()); log::debug!( diff --git a/radicle-node/src/test/handle.rs b/radicle-node/src/test/handle.rs index 7219b6f7..1d4e6c18 100644 --- a/radicle-node/src/test/handle.rs +++ b/radicle-node/src/test/handle.rs @@ -9,7 +9,7 @@ use radicle::storage::refs::RefsAt; use crate::identity::Id; use crate::node::{Alias, Config, ConnectOptions, ConnectResult, Event, FetchResult, Seeds}; use crate::runtime::HandleError; -use crate::service::tracking; +use crate::service::policy; use crate::service::NodeId; #[derive(Default, Clone)] @@ -60,7 +60,7 @@ impl radicle::node::Handle for Handle { }) } - fn seed(&mut self, id: Id, _scope: tracking::Scope) -> Result { + fn seed(&mut self, id: Id, _scope: policy::Scope) -> Result { Ok(self.tracking_repos.lock().unwrap().insert(id)) } diff --git a/radicle-node/src/test/peer.rs b/radicle-node/src/test/peer.rs index a75a8e97..2629a8ae 100644 --- a/radicle-node/src/test/peer.rs +++ b/radicle-node/src/test/peer.rs @@ -24,7 +24,7 @@ use crate::runtime::Emitter; use crate::service; use crate::service::io::Io; use crate::service::message::*; -use crate::service::tracking::{Policy, Scope}; +use crate::service::policy::{Policy, Scope}; use crate::service::*; use crate::storage::git::transport::remote; use crate::storage::Inventory; @@ -162,8 +162,8 @@ where storage: S, mut config: Config, ) -> Self { - let tracking = tracking::Store::::memory().unwrap(); - let mut tracking = tracking::Config::new(config.policy, config.scope, tracking); + let tracking = policy::Store::::memory().unwrap(); + let mut tracking = policy::Config::new(config.policy, config.scope, tracking); let id = *config.signer.public_key(); let ip = ip.into(); let local_addr = net::SocketAddr::new(ip, config.rng.u16(..)); diff --git a/radicle-node/src/tests.rs b/radicle-node/src/tests.rs index 18ae0c3a..84fc8706 100644 --- a/radicle-node/src/tests.rs +++ b/radicle-node/src/tests.rs @@ -395,7 +395,7 @@ fn test_tracking() { let (sender, receiver) = chan::bounded(1); alice.command(Command::TrackRepo( proj_id, - tracking::Scope::default(), + policy::Scope::default(), sender, )); let policy_change = receiver.recv().map_err(runtime::HandleError::from).unwrap(); @@ -504,7 +504,7 @@ fn test_announcement_rebroadcast_duplicates() { anns.insert(bob.node_announcement()); for rid in rids { - alice.track_repo(&rid, tracking::Scope::All).unwrap(); + alice.track_repo(&rid, policy::Scope::All).unwrap(); anns.insert(carol.refs_announcement(rid)); anns.insert(bob.refs_announcement(rid)); } @@ -676,9 +676,9 @@ fn test_refs_announcement_relay() { }; let bob_inv = bob.storage().inventory().unwrap(); - alice.track_repo(&bob_inv[0], tracking::Scope::All).unwrap(); - alice.track_repo(&bob_inv[1], tracking::Scope::All).unwrap(); - alice.track_repo(&bob_inv[2], tracking::Scope::All).unwrap(); + alice.track_repo(&bob_inv[0], policy::Scope::All).unwrap(); + alice.track_repo(&bob_inv[1], policy::Scope::All).unwrap(); + alice.track_repo(&bob_inv[2], policy::Scope::All).unwrap(); alice.connect_to(&bob); alice.connect_to(&eve); alice.receive(eve.id(), Message::Subscribe(Subscribe::all())); @@ -742,7 +742,7 @@ fn test_refs_announcement_fetch_trusted_no_inventory() { let bob_inv = bob.storage().inventory().unwrap(); let rid = bob_inv[0]; - alice.track_repo(&rid, tracking::Scope::Followed).unwrap(); + alice.track_repo(&rid, policy::Scope::Followed).unwrap(); alice.connect_to(&bob); // Alice receives Bob's refs. @@ -798,7 +798,7 @@ fn test_refs_announcement_followed() { // Alice uses Scope::Followed, and did not track Bob yet. alice.connect_to(&bob); - alice.track_repo(&rid, tracking::Scope::Followed).unwrap(); + alice.track_repo(&rid, policy::Scope::Followed).unwrap(); // Alice receives Bob's refs alice.receive(bob.id(), bob.refs_announcement(rid)); @@ -834,7 +834,7 @@ fn test_refs_announcement_no_subscribe() { let eve = Peer::new("eve", [9, 9, 9, 9]); let id = arbitrary::gen(1); - alice.track_repo(&id, tracking::Scope::All).unwrap(); + alice.track_repo(&id, policy::Scope::All).unwrap(); alice.connect_to(&bob); alice.connect_to(&eve); alice.receive(bob.id(), bob.refs_announcement(rid)); @@ -863,7 +863,7 @@ fn test_refs_announcement_offline() { let inv = alice.inventory(); let rid = inv.first().unwrap(); let mut bob = Peer::new("bob", [8, 8, 8, 8]); - bob.track_repo(rid, tracking::Scope::All).unwrap(); + bob.track_repo(rid, policy::Scope::All).unwrap(); // Make sure alice's service wasn't initialized before. assert!(alice.initialize()); @@ -1255,7 +1255,7 @@ fn test_track_repo_subscribe() { let (send, recv) = chan::bounded(1); alice.connect_to(&bob); - alice.command(Command::TrackRepo(rid, tracking::Scope::default(), send)); + alice.command(Command::TrackRepo(rid, policy::Scope::default(), send)); assert!(recv.recv().unwrap()); assert_matches!( @@ -1275,7 +1275,7 @@ fn test_fetch_missing_inventory_on_gossip() { let bob = Peer::new("bob", [8, 8, 8, 8]); let now = LocalTime::now(); - alice.track_repo(&rid, node::tracking::Scope::All).unwrap(); + alice.track_repo(&rid, node::policy::Scope::All).unwrap(); alice.connect_to(&bob); alice.receive( bob.id(), @@ -1300,7 +1300,7 @@ fn test_fetch_missing_inventory_on_schedule() { let bob = Peer::new("bob", [8, 8, 8, 8]); let now = LocalTime::now(); - alice.track_repo(&rid, node::tracking::Scope::All).unwrap(); + alice.track_repo(&rid, node::policy::Scope::All).unwrap(); alice.connect_to(&bob); alice.receive( bob.id(), @@ -1441,7 +1441,7 @@ fn test_refs_synced_event() { }); let msg = ann.signed(bob.signer()); - alice.track_repo(&acme, tracking::Scope::All).unwrap(); + alice.track_repo(&acme, policy::Scope::All).unwrap(); alice.connect_to(&bob); alice.receive(bob.id, Message::Announcement(msg)); @@ -1542,14 +1542,14 @@ fn test_push_and_pull() { let (sender, _) = chan::bounded(1); bob.command(service::Command::TrackRepo( proj_id, - tracking::Scope::default(), + policy::Scope::default(), sender, )); // Eve seeds Alice's project. let (sender, _) = chan::bounded(1); eve.command(service::Command::TrackRepo( proj_id, - tracking::Scope::default(), + policy::Scope::default(), sender, )); diff --git a/radicle-node/src/tests/e2e.rs b/radicle-node/src/tests/e2e.rs index fd6458dd..500b8eae 100644 --- a/radicle-node/src/tests/e2e.rs +++ b/radicle-node/src/tests/e2e.rs @@ -13,7 +13,7 @@ use radicle::{assert_matches, rad}; use crate::node::config::Limits; use crate::node::{Config, ConnectOptions}; use crate::service; -use crate::service::tracking::Scope; +use crate::service::policy::Scope; use crate::storage::git::transport; use crate::test::environment::{converge, Environment, Node}; use crate::test::logger; diff --git a/radicle-node/src/worker.rs b/radicle-node/src/worker.rs index 513d020f..4aba4346 100644 --- a/radicle-node/src/worker.rs +++ b/radicle-node/src/worker.rs @@ -18,7 +18,8 @@ use radicle::{crypto, Storage}; use radicle_fetch::FetchLimit; use crate::runtime::{thread, Handle}; -use crate::service::tracking; +use crate::service::policy; +use crate::service::policy::Policy; use crate::wire::StreamId; pub use channels::{ChannelEvent, Channels}; @@ -49,7 +50,7 @@ pub enum FetchError { #[error(transparent)] Storage(#[from] radicle::storage::Error), #[error(transparent)] - TrackingConfig(#[from] radicle::node::tracking::store::Error), + TrackingConfig(#[from] radicle::node::policy::store::Error), #[error(transparent)] Tracked(#[from] radicle_fetch::tracking::error::Tracking), #[error(transparent)] @@ -152,9 +153,9 @@ pub struct TaskResult { #[derive(Debug, Clone)] pub struct FetchConfig { /// Default policy, if a policy for a specific node or repository was not found. - pub policy: tracking::Policy, + pub policy: Policy, /// Default scope, if a scope for a specific repository was not found. - pub scope: tracking::Scope, + pub scope: policy::Scope, /// Path to the tracking database. pub tracking_db: PathBuf, /// Data limits when fetching from a remote. @@ -282,12 +283,11 @@ impl Worker { local, expiry, } = &self.fetch_config; - let tracking = - tracking::Config::new(*policy, *scope, tracking::Store::reader(tracking_db)?); + let policies = policy::Config::new(*policy, *scope, policy::Store::reader(tracking_db)?); // N.b. if the `rid` is blocked this will return an error, so // we won't continue with any further set up of the fetch. - let tracked = radicle_fetch::Tracked::from_config(rid, &tracking)?; - let blocked = radicle_fetch::BlockList::from_config(&tracking)?; + let tracked = radicle_fetch::Tracked::from_config(rid, &policies)?; + let blocked = radicle_fetch::BlockList::from_config(&policies)?; let handle = fetch::Handle::new(rid, *local, &self.storage, tracked, blocked, channels)?; let result = handle.fetch(rid, &self.storage, *limit, remote, refs_at)?; diff --git a/radicle/src/node.rs b/radicle/src/node.rs index 2ffecf0f..e4b5bf62 100644 --- a/radicle/src/node.rs +++ b/radicle/src/node.rs @@ -4,9 +4,9 @@ pub mod address; pub mod config; pub mod db; pub mod events; +pub mod policy; pub mod routing; pub mod seed; -pub mod tracking; use std::collections::{BTreeSet, HashMap, HashSet}; use std::io::{BufRead, BufReader}; @@ -414,7 +414,7 @@ pub enum Command { /// Seed the given repository. #[serde(rename_all = "camelCase")] - Seed { rid: Id, scope: tracking::Scope }, + Seed { rid: Id, scope: policy::Scope }, /// Unseed the given repository. #[serde(rename_all = "camelCase")] @@ -777,7 +777,7 @@ pub trait Handle: Clone + Sync + Send { ) -> Result; /// Start seeding the given repo. May update the scope. Does nothing if the /// repo is already seeded. - fn seed(&mut self, id: Id, scope: tracking::Scope) -> Result; + fn seed(&mut self, id: Id, scope: policy::Scope) -> Result; /// Start following the given peer. fn follow(&mut self, id: NodeId, alias: Option) -> Result; /// Un-seed the given repo and delete it from storage. @@ -988,7 +988,7 @@ impl Handle for Node { Ok(response.updated) } - fn seed(&mut self, rid: Id, scope: tracking::Scope) -> Result { + fn seed(&mut self, rid: Id, scope: policy::Scope) -> Result { let mut line = self.call::(Command::Seed { rid, scope }, DEFAULT_TIMEOUT)?; let response = line.next().ok_or(Error::EmptyResponse)??; diff --git a/radicle/src/node/config.rs b/radicle/src/node/config.rs index 213297a9..350d989e 100644 --- a/radicle/src/node/config.rs +++ b/radicle/src/node/config.rs @@ -6,7 +6,7 @@ use cyphernet::addr::PeerAddr; use localtime::LocalDuration; use crate::node; -use crate::node::tracking::{Policy, Scope}; +use crate::node::policy::{Policy, Scope}; use crate::node::{Address, Alias, NodeId}; /// Target number of peers to maintain connections to. diff --git a/radicle/src/node/tracking.rs b/radicle/src/node/policy.rs similarity index 98% rename from radicle/src/node/tracking.rs rename to radicle/src/node/policy.rs index b81ac9de..f1d6bcf6 100644 --- a/radicle/src/node/tracking.rs +++ b/radicle/src/node/policy.rs @@ -11,6 +11,7 @@ use crate::prelude::Id; pub use super::{Alias, NodeId}; +/// Repository seeding policy. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Repo { pub id: Id, @@ -18,6 +19,7 @@ pub struct Repo { pub policy: Policy, } +/// Node following policy. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Node { pub id: NodeId, diff --git a/radicle/src/node/tracking/config.rs b/radicle/src/node/policy/config.rs similarity index 96% rename from radicle/src/node/tracking/config.rs rename to radicle/src/node/policy/config.rs index 04165f70..7e8cf6ee 100644 --- a/radicle/src/node/tracking/config.rs +++ b/radicle/src/node/policy/config.rs @@ -9,10 +9,10 @@ use crate::crypto::PublicKey; use crate::prelude::{Id, NodeId}; use crate::storage::{Namespaces, ReadRepository as _, ReadStorage, RepositoryError}; -pub use crate::node::tracking::store; -pub use crate::node::tracking::store::Config as Store; -pub use crate::node::tracking::store::Error; -pub use crate::node::tracking::{Alias, Node, Policy, Repo, Scope}; +pub use crate::node::policy::store; +pub use crate::node::policy::store::Config as Store; +pub use crate::node::policy::store::Error; +pub use crate::node::policy::{Alias, Node, Policy, Repo, Scope}; #[derive(Debug, Error)] pub enum NamespacesError { diff --git a/radicle/src/node/tracking/schema.sql b/radicle/src/node/policy/schema.sql similarity index 96% rename from radicle/src/node/tracking/schema.sql rename to radicle/src/node/policy/schema.sql index 6a2bf3f6..72d5ed04 100644 --- a/radicle/src/node/tracking/schema.sql +++ b/radicle/src/node/policy/schema.sql @@ -1,5 +1,5 @@ -- --- Service configuration schema. +-- Node policy database. -- -- Node follow policies. diff --git a/radicle/src/node/tracking/store.rs b/radicle/src/node/policy/store.rs similarity index 100% rename from radicle/src/node/tracking/store.rs rename to radicle/src/node/policy/store.rs diff --git a/radicle/src/profile.rs b/radicle/src/profile.rs index 73b81454..ce920c19 100644 --- a/radicle/src/profile.rs +++ b/radicle/src/profile.rs @@ -20,7 +20,7 @@ use thiserror::Error; use crate::crypto::ssh::agent::Agent; use crate::crypto::ssh::{keystore, Keystore, Passphrase}; use crate::crypto::{PublicKey, Signer}; -use crate::node::{tracking, Alias, AliasStore}; +use crate::node::{policy, Alias, AliasStore}; use crate::prelude::Did; use crate::prelude::{Id, NodeId}; use crate::storage::git::transport; @@ -146,7 +146,7 @@ pub enum Error { #[error("profile key `{0}` is not registered with ssh-agent")] KeyNotRegistered(PublicKey), #[error(transparent)] - TrackingStore(#[from] node::tracking::store::Error), + TrackingStore(#[from] node::policy::store::Error), #[error(transparent)] DatabaseStore(#[from] node::db::Error), } @@ -342,17 +342,17 @@ impl Profile { } /// Return a read-only handle to the tracking configuration of the node. - pub fn tracking(&self) -> Result { + pub fn tracking(&self) -> Result { let path = self.home.node().join(node::TRACKING_DB_FILE); - let config = tracking::store::Config::reader(path)?; + let config = policy::store::Config::reader(path)?; Ok(config) } /// Return a read-write handle to the tracking configuration of the node. - pub fn tracking_mut(&self) -> Result { + pub fn tracking_mut(&self) -> Result { let path = self.home.node().join(node::TRACKING_DB_FILE); - let config = tracking::store::Config::open(path)?; + let config = policy::store::Config::open(path)?; Ok(config) } @@ -388,7 +388,7 @@ impl std::ops::DerefMut for Profile { /// Holds multiple alias stores, and will try /// them one by one when asking for an alias. pub struct Aliases { - tracking: Option, + tracking: Option, db: Option, } @@ -488,17 +488,17 @@ impl Home { } /// Return a read-only handle to the tracking configuration of the node. - pub fn tracking(&self) -> Result { + pub fn tracking(&self) -> Result { let path = self.node().join(node::TRACKING_DB_FILE); - let config = tracking::store::Config::reader(path)?; + let config = policy::store::Config::reader(path)?; Ok(config) } /// Return a read-write handle to the tracking configuration of the node. - pub fn tracking_mut(&self) -> Result { + pub fn tracking_mut(&self) -> Result { let path = self.node().join(node::TRACKING_DB_FILE); - let config = tracking::store::Config::open(path)?; + let config = policy::store::Config::open(path)?; Ok(config) }