mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-16 00:00:37 +08:00
cli: Consolidate policy/scope variants
* Policy::Track -> Policy::Allow * Scope::Trusted -> Scope::Followed
This commit is contained in:
+10
-10
@@ -425,7 +425,7 @@ where
|
||||
self.filter = Filter::new(
|
||||
self.tracking
|
||||
.repo_policies()?
|
||||
.filter_map(|t| (t.policy == tracking::Policy::Track).then_some(t.id)),
|
||||
.filter_map(|t| (t.policy == tracking::Policy::Allow).then_some(t.id)),
|
||||
);
|
||||
Ok(updated)
|
||||
}
|
||||
@@ -570,7 +570,7 @@ where
|
||||
self.filter = Filter::new(
|
||||
self.tracking
|
||||
.repo_policies()?
|
||||
.filter_map(|t| (t.policy == tracking::Policy::Track).then_some(t.id)),
|
||||
.filter_map(|t| (t.policy == tracking::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::Track {
|
||||
if repo_entry.policy == tracking::Policy::Allow {
|
||||
let (fresh, stale) = match self.refs_status_of(message, &repo_entry.scope) {
|
||||
Ok(RefsStatus { fresh, stale }) => (fresh, stale),
|
||||
Err(e) => {
|
||||
@@ -1424,13 +1424,13 @@ where
|
||||
// Second, check the scope.
|
||||
match scope {
|
||||
tracking::Scope::All => Ok(refs),
|
||||
tracking::Scope::Trusted => {
|
||||
tracking::Scope::Followed => {
|
||||
match self.tracking.namespaces_for(&self.storage, &message.rid) {
|
||||
Ok(Namespaces::All) => Ok(refs),
|
||||
Ok(Namespaces::Trusted(mut trusted)) => {
|
||||
// Get the set of trusted nodes except self.
|
||||
trusted.remove(self.nid());
|
||||
refs.fresh.retain(|r| trusted.contains(&r.remote));
|
||||
Ok(Namespaces::Followed(mut followed)) => {
|
||||
// Get the set of followed nodes except self.
|
||||
followed.remove(self.nid());
|
||||
refs.fresh.retain(|r| followed.contains(&r.remote));
|
||||
|
||||
Ok(refs)
|
||||
}
|
||||
@@ -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::Track {
|
||||
if self.config.policy == tracking::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::Track).then_some(t.id))
|
||||
.filter_map(|t| (t.policy == tracking::Policy::Allow).then_some(t.id))
|
||||
.filter(|rid| !inventory.contains(rid));
|
||||
|
||||
for rid in missing {
|
||||
|
||||
@@ -420,7 +420,7 @@ impl<G: cyphernet::Ecdh<Pk = NodeId> + Signer + Clone> Node<G> {
|
||||
|
||||
assert!(self
|
||||
.tracking
|
||||
.track_repo(&id, node::tracking::Scope::Trusted)
|
||||
.track_repo(&id, node::tracking::Scope::Followed)
|
||||
.unwrap());
|
||||
|
||||
log::debug!(
|
||||
|
||||
@@ -172,7 +172,7 @@ where
|
||||
config.config.external_addresses.push(local_addr.into());
|
||||
|
||||
for rid in storage.inventory().unwrap() {
|
||||
tracking.track_repo(&rid, Scope::Trusted).unwrap();
|
||||
tracking.track_repo(&rid, Scope::Followed).unwrap();
|
||||
}
|
||||
let announcement = service::gossip::node(&config.config, config.local_time.as_secs());
|
||||
let emitter: Emitter<Event> = Default::default();
|
||||
|
||||
@@ -422,7 +422,7 @@ impl<S: WriteStorage + 'static, G: Signer> Simulation<S, G> {
|
||||
radicle::test::fetch(
|
||||
&repo,
|
||||
&nid,
|
||||
Namespaces::Trusted(namespaces.clone()),
|
||||
Namespaces::Followed(namespaces.clone()),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -655,7 +655,7 @@ impl<S: WriteStorage + 'static, G: Signer> Simulation<S, G> {
|
||||
Rc::new(Ok(fetch::FetchResult {
|
||||
updated: vec![],
|
||||
namespaces: match namespaces {
|
||||
Namespaces::Trusted(hs) => hs,
|
||||
Namespaces::Followed(hs) => hs,
|
||||
Namespaces::All => HashSet::new(),
|
||||
},
|
||||
})),
|
||||
|
||||
@@ -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::Trusted).unwrap();
|
||||
alice.track_repo(&rid, tracking::Scope::Followed).unwrap();
|
||||
alice.connect_to(&bob);
|
||||
|
||||
// Alice receives Bob's refs.
|
||||
@@ -755,11 +755,11 @@ fn test_refs_announcement_fetch_trusted_no_inventory() {
|
||||
/// Alice and Bob both have the same repo.
|
||||
///
|
||||
/// First, Alice will not fetch from Bob's `RefsAnnouncement` as Alice does not
|
||||
/// track Bob as `Trusted`.
|
||||
/// track Bob as `Followed`.
|
||||
///
|
||||
/// Later Alice tracks Bob, and will be able to fetch Bob's refs.
|
||||
/// Later Alice follows Bob, and will be able to fetch Bob's refs.
|
||||
#[test]
|
||||
fn test_refs_announcement_trusted() {
|
||||
fn test_refs_announcement_followed() {
|
||||
logger::init(log::Level::Debug);
|
||||
|
||||
// Create MockStorage for Alice and Bob. Both will have repo with `rid`.
|
||||
@@ -796,9 +796,9 @@ fn test_refs_announcement_trusted() {
|
||||
},
|
||||
);
|
||||
|
||||
// Alice uses Scope::Trusted, and did not track Bob yet.
|
||||
// Alice uses Scope::Followed, and did not track Bob yet.
|
||||
alice.connect_to(&bob);
|
||||
alice.track_repo(&rid, tracking::Scope::Trusted).unwrap();
|
||||
alice.track_repo(&rid, tracking::Scope::Followed).unwrap();
|
||||
|
||||
// Alice receives Bob's refs
|
||||
alice.receive(bob.id(), bob.refs_announcement(rid));
|
||||
@@ -1538,14 +1538,14 @@ fn test_push_and_pull() {
|
||||
assert!(eve.get(proj_id).unwrap().is_none());
|
||||
assert!(bob.get(proj_id).unwrap().is_none());
|
||||
|
||||
// Bob tracks Alice's project.
|
||||
// Bob seeds Alice's project.
|
||||
let (sender, _) = chan::bounded(1);
|
||||
bob.command(service::Command::TrackRepo(
|
||||
proj_id,
|
||||
tracking::Scope::default(),
|
||||
sender,
|
||||
));
|
||||
// Eve tracks Alice's project.
|
||||
// Eve seeds Alice's project.
|
||||
let (sender, _) = chan::bounded(1);
|
||||
eve.command(service::Command::TrackRepo(
|
||||
proj_id,
|
||||
|
||||
@@ -284,7 +284,7 @@ fn test_replication_invalid() {
|
||||
converge([&alice, &bob]);
|
||||
|
||||
alice.handle.track_node(*carol.public_key(), None).unwrap();
|
||||
alice.handle.track_repo(acme, Scope::Trusted).unwrap();
|
||||
alice.handle.track_repo(acme, Scope::Followed).unwrap();
|
||||
let result = alice.handle.fetch(acme, bob.id, DEFAULT_TIMEOUT).unwrap();
|
||||
|
||||
// Fetch is successful despite not fetching Carol's refs, since she isn't a delegate.
|
||||
@@ -367,7 +367,7 @@ fn test_dont_fetch_owned_refs() {
|
||||
alice.connect(&bob);
|
||||
converge([&alice, &bob]);
|
||||
|
||||
assert!(bob.handle.track_repo(acme, Scope::Trusted).unwrap());
|
||||
assert!(bob.handle.track_repo(acme, Scope::Followed).unwrap());
|
||||
|
||||
let result = bob.handle.fetch(acme, alice.id, DEFAULT_TIMEOUT).unwrap();
|
||||
assert!(result.is_success());
|
||||
@@ -380,7 +380,7 @@ fn test_dont_fetch_owned_refs() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fetch_trusted_remotes() {
|
||||
fn test_fetch_followed_remotes() {
|
||||
logger::init(log::Level::Debug);
|
||||
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
@@ -402,18 +402,18 @@ fn test_fetch_trusted_remotes() {
|
||||
alice.connect(&bob);
|
||||
converge([&alice, &bob]);
|
||||
|
||||
let trusted = signers
|
||||
let followed = signers
|
||||
.iter()
|
||||
.map(|s| *s.public_key())
|
||||
.take(2)
|
||||
.collect::<HashSet<_>>();
|
||||
|
||||
assert!(
|
||||
trusted.len() < signers.len(),
|
||||
followed.len() < signers.len(),
|
||||
"Bob is only trusting a subset of peers"
|
||||
);
|
||||
assert!(bob.handle.track_repo(acme, Scope::Trusted).unwrap());
|
||||
for nid in &trusted {
|
||||
assert!(bob.handle.track_repo(acme, Scope::Followed).unwrap());
|
||||
for nid in &followed {
|
||||
assert!(bob.handle.track_node(*nid, None).unwrap());
|
||||
}
|
||||
|
||||
@@ -429,8 +429,8 @@ fn test_fetch_trusted_remotes() {
|
||||
.collect::<Result<HashSet<_>, _>>()
|
||||
.unwrap();
|
||||
|
||||
assert!(bob_remotes.len() == trusted.len() + 1);
|
||||
assert!(bob_remotes.is_superset(&trusted));
|
||||
assert!(bob_remotes.len() == followed.len() + 1);
|
||||
assert!(bob_remotes.is_superset(&followed));
|
||||
assert!(bob_remotes.contains(&alice.id));
|
||||
}
|
||||
|
||||
@@ -450,7 +450,7 @@ fn test_missing_remote() {
|
||||
alice.connect(&bob);
|
||||
converge([&alice, &bob]);
|
||||
|
||||
assert!(bob.handle.track_repo(acme, Scope::Trusted).unwrap());
|
||||
assert!(bob.handle.track_repo(acme, Scope::Followed).unwrap());
|
||||
assert!(bob.handle.track_node(*carol.public_key(), None).unwrap());
|
||||
let result = bob.handle.fetch(acme, alice.id, DEFAULT_TIMEOUT).unwrap();
|
||||
assert!(result.is_success());
|
||||
@@ -477,7 +477,7 @@ fn test_fetch_preserve_owned_refs() {
|
||||
alice.connect(&bob);
|
||||
converge([&alice, &bob]);
|
||||
|
||||
assert!(bob.handle.track_repo(acme, Scope::Trusted).unwrap());
|
||||
assert!(bob.handle.track_repo(acme, Scope::Followed).unwrap());
|
||||
assert!(bob.handle.track_node(alice.id, None).unwrap());
|
||||
|
||||
let result = bob.handle.fetch(acme, alice.id, DEFAULT_TIMEOUT).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user