Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
node: Add `--alias` option to node
xphoniex committed 3 years ago
commit 35ce6663c15c84a9995bdbee82bad163a41c2a4b
parent 8da6363cb3ab523e367b852dfb259214bc91d0bf
2 files changed +20 -1
modified radicle-node/src/main.rs
@@ -21,6 +21,7 @@ Usage

Options

+
    --alias              <alias>        Identify yourself with an alias on the network
    --connect            <peer>         Connect to the given peer address on start
    --external-address   <address>      Publicly accessible address (default 0.0.0.0:8776)
    --git-daemon         <address>      Address to bind git-daemon to (default 0.0.0.0:9418)
@@ -33,6 +34,7 @@ Options

#[derive(Debug)]
struct Options {
+
    alias: Option<String>,
    connect: Vec<(NodeId, Address)>,
    external_addresses: Vec<Address>,
    daemon: Option<net::SocketAddr>,
@@ -48,6 +50,7 @@ impl Options {
        use lexopt::prelude::*;

        let mut parser = lexopt::Parser::from_env();
+
        let mut alias = None;
        let mut connect = Vec::new();
        let mut external_addresses = Vec::new();
        let mut limits = service::config::Limits::default();
@@ -59,6 +62,13 @@ impl Options {

        while let Some(arg) = parser.next()? {
            match arg {
+
                Long("alias") => {
+
                    let name: String = parser.value()?.parse()?;
+
                    if name.len() > 32 {
+
                        anyhow::bail!("alias '{}' is longer than 32 characters", name);
+
                    }
+
                    alias = Some(name);
+
                }
                Long("connect") => {
                    let peer: PeerAddr<NodeId, Address> = parser.value()?.parse()?;
                    connect.push((peer.id, peer.addr.clone()));
@@ -118,6 +128,7 @@ impl Options {
        }

        Ok(Self {
+
            alias,
            connect,
            daemon,
            external_addresses,
@@ -148,6 +159,7 @@ fn execute() -> anyhow::Result<()> {
    log::info!(target: "node", "Node ID is {}", signer.public_key());

    let config = service::Config {
+
        alias: options.alias,
        connect: options.connect.into_iter().collect(),
        external_addresses: options.external_addresses,
        limits: options.limits,
modified radicle-node/src/service/config.rs
@@ -37,6 +37,9 @@ impl Default for Limits {
/// Service configuration.
#[derive(Debug, Clone)]
pub struct Config {
+
    /// Alias chosen by the operator.
+
    /// Doesn't have to be unique on the network.
+
    pub alias: Option<String>,
    /// Peers to connect to on startup.
    /// Connections to these peers will be maintained.
    pub connect: Vec<(NodeId, Address)>,
@@ -57,6 +60,7 @@ pub struct Config {
impl Default for Config {
    fn default() -> Self {
        Self {
+
            alias: None,
            connect: Vec::default(),
            external_addresses: vec![],
            network: Network::default(),
@@ -87,7 +91,10 @@ impl Config {
    pub fn alias(&self) -> [u8; 32] {
        let mut alias = [0u8; 32];

-
        alias[..9].copy_from_slice("anonymous".as_bytes());
+
        if let Some(name) = &self.alias {
+
            alias[..name.len()].copy_from_slice(name.as_bytes());
+
        }
+

        alias
    }
}