From 116eaa79e6367e5790569e54324ad98ecde71963 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Fri, 23 Sep 2022 20:21:21 +0200 Subject: [PATCH] Use `Profile` in client Signed-off-by: Alexis Sellier --- radicle-node/src/client.rs | 21 ++++++++------------- radicle-node/src/lib.rs | 2 +- radicle-node/src/main.rs | 18 ++---------------- radicle/src/profile.rs | 2 ++ 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/radicle-node/src/client.rs b/radicle-node/src/client.rs index e3025440..753ef675 100644 --- a/radicle-node/src/client.rs +++ b/radicle-node/src/client.rs @@ -1,14 +1,12 @@ use std::net; -use std::path::Path; use crossbeam_channel as chan; use nakamoto_net::{LocalTime, Reactor}; use crate::clock::RefClock; use crate::collections::HashMap; -use crate::crypto::Signer; +use crate::profile::Profile; use crate::service; -use crate::storage::git::Storage; use crate::transport::Transport; use crate::wire::Wire; @@ -45,10 +43,9 @@ impl Default for Config { } } -pub struct Client { +pub struct Client { reactor: R, - storage: Storage, - signer: G, + profile: Profile, handle: chan::Sender, commands: chan::Receiver, @@ -57,18 +54,16 @@ pub struct Client { events: Events, } -impl Client { - pub fn new>(path: P, signer: G) -> Result { +impl Client { + pub fn new(profile: Profile) -> Result { let (handle, commands) = chan::unbounded::(); let (shutdown, shutdown_recv) = chan::bounded(1); let (listening_send, listening) = chan::bounded(1); let reactor = R::new(shutdown_recv, listening_send)?; - let storage = Storage::open(path)?; let events = Events {}; Ok(Self { - storage, - signer, + profile, reactor, handle, commands, @@ -82,8 +77,8 @@ impl Client { let network = config.service.network; let rng = fastrand::Rng::new(); let time = LocalTime::now(); - let storage = self.storage; - let signer = self.signer; + let storage = self.profile.storage; + let signer = self.profile.signer; let addresses = HashMap::with_hasher(rng.clone().into()); log::info!("Initializing client ({:?})..", network); diff --git a/radicle-node/src/lib.rs b/radicle-node/src/lib.rs index 1316e125..f0488a8a 100644 --- a/radicle-node/src/lib.rs +++ b/radicle-node/src/lib.rs @@ -13,7 +13,7 @@ pub mod transport; pub mod wire; pub use nakamoto_net::{Io, Link, LocalDuration, LocalTime}; -pub use radicle::{collections, crypto, git, hash, identity, rad, storage}; +pub use radicle::{collections, crypto, git, hash, identity, profile, rad, storage}; pub mod prelude { pub use crate::clock::Timestamp; diff --git a/radicle-node/src/main.rs b/radicle-node/src/main.rs index 08becf22..64797372 100644 --- a/radicle-node/src/main.rs +++ b/radicle-node/src/main.rs @@ -1,27 +1,13 @@ -use std::path::Path; use std::thread; use std::{env, net}; -use radicle_node::crypto::{PublicKey, Signature, Signer}; use radicle_node::{client, control}; type Reactor = nakamoto_net_poll::Reactor; -struct FailingSigner {} - -impl Signer for FailingSigner { - fn public_key(&self) -> &PublicKey { - panic!("Failing signer always fails!"); - } - - fn sign(&self, _msg: &[u8]) -> Signature { - panic!("Failing signer always fails!"); - } -} - fn main() -> anyhow::Result<()> { - let signer = FailingSigner {}; - let client = client::Client::::new(Path::new("."), signer)?; + let profile = radicle::Profile::load()?; + let client = client::Client::::new(profile)?; let handle = client.handle(); let config = client::Config::default(); let socket = env::var("RAD_SOCKET").unwrap_or_else(|_| control::DEFAULT_SOCKET_NAME.to_owned()); diff --git a/radicle/src/profile.rs b/radicle/src/profile.rs index edd2fa7e..94fa30d7 100644 --- a/radicle/src/profile.rs +++ b/radicle/src/profile.rs @@ -5,6 +5,7 @@ use crate::crypto::{KeyPair, PublicKey, SecretKey, Signature, Signer}; use crate::keystore::UnsafeKeystore; use crate::storage::git::Storage; +#[derive(Debug)] pub struct UnsafeSigner { public: PublicKey, secret: SecretKey, @@ -20,6 +21,7 @@ impl Signer for UnsafeSigner { } } +#[derive(Debug)] pub struct Profile { pub home: PathBuf, pub signer: UnsafeSigner,