node: Start control socket server

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier 2022-09-01 16:11:50 +02:00
parent fc30dc2668
commit 12dd6d4a5d
No known key found for this signature in database
6 changed files with 19 additions and 24 deletions

View File

@ -11,7 +11,6 @@ use crate::protocol;
use crate::storage::git::Storage;
pub mod handle;
pub mod socket;
/// Client configuration.
#[derive(Debug, Clone)]

View File

@ -1,3 +1,4 @@
//! Client control socket implementation.
use std::io::prelude::*;
use std::io::BufReader;
use std::os::unix::net::UnixListener;
@ -13,7 +14,7 @@ use crate::client::handle::Handle;
use crate::identity::ProjId;
/// Default name for control socket file.
pub const DEFAULT_NAME: &str = "radicle.sock";
pub const DEFAULT_SOCKET_NAME: &str = "radicle.sock";
#[derive(thiserror::Error, Debug)]
pub enum Error {

View File

@ -1,4 +1,3 @@
use std::rc::Rc;
use std::sync::Arc;
use std::{fmt, ops::Deref, str::FromStr};
@ -8,26 +7,13 @@ use thiserror::Error;
pub use ed25519::Signature;
pub trait Signer: 'static {
pub trait Signer: Send + Sync + 'static {
/// Return this signer's public/verification key.
fn public_key(&self) -> &PublicKey;
/// Sign a message and return the signature.
fn sign(&self, msg: &[u8]) -> Signature;
}
impl<T> Signer for Rc<T>
where
T: Signer + ?Sized,
{
fn sign(&self, msg: &[u8]) -> Signature {
self.deref().sign(msg)
}
fn public_key(&self) -> &PublicKey {
self.deref().public_key()
}
}
impl<T> Signer for Arc<T>
where
T: Signer + ?Sized,

View File

@ -2,6 +2,7 @@
pub use nakamoto_net::{Io, Link, LocalDuration, LocalTime};
pub mod client;
pub mod control;
pub mod crypto;
mod address_book;

View File

@ -1,8 +1,9 @@
use std::net;
use std::path::Path;
use std::thread;
use std::{env, net};
use radicle_node::client;
use radicle_node::crypto::{PublicKey, Signature, Signer};
use radicle_node::{client, control};
type Reactor = nakamoto_net_poll::Reactor<net::TcpStream>;
@ -21,8 +22,15 @@ impl Signer for FailingSigner {
fn main() -> anyhow::Result<()> {
let signer = FailingSigner {};
let client = client::Client::<Reactor>::new(Path::new("."), signer)?;
let handle = client.handle();
let config = client::Config::default();
let socket = env::var("RAD_SOCKET").unwrap_or_else(|_| control::DEFAULT_SOCKET_NAME.to_owned());
client.run(client::Config::default())?;
let t1 = thread::spawn(move || control::listen(socket, handle));
let t2 = thread::spawn(move || client.run(config));
t1.join().unwrap()?;
t2.join().unwrap()?;
Ok(())
}

View File

@ -1,5 +1,5 @@
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::Arc;
use std::{fmt, fs, io};
use git_ref_format::refspec;
@ -26,7 +26,7 @@ pub static NAMESPACES_GLOB: Lazy<refspec::PatternString> =
pub struct Storage {
path: PathBuf,
signer: Rc<dyn Signer>,
signer: Arc<dyn Signer>,
}
impl fmt::Debug for Storage {
@ -77,7 +77,7 @@ impl Storage {
Ok(Self {
path,
signer: Rc::new(signer),
signer: Arc::new(signer),
})
}
@ -85,7 +85,7 @@ impl Storage {
self.path.as_path()
}
pub fn signer(&self) -> Rc<dyn Signer> {
pub fn signer(&self) -> Arc<dyn Signer> {
self.signer.clone()
}