Use `Profile` in client
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
51e18c27fc
commit
116eaa79e6
|
|
@ -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<R: Reactor, G: Signer> {
|
||||
pub struct Client<R: Reactor> {
|
||||
reactor: R,
|
||||
storage: Storage,
|
||||
signer: G,
|
||||
profile: Profile,
|
||||
|
||||
handle: chan::Sender<service::Command>,
|
||||
commands: chan::Receiver<service::Command>,
|
||||
|
|
@ -57,18 +54,16 @@ pub struct Client<R: Reactor, G: Signer> {
|
|||
events: Events,
|
||||
}
|
||||
|
||||
impl<R: Reactor, G: Signer> Client<R, G> {
|
||||
pub fn new<P: AsRef<Path>>(path: P, signer: G) -> Result<Self, nakamoto_net::error::Error> {
|
||||
impl<R: Reactor> Client<R> {
|
||||
pub fn new(profile: Profile) -> Result<Self, nakamoto_net::error::Error> {
|
||||
let (handle, commands) = chan::unbounded::<service::Command>();
|
||||
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<R: Reactor, G: Signer> Client<R, G> {
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<net::TcpStream>;
|
||||
|
||||
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::<Reactor, _>::new(Path::new("."), signer)?;
|
||||
let profile = radicle::Profile::load()?;
|
||||
let client = client::Client::<Reactor>::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());
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue