node: Rename "user"

In some cases to "public key" and in other cases to "remote".

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier 2022-09-07 13:57:50 +02:00
parent 4e9b60dee0
commit 46ee08aaf3
No known key found for this signature in database
6 changed files with 34 additions and 30 deletions

View File

@ -431,7 +431,7 @@ where
resp.send(self.untrack(proj)).ok(); resp.send(self.untrack(proj)).ok();
} }
Command::AnnounceRefsUpdate(proj) => { Command::AnnounceRefsUpdate(proj) => {
let user = *self.storage.user_id(); let user = *self.storage.public_key();
let repo = self.storage.repository(&proj).unwrap(); let repo = self.storage.repository(&proj).unwrap();
let remote = repo.remote(&user).unwrap(); let remote = repo.remote(&user).unwrap();
let peers = self.peers.negotiated().map(|(_, p)| p.addr); let peers = self.peers.negotiated().map(|(_, p)| p.addr);

View File

@ -40,11 +40,11 @@ pub fn init<'r, S: storage::WriteStorage<'r>>(
default_branch: BranchName, default_branch: BranchName,
storage: S, storage: S,
) -> Result<(ProjId, SignedRefs<Verified>), InitError> { ) -> Result<(ProjId, SignedRefs<Verified>), InitError> {
let user_id = storage.user_id(); let pk = storage.public_key();
let delegate = identity::Delegate { let delegate = identity::Delegate {
// TODO: Use actual user name. // TODO: Use actual user name.
name: String::from("anonymous"), name: String::from("anonymous"),
id: identity::Did::from(*user_id), id: identity::Did::from(*pk),
}; };
let doc = identity::Doc { let doc = identity::Doc {
name: name.to_owned(), name: name.to_owned(),
@ -81,24 +81,24 @@ pub fn init<'r, S: storage::WriteStorage<'r>>(
}?; }?;
let sig = repo let sig = repo
.signature() .signature()
.or_else(|_| git2::Signature::now("radicle", user_id.to_string().as_str()))?; .or_else(|_| git2::Signature::now("radicle", pk.to_string().as_str()))?;
let id_ref = format!("refs/remotes/{user_id}/{}", &*RADICLE_ID_REF); let id_ref = format!("refs/remotes/{pk}/{}", &*RADICLE_ID_REF);
let _oid = repo.commit(Some(&id_ref), &sig, &sig, "Initialize Radicle", &tree, &[])?; let _oid = repo.commit(Some(&id_ref), &sig, &sig, "Initialize Radicle", &tree, &[])?;
} }
git::set_upstream( git::set_upstream(
repo, repo,
REMOTE_NAME, REMOTE_NAME,
&default_branch, &default_branch,
&format!("refs/remotes/{user_id}/heads/{default_branch}"), &format!("refs/remotes/{pk}/heads/{default_branch}"),
)?; )?;
// TODO: Note that you'll likely want to use `RemoteCallbacks` and set // TODO: Note that you'll likely want to use `RemoteCallbacks` and set
// `push_update_reference` to test whether all the references were pushed // `push_update_reference` to test whether all the references were pushed
// successfully. // successfully.
git::configure_remote(repo, REMOTE_NAME, user_id, project.path())?.push::<&str>( git::configure_remote(repo, REMOTE_NAME, pk, project.path())?.push::<&str>(
&[&format!( &[&format!(
"refs/heads/{default_branch}:refs/remotes/{user_id}/heads/{default_branch}" "refs/heads/{default_branch}:refs/remotes/{pk}/heads/{default_branch}"
)], )],
None, None,
)?; )?;
@ -132,7 +132,7 @@ pub fn checkout<P: AsRef<Path>, S: storage::ReadStorage>(
opts.no_reinit(true).description(&project.doc.description); opts.no_reinit(true).description(&project.doc.description);
let repo = git2::Repository::init_opts(path, &opts)?; let repo = git2::Repository::init_opts(path, &opts)?;
let remote_id = storage.user_id(); let remote_id = storage.public_key();
let default_branch = project.doc.default_branch.as_str(); let default_branch = project.doc.default_branch.as_str();
// Configure and fetch all refs from remote. // Configure and fetch all refs from remote.
@ -184,7 +184,7 @@ mod tests {
let project = storage.get(&id).unwrap().unwrap(); let project = storage.get(&id).unwrap().unwrap();
assert_eq!(project.remotes[storage.user_id()].refs, refs); assert_eq!(project.remotes[storage.public_key()].refs, refs);
assert_eq!(project.id, id); assert_eq!(project.id, id);
assert_eq!(project.doc.name, "acme"); assert_eq!(project.doc.name, "acme");
assert_eq!(project.doc.description, "Acme's repo"); assert_eq!(project.doc.description, "Acme's repo");
@ -193,7 +193,7 @@ mod tests {
project.doc.delegates.first(), project.doc.delegates.first(),
&Delegate { &Delegate {
name: String::from("anonymous"), name: String::from("anonymous"),
id: Did::from(*storage.user_id()), id: Did::from(*storage.public_key()),
} }
); );
} }

View File

@ -14,7 +14,7 @@ use thiserror::Error;
pub use radicle_git_ext::Oid; pub use radicle_git_ext::Oid;
use crate::collections::HashMap; use crate::collections::HashMap;
use crate::crypto::{self, Unverified, Verified}; use crate::crypto::{self, PublicKey, Unverified, Verified};
use crate::git::Url; use crate::git::Url;
use crate::git::{RefError, RefStr}; use crate::git::{RefError, RefStr};
use crate::identity; use crate::identity;
@ -159,7 +159,7 @@ impl Remote<Verified> {
} }
pub trait ReadStorage { pub trait ReadStorage {
fn user_id(&self) -> &UserId; fn public_key(&self) -> &PublicKey;
fn url(&self) -> Url; fn url(&self) -> Url;
fn get(&self, proj: &ProjId) -> Result<Option<Project>, Error>; fn get(&self, proj: &ProjId) -> Result<Option<Project>, Error>;
fn inventory(&self) -> Result<Inventory, Error>; fn inventory(&self) -> Result<Inventory, Error>;
@ -180,12 +180,16 @@ pub trait ReadRepository<'r> {
fn blob_at<'a>(&'a self, oid: Oid, path: &'a Path) -> Result<git2::Blob<'a>, git_ext::Error>; fn blob_at<'a>(&'a self, oid: Oid, path: &'a Path) -> Result<git2::Blob<'a>, git_ext::Error>;
fn reference( fn reference(
&self, &self,
user: &UserId, remote: &RemoteId,
reference: &RefStr, reference: &RefStr,
) -> Result<Option<git2::Reference>, git2::Error>; ) -> Result<Option<git2::Reference>, git2::Error>;
fn reference_oid(&self, user: &UserId, reference: &RefStr) -> Result<Option<Oid>, git2::Error>; fn reference_oid(
fn references(&self, user: &UserId) -> Result<Refs, Error>; &self,
fn remote(&self, user: &UserId) -> Result<Remote<Verified>, refs::Error>; remote: &RemoteId,
reference: &RefStr,
) -> Result<Option<Oid>, git2::Error>;
fn references(&self, remote: &RemoteId) -> Result<Refs, Error>;
fn remote(&self, remote: &RemoteId) -> Result<Remote<Verified>, refs::Error>;
fn remotes(&'r self) -> Result<Self::Remotes, git2::Error>; fn remotes(&'r self) -> Result<Self::Remotes, git2::Error>;
} }
@ -199,8 +203,8 @@ where
T: Deref<Target = S>, T: Deref<Target = S>,
S: ReadStorage + 'static, S: ReadStorage + 'static,
{ {
fn user_id(&self) -> &UserId { fn public_key(&self) -> &UserId {
self.deref().user_id() self.deref().public_key()
} }
fn url(&self) -> Url { fn url(&self) -> Url {

View File

@ -38,7 +38,7 @@ impl fmt::Debug for Storage {
} }
impl ReadStorage for Storage { impl ReadStorage for Storage {
fn user_id(&self) -> &UserId { fn public_key(&self) -> &UserId {
self.signer.public_key() self.signer.public_key()
} }
@ -53,7 +53,7 @@ impl ReadStorage for Storage {
fn get(&self, id: &ProjId) -> Result<Option<Project>, Error> { fn get(&self, id: &ProjId) -> Result<Option<Project>, Error> {
// TODO: Don't create a repo here if it doesn't exist? // TODO: Don't create a repo here if it doesn't exist?
// Perhaps for checking we could have a `contains` method? // Perhaps for checking we could have a `contains` method?
let local = self.user_id(); let local = self.public_key();
let repo = self.repository(id)?; let repo = self.repository(id)?;
if let Some(doc) = repo.identity(local)? { if let Some(doc) = repo.identity(local)? {
@ -424,7 +424,7 @@ mod tests {
let signer = MockSigner::new(&mut rng); let signer = MockSigner::new(&mut rng);
let storage = Storage::open(tmp.path(), signer).unwrap(); let storage = Storage::open(tmp.path(), signer).unwrap();
let proj_id = arbitrary::gen::<ProjId>(1); let proj_id = arbitrary::gen::<ProjId>(1);
let alice = *storage.user_id(); let alice = *storage.public_key();
let project = storage.repository(&proj_id).unwrap(); let project = storage.repository(&proj_id).unwrap();
let backend = &project.backend; let backend = &project.backend;
let sig = git2::Signature::now(&alice.to_string(), "anonymous@radicle.xyz").unwrap(); let sig = git2::Signature::now(&alice.to_string(), "anonymous@radicle.xyz").unwrap();

View File

@ -19,7 +19,7 @@ pub fn storage<P: AsRef<Path>>(path: P) -> Storage {
crate::test::logger::init(log::Level::Debug); crate::test::logger::init(log::Level::Debug);
for storage in &storages { for storage in &storages {
let remote = storage.user_id(); let remote = storage.public_key();
log::debug!("signer {}...", remote); log::debug!("signer {}...", remote);

View File

@ -1,8 +1,8 @@
use git_url::Url; use git_url::Url;
use crate::crypto::Verified; use crate::crypto::{PublicKey, Verified};
use crate::git; use crate::git;
use crate::identity::{ProjId, Project, UserId}; use crate::identity::{ProjId, Project};
use crate::storage::refs; use crate::storage::refs;
use crate::storage::{ use crate::storage::{
Error, Inventory, ReadRepository, ReadStorage, Remote, RemoteId, WriteRepository, WriteStorage, Error, Inventory, ReadRepository, ReadStorage, Remote, RemoteId, WriteRepository, WriteStorage,
@ -26,7 +26,7 @@ impl MockStorage {
} }
impl ReadStorage for MockStorage { impl ReadStorage for MockStorage {
fn user_id(&self) -> &UserId { fn public_key(&self) -> &PublicKey {
todo!() todo!()
} }
@ -84,7 +84,7 @@ impl ReadRepository<'_> for MockRepository {
todo!() todo!()
} }
fn remote(&self, _user: &UserId) -> Result<Remote<Verified>, refs::Error> { fn remote(&self, _remote: &RemoteId) -> Result<Remote<Verified>, refs::Error> {
todo!() todo!()
} }
@ -102,7 +102,7 @@ impl ReadRepository<'_> for MockRepository {
fn reference( fn reference(
&self, &self,
_user: &UserId, _remote: &RemoteId,
_reference: &git::RefStr, _reference: &git::RefStr,
) -> Result<Option<git2::Reference>, git2::Error> { ) -> Result<Option<git2::Reference>, git2::Error> {
todo!() todo!()
@ -110,13 +110,13 @@ impl ReadRepository<'_> for MockRepository {
fn reference_oid( fn reference_oid(
&self, &self,
_user: &UserId, _remote: &RemoteId,
_reference: &git::RefStr, _reference: &git::RefStr,
) -> Result<Option<radicle_git_ext::Oid>, git2::Error> { ) -> Result<Option<radicle_git_ext::Oid>, git2::Error> {
todo!() todo!()
} }
fn references(&self, _user: &UserId) -> Result<crate::storage::refs::Refs, Error> { fn references(&self, _remote: &RemoteId) -> Result<crate::storage::refs::Refs, Error> {
todo!() todo!()
} }
} }