Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Get the node running
Alexis Sellier committed 3 years ago
commit 706fbc655087c504e101c3801f8937e90ac46b9e
parent 961c18319ff9625258655316b23983ee6016db72
3 files changed +21 -7
modified radicle-node/src/control.rs
@@ -4,7 +4,7 @@ use std::io::BufReader;
use std::io::LineWriter;
use std::os::unix::net::UnixListener;
use std::os::unix::net::UnixStream;
-
use std::path::Path;
+
use std::path::{Path, PathBuf};
use std::{fs, io, net};

use crate::client;
@@ -17,12 +17,22 @@ use crate::service::FetchResult;
pub enum Error {
    #[error("failed to bind control socket listener: {0}")]
    Bind(io::Error),
+
    #[error("invalid socket path specified: {0}")]
+
    InvalidPath(PathBuf),
}

/// Listen for commands on the control socket, and process them.
pub fn listen<P: AsRef<Path>, H: Handle>(path: P, handle: H) -> Result<(), Error> {
    // Remove the socket file on startup before rebinding.
    fs::remove_file(&path).ok();
+
    fs::create_dir_all(
+
        path.as_ref()
+
            .parent()
+
            .ok_or_else(|| Error::InvalidPath(path.as_ref().to_path_buf()))?,
+
    )
+
    .ok();
+

+
    log::info!("Binding control socket {}..", path.as_ref().display());

    let listener = UnixListener::bind(path).map_err(Error::Bind)?;
    for incoming in listener.incoming() {
modified radicle-node/src/main.rs
@@ -1,7 +1,9 @@
use std::thread;
-
use std::{env, net, process};
+
use std::{net, process};

-
use radicle_node::node;
+
use anyhow::Context as _;
+

+
use radicle_node::logger;
use radicle_node::prelude::Address;
use radicle_node::{client, control, git, service};

@@ -53,9 +55,12 @@ impl Options {
}

fn main() -> anyhow::Result<()> {
+
    logger::init(log::Level::Debug)?;
+

    let options = Options::from_env()?;
-
    let profile = radicle::Profile::load()?;
-
    let client = client::Client::<Reactor>::new(profile)?;
+
    let profile = radicle::Profile::load().context("Failed to load node profile")?;
+
    let socket = profile.socket();
+
    let client = client::Client::<Reactor>::new(profile).context("Failed to initialize client")?;
    let handle = client.handle();
    let config = client::Config {
        service: service::Config {
@@ -65,7 +70,6 @@ fn main() -> anyhow::Result<()> {
        },
        listen: options.listen,
    };
-
    let socket = env::var("RAD_SOCKET").unwrap_or_else(|_| node::DEFAULT_SOCKET_NAME.to_owned());

    let t1 = thread::spawn(move || control::listen(socket, handle));
    let t2 = thread::spawn(move || client.run(config));
modified radicle/src/profile.rs
@@ -84,7 +84,7 @@ impl Profile {
    }

    /// Get the path to the radicle node socket.
-
    fn socket(&self) -> PathBuf {
+
    pub fn socket(&self) -> PathBuf {
        env::var_os("RAD_SOCKET")
            .map(PathBuf::from)
            .unwrap_or_else(|| self.home.join("node").join(node::DEFAULT_SOCKET_NAME))