node: remove Namespaces::One
The One variant caused many paint points for fetching logic, where it was not necessary. It was only constructed in one place, which could be replaced by using the variant that holds a set of keys. Remove the Namespaces::One variant and rename Namespaces::Many to Namespaces::Trusted. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
adf6312a55
commit
c618c3e443
|
|
@ -516,7 +516,7 @@ where
|
||||||
resp.send(untracked).ok();
|
resp.send(untracked).ok();
|
||||||
}
|
}
|
||||||
Command::AnnounceRefs(id) => {
|
Command::AnnounceRefs(id) => {
|
||||||
if let Err(err) = self.announce_refs(id, &Namespaces::One(self.node_id())) {
|
if let Err(err) = self.announce_refs(id, &Namespaces::from_iter([self.node_id()])) {
|
||||||
error!("Error announcing refs: {}", err);
|
error!("Error announcing refs: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1004,7 +1004,7 @@ where
|
||||||
tracking::Scope::Trusted => {
|
tracking::Scope::Trusted => {
|
||||||
match self.tracking.namespaces_for(&self.storage, &message.rid) {
|
match self.tracking.namespaces_for(&self.storage, &message.rid) {
|
||||||
Ok(Namespaces::All) => Ok(true),
|
Ok(Namespaces::All) => Ok(true),
|
||||||
Ok(Namespaces::Many(mut trusted)) => {
|
Ok(Namespaces::Trusted(mut trusted)) => {
|
||||||
// Get the set of trusted nodes except self.
|
// Get the set of trusted nodes except self.
|
||||||
trusted.remove(&self.node_id());
|
trusted.remove(&self.node_id());
|
||||||
|
|
||||||
|
|
@ -1014,9 +1014,6 @@ where
|
||||||
.iter()
|
.iter()
|
||||||
.any(|(pub_key, _refs)| trusted.contains(pub_key)))
|
.any(|(pub_key, _refs)| trusted.contains(pub_key)))
|
||||||
}
|
}
|
||||||
Ok(Namespaces::One(key)) => {
|
|
||||||
Ok(message.refs.iter().any(|(pub_key, _refs)| pub_key == &key))
|
|
||||||
}
|
|
||||||
Err(NamespacesError::NoTrusted { rid }) => {
|
Err(NamespacesError::NoTrusted { rid }) => {
|
||||||
debug!(target: "service", "No trusted nodes to fetch {}", &rid);
|
debug!(target: "service", "No trusted nodes to fetch {}", &rid);
|
||||||
Ok(false)
|
Ok(false)
|
||||||
|
|
@ -1272,12 +1269,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Namespaces::One(pk) => refs
|
Namespaces::Trusted(trusted) => {
|
||||||
.push((*pk, repo.remote(pk)?.refs.unverified()))
|
|
||||||
// SAFETY: `REF_REMOTE_LIMIT` is greater than 1, thus the bounded vec can hold at least
|
|
||||||
// one remote.
|
|
||||||
.unwrap(),
|
|
||||||
Namespaces::Many(trusted) => {
|
|
||||||
for remote_id in trusted.iter() {
|
for remote_id in trusted.iter() {
|
||||||
if refs
|
if refs
|
||||||
.push((*remote_id, repo.remote(remote_id)?.refs.unverified()))
|
.push((*remote_id, repo.remote(remote_id)?.refs.unverified()))
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ impl Config {
|
||||||
// trusted and delegate remotes.
|
// trusted and delegate remotes.
|
||||||
Ok(Namespaces::All)
|
Ok(Namespaces::All)
|
||||||
} else {
|
} else {
|
||||||
Ok(Namespaces::Many(trusted))
|
Ok(Namespaces::Trusted(trusted))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -670,8 +670,7 @@ fn fetch<W: WriteRepository>(
|
||||||
) -> Result<Vec<RefUpdate>, radicle::storage::FetchError> {
|
) -> Result<Vec<RefUpdate>, radicle::storage::FetchError> {
|
||||||
let namespace = match namespaces.into() {
|
let namespace = match namespaces.into() {
|
||||||
Namespaces::All => None,
|
Namespaces::All => None,
|
||||||
Namespaces::One(ns) => Some(ns),
|
Namespaces::Trusted(trusted) => trusted.into_iter().next(),
|
||||||
Namespaces::Many(trusted) => trusted.into_iter().next(),
|
|
||||||
};
|
};
|
||||||
let mut updates = Vec::new();
|
let mut updates = Vec::new();
|
||||||
let mut callbacks = git::RemoteCallbacks::new();
|
let mut callbacks = git::RemoteCallbacks::new();
|
||||||
|
|
|
||||||
|
|
@ -132,11 +132,7 @@ impl<'a> StagingPhaseInitial<'a> {
|
||||||
let doc = doc.verified()?;
|
let doc = doc.verified()?;
|
||||||
let mut trusted = match self.namespaces.clone() {
|
let mut trusted = match self.namespaces.clone() {
|
||||||
Namespaces::All => HashSet::new(),
|
Namespaces::All => HashSet::new(),
|
||||||
// TODO(finto): this is one of those cases where
|
Namespaces::Trusted(trusted) => trusted,
|
||||||
// having the `One` variant doesn't make any
|
|
||||||
// sense.
|
|
||||||
Namespaces::One(pk) => [pk].into_iter().collect(),
|
|
||||||
Namespaces::Many(trusted) => trusted,
|
|
||||||
};
|
};
|
||||||
let delegates = doc.delegates.map(PublicKey::from);
|
let delegates = doc.delegates.map(PublicKey::from);
|
||||||
trusted.extend(delegates);
|
trusted.extend(delegates);
|
||||||
|
|
@ -148,13 +144,13 @@ impl<'a> StagingPhaseInitial<'a> {
|
||||||
// Nb. Namespaces::One is not constructed in
|
// Nb. Namespaces::One is not constructed in
|
||||||
// namespaces_for so it's safe to just bundle this
|
// namespaces_for so it's safe to just bundle this
|
||||||
// with Namespaces::All
|
// with Namespaces::All
|
||||||
Namespaces::One(_) | Namespaces::All => {
|
Namespaces::All => {
|
||||||
let mut trusted = repo.remote_ids()?.collect::<Result<HashSet<_>, _>>()?;
|
let mut trusted = repo.remote_ids()?.collect::<Result<HashSet<_>, _>>()?;
|
||||||
trusted.extend(repo.delegates()?.map(PublicKey::from));
|
trusted.extend(repo.delegates()?.map(PublicKey::from));
|
||||||
trusted
|
trusted
|
||||||
}
|
}
|
||||||
|
|
||||||
Namespaces::Many(trusted) => trusted,
|
Namespaces::Trusted(trusted) => trusted,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -202,7 +198,7 @@ impl<'a> StagingPhaseFinal<'a> {
|
||||||
/// references.
|
/// references.
|
||||||
pub fn refspecs(&self) -> Vec<Refspec<git::PatternString, git::PatternString>> {
|
pub fn refspecs(&self) -> Vec<Refspec<git::PatternString, git::PatternString>> {
|
||||||
match self.repo {
|
match self.repo {
|
||||||
StagedRepository::Cloning(_) => Namespaces::Many(self.trusted.clone()).as_refspecs(),
|
StagedRepository::Cloning(_) => Namespaces::Trusted(self.trusted.clone()).as_refspecs(),
|
||||||
StagedRepository::Fetching(_) => {
|
StagedRepository::Fetching(_) => {
|
||||||
self.remotes().fold(Vec::new(), |mut specs, remote| {
|
self.remotes().fold(Vec::new(), |mut specs, remote| {
|
||||||
specs.extend(remote.as_refspecs());
|
specs.extend(remote.as_refspecs());
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,7 @@ impl AsRefspecs for SpecialRefs {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Namespaces::One(pk) => rad_refs(pk),
|
Namespaces::Trusted(pks) => pks.iter().flat_map(rad_refs).collect(),
|
||||||
Namespaces::Many(pks) => pks.iter().flat_map(rad_refs).collect(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,15 +105,7 @@ impl AsRefspecs for Namespaces {
|
||||||
dst: (*storage::git::NAMESPACES_GLOB).clone(),
|
dst: (*storage::git::NAMESPACES_GLOB).clone(),
|
||||||
force: false,
|
force: false,
|
||||||
}],
|
}],
|
||||||
Namespaces::One(pk) => {
|
Namespaces::Trusted(pks) => pks
|
||||||
let ns = pk.to_namespace().with_pattern(git::refspec::STAR);
|
|
||||||
vec![Refspec {
|
|
||||||
src: ns.clone(),
|
|
||||||
dst: ns,
|
|
||||||
force: false,
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
Namespaces::Many(pks) => pks
|
|
||||||
.iter()
|
.iter()
|
||||||
.map(|pk| {
|
.map(|pk| {
|
||||||
let ns = pk.to_namespace().with_pattern(git::refspec::STAR);
|
let ns = pk.to_namespace().with_pattern(git::refspec::STAR);
|
||||||
|
|
|
||||||
|
|
@ -34,15 +34,13 @@ pub enum Namespaces {
|
||||||
/// All namespaces.
|
/// All namespaces.
|
||||||
#[default]
|
#[default]
|
||||||
All,
|
All,
|
||||||
/// A single namespace, by public key.
|
/// The trusted set of namespaces.
|
||||||
One(PublicKey),
|
Trusted(HashSet<PublicKey>),
|
||||||
/// Many namespaces, by public keys.
|
|
||||||
Many(HashSet<PublicKey>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<PublicKey> for Namespaces {
|
impl FromIterator<PublicKey> for Namespaces {
|
||||||
fn from(pk: PublicKey) -> Self {
|
fn from_iter<T: IntoIterator<Item = PublicKey>>(iter: T) -> Self {
|
||||||
Self::One(pk)
|
Self::Trusted(iter.into_iter().collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue