diff --git a/Cargo.lock b/Cargo.lock index de693647e0..2c3773b41e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4606,7 +4606,9 @@ dependencies = [ "color-eyre", "futures", "libp2p", + "sn_build_info", "sn_networking", + "sn_protocol", "tokio", "tracing", "tracing-log 0.2.0", @@ -4744,7 +4746,9 @@ dependencies = [ "signal-hook", "sn-node-manager", "sn-releases", + "sn_build_info", "sn_peers_acquisition", + "sn_protocol", "sn_service_management", "strip-ansi-escapes", "strum", @@ -6976,6 +6980,7 @@ dependencies = [ "serde_json", "service-manager", "sn-releases", + "sn_build_info", "sn_logging", "sn_peers_acquisition", "sn_protocol", @@ -7024,9 +7029,11 @@ dependencies = [ "lazy_static", "serde", "serde_json", + "sn_build_info", "sn_client", "sn_logging", "sn_peers_acquisition", + "sn_protocol", "tiny_http", "tokio", "tracing", @@ -7049,6 +7056,8 @@ dependencies = [ name = "sn_build_info" version = "0.1.12" dependencies = [ + "chrono", + "tracing", "vergen", ] @@ -7358,6 +7367,7 @@ dependencies = [ "hex 0.4.3", "libp2p", "libp2p-identity", + "sn_build_info", "sn_client", "sn_logging", "sn_node", diff --git a/nat-detection/Cargo.toml b/nat-detection/Cargo.toml index 7443b13cbc..8a1aa8a8b4 100644 --- a/nat-detection/Cargo.toml +++ b/nat-detection/Cargo.toml @@ -13,6 +13,9 @@ version = "0.2.4" name = "nat-detection" path = "src/main.rs" +[features] +nightly = [] + [dependencies] clap = { version = "4.5.4", features = ["derive"] } clap-verbosity-flag = "2.2.0" @@ -28,7 +31,9 @@ libp2p = { version = "0.54.1", features = [ "macros", "upnp", ] } +sn_build_info = { path = "../sn_build_info", version = "0.1.12" } sn_networking = { path = "../sn_networking", version = "0.18.1" } +sn_protocol = { path = "../sn_protocol", version = "0.17.8" } tokio = { version = "1.32.0", features = ["full"] } tracing = { version = "~0.1.26" } tracing-log = "0.2.0" diff --git a/nat-detection/src/main.rs b/nat-detection/src/main.rs index 645b181266..3621d210ca 100644 --- a/nat-detection/src/main.rs +++ b/nat-detection/src/main.rs @@ -13,6 +13,7 @@ use libp2p::autonat::NatStatus; use libp2p::core::{multiaddr::Protocol, Multiaddr}; use libp2p::swarm::SwarmEvent; use libp2p::{noise, tcp, yamux}; +use sn_protocol::version::IDENTIFY_PROTOCOL_STR; use std::collections::HashSet; use std::net::Ipv4Addr; use std::time::Duration; @@ -35,7 +36,7 @@ const RETRY_INTERVAL: Duration = Duration::from_secs(10); /// - 11: Public under UPnP /// - 12: Private or Unknown NAT #[derive(Debug, Parser)] -#[clap(version, author, verbatim_doc_comment)] +#[clap(version = sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR), author, verbatim_doc_comment)] struct Opt { /// Port to listen on. /// @@ -60,15 +61,43 @@ struct Opt { #[command(flatten)] verbose: clap_verbosity_flag::Verbosity, + + /// Print the crate version + #[clap(long)] + crate_version: bool, + + /// Print the protocol version + #[clap(long)] + protocol_version: bool, + + /// Print the package version + #[clap(long)] + #[cfg(not(feature = "nightly"))] + package_version: bool, } #[tokio::main] async fn main() -> Result<()> { color_eyre::install()?; - // Process command line arguments. let opt = Opt::parse(); + if opt.crate_version { + println!("Crate version: {}", env!("CARGO_PKG_VERSION")); + return Ok(()); + } + + if opt.protocol_version { + println!("Network version: {}", IDENTIFY_PROTOCOL_STR.to_string()); + return Ok(()); + } + + #[cfg(not(feature = "nightly"))] + if opt.package_version { + println!("Package version: {}", sn_build_info::package_version()); + return Ok(()); + } + let registry = tracing_subscriber::registry().with(tracing_subscriber::fmt::layer()); // Use `RUST_LOG` if set, else use the verbosity flag (where `-vvvv` is trace level). let _ = if std::env::var_os("RUST_LOG").is_some() { diff --git a/node-launchpad/Cargo.toml b/node-launchpad/Cargo.toml index 8c92a39f62..451e733c66 100644 --- a/node-launchpad/Cargo.toml +++ b/node-launchpad/Cargo.toml @@ -14,6 +14,9 @@ build = "build.rs" name = "node-launchpad" path = "src/bin/tui/main.rs" +[features] +nightly = [] + [dependencies] atty = "0.2.14" better-panic = "0.3.0" @@ -48,8 +51,10 @@ reqwest = { version = "0.12.2", default-features = false, features = [ serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.107" signal-hook = "0.3.17" +sn_build_info = { path = "../sn_build_info", version = "0.1.12" } sn-node-manager = { version = "0.10.3", path = "../sn_node_manager" } sn_peers_acquisition = { version = "0.5.0", path = "../sn_peers_acquisition" } +sn_protocol = { path = "../sn_protocol", version = "0.17.8" } sn-releases = "~0.2.6" sn_service_management = { version = "0.3.11", path = "../sn_service_management" } strip-ansi-escapes = "0.2.0" diff --git a/node-launchpad/src/bin/tui/main.rs b/node-launchpad/src/bin/tui/main.rs index 2ceb235900..3fe99aaaeb 100644 --- a/node-launchpad/src/bin/tui/main.rs +++ b/node-launchpad/src/bin/tui/main.rs @@ -21,11 +21,12 @@ use node_launchpad::{ #[cfg(target_os = "windows")] use sn_node_manager::config::is_running_as_root; use sn_peers_acquisition::PeersArgs; +use sn_protocol::version::IDENTIFY_PROTOCOL_STR; use std::{env, path::PathBuf}; use tokio::task::LocalSet; #[derive(Parser, Debug)] -#[command(author, version = version(), about)] +#[command(author, version = version(), about, name = "Autonomi Node Launchpad")] pub struct Cli { #[arg( short, @@ -53,12 +54,41 @@ pub struct Cli { #[command(flatten)] pub(crate) peers: PeersArgs, + + /// Print the crate version. + #[clap(long)] + crate_version: bool, + + /// Print the network protocol version. + #[clap(long)] + protocol_version: bool, + + /// Print the package version. + #[clap(long)] + #[cfg(not(feature = "nightly"))] + package_version: bool, } async fn tokio_main() -> Result<()> { initialize_panic_handler()?; let args = Cli::parse(); + if args.crate_version { + println!("{}", env!("CARGO_PKG_VERSION")); + return Ok(()); + } + + if args.protocol_version { + println!("{}", IDENTIFY_PROTOCOL_STR.to_string()); + return Ok(()); + } + + #[cfg(not(feature = "nightly"))] + if args.package_version { + println!("{}", sn_build_info::package_version()); + return Ok(()); + } + info!("Starting app with args: {args:?}"); let mut app = App::new( args.tick_rate, diff --git a/node-launchpad/src/utils.rs b/node-launchpad/src/utils.rs index ffb997246c..6f64031180 100644 --- a/node-launchpad/src/utils.rs +++ b/node-launchpad/src/utils.rs @@ -8,21 +8,13 @@ use crate::config::get_launchpad_data_dir_path; use color_eyre::eyre::{Context, Result}; +use sn_protocol::version::IDENTIFY_PROTOCOL_STR; use tracing::error; use tracing_error::ErrorLayer; use tracing_subscriber::{ self, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, Layer, }; -const VERSION_MESSAGE: &str = concat!( - env!("CARGO_PKG_VERSION"), - "-", - env!("VERGEN_GIT_DESCRIBE"), - " (", - env!("VERGEN_BUILD_DATE"), - ")" -); - pub fn initialize_panic_handler() -> Result<()> { let (panic_hook, eyre_hook) = color_eyre::config::HookBuilder::default() .panic_section(format!( @@ -135,12 +127,12 @@ macro_rules! trace_dbg { pub fn version() -> String { let author = clap::crate_authors!(); - + let version_message = + sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR); let data_dir_path = get_launchpad_data_dir_path().unwrap().display().to_string(); - format!( "\ -{VERSION_MESSAGE} +{version_message} Authors: {author} diff --git a/sn_auditor/Cargo.toml b/sn_auditor/Cargo.toml index 387233aee5..8f9efada9b 100644 --- a/sn_auditor/Cargo.toml +++ b/sn_auditor/Cargo.toml @@ -16,6 +16,7 @@ local-discovery = [ "sn_peers_acquisition/local-discovery", ] network-contacts = ["sn_peers_acquisition/network-contacts"] +nightly = [] open-metrics = ["sn_client/open-metrics"] websockets = ["sn_client/websockets"] svg-dag = ["graphviz-rust", "dag-collection"] @@ -31,9 +32,11 @@ graphviz-rust = { version = "0.9.0", optional = true } lazy_static = "1.4.0" serde = { version = "1.0.133", features = ["derive", "rc"] } serde_json = "1.0.108" +sn_build_info = { path = "../sn_build_info", version = "0.1.12" } sn_client = { path = "../sn_client", version = "0.110.0" } sn_logging = { path = "../sn_logging", version = "0.2.33" } sn_peers_acquisition = { path = "../sn_peers_acquisition", version = "0.5.0" } +sn_protocol = { path = "../sn_protocol", version = "0.17.8" } tiny_http = { version = "0.12", features = ["ssl-rustls"] } tracing = { version = "~0.1.26" } tokio = { version = "1.32.0", features = [ diff --git a/sn_auditor/src/main.rs b/sn_auditor/src/main.rs index 2faf8551e1..aa15630422 100644 --- a/sn_auditor/src/main.rs +++ b/sn_auditor/src/main.rs @@ -19,6 +19,7 @@ use dag_db::SpendDagDb; use sn_client::Client; use sn_logging::{Level, LogBuilder, LogFormat, LogOutputDest}; use sn_peers_acquisition::PeersArgs; +use sn_protocol::version::IDENTIFY_PROTOCOL_STR; use std::collections::BTreeSet; use std::path::PathBuf; use tiny_http::{Response, Server}; @@ -27,7 +28,7 @@ use tiny_http::{Response, Server}; const BETA_REWARDS_BACKUP_INTERVAL_SECS: u64 = 20 * 60; #[derive(Parser)] -#[command(author, version, about, long_about = None)] +#[command(author, version = sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR), about, long_about = None, name = "Autonomi Auditor")] struct Opt { #[command(flatten)] peers: PeersArgs, @@ -70,6 +71,19 @@ struct Opt { /// discord usernames of the beta participants #[clap(short = 'k', long, value_name = "hex_secret_key")] beta_encryption_key: Option, + + /// Print the crate version. + #[clap(long)] + pub crate_version: bool, + + /// Print the network protocol version. + #[clap(long)] + pub protocol_version: bool, + + /// Print the package version. + #[cfg(not(feature = "nightly"))] + #[clap(long)] + pub package_version: bool, } #[tokio::main] @@ -78,6 +92,22 @@ async fn main() -> Result<()> { let log_builder = logging_init(opt.log_output_dest, opt.log_format)?; let _log_handles = log_builder.initialize()?; + if opt.crate_version { + println!("{}", sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR)); + return Ok(()); + } + + #[cfg(not(feature = "nightly"))] + if opt.package_version { + println!("{}", sn_build_info::package_version()); + return Ok(()); + } + + if opt.protocol_version { + println!("{}", IDENTIFY_PROTOCOL_STR.to_string()); + return Ok(()); + } + let beta_participants = load_and_update_beta_participants(opt.beta_participants)?; let maybe_sk = if let Some(sk_str) = opt.beta_encryption_key { diff --git a/sn_build_info/Cargo.toml b/sn_build_info/Cargo.toml index b47bdf68d0..0cc6d02733 100644 --- a/sn_build_info/Cargo.toml +++ b/sn_build_info/Cargo.toml @@ -9,9 +9,17 @@ name = "sn_build_info" readme = "README.md" repository = "https://github.com/maidsafe/safe_network" version = "0.1.12" +build = "build.rs" [build-dependencies] vergen = { version = "8.0.0", features = ["build", "git", "gitcl"] } +[features] +nightly = [] + [lints] workspace = true + +[dependencies] +chrono = "0.4" +tracing = { version = "~0.1.26" } diff --git a/sn_build_info/build.rs b/sn_build_info/build.rs index 392c55da4e..96917d3690 100644 --- a/sn_build_info/build.rs +++ b/sn_build_info/build.rs @@ -5,6 +5,8 @@ // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. Please review the Licences for the specific language governing // permissions and limitations relating to use of the SAFE Network Software. +use std::fs; +use std::path::Path; use vergen::EmitBuilder; fn main() -> Result<(), Box> { @@ -18,5 +20,31 @@ fn main() -> Result<(), Box> { .git_describe(true, false, None) .emit()?; + let release_info_path = Path::new("../release-cycle-info"); + let contents = + fs::read_to_string(release_info_path).expect("Failed to read release-cycle-info"); + + let mut year = String::new(); + let mut month = String::new(); + let mut cycle = String::new(); + let mut counter = String::new(); + + for line in contents.lines() { + if line.starts_with("release-year:") { + year = line.split(':').nth(1).unwrap().trim().to_string(); + } else if line.starts_with("release-month:") { + month = line.split(':').nth(1).unwrap().trim().to_string(); + } else if line.starts_with("release-cycle:") { + cycle = line.split(':').nth(1).unwrap().trim().to_string(); + } else if line.starts_with("release-cycle-counter:") { + counter = line.split(':').nth(1).unwrap().trim().to_string(); + } + } + + println!("cargo:rustc-env=RELEASE_YEAR={}", year); + println!("cargo:rustc-env=RELEASE_MONTH={}", month); + println!("cargo:rustc-env=RELEASE_CYCLE={}", cycle); + println!("cargo:rustc-env=RELEASE_CYCLE_COUNTER={}", counter); + Ok(()) } diff --git a/sn_build_info/src/lib.rs b/sn_build_info/src/lib.rs index 6b858254ac..04265e709b 100644 --- a/sn_build_info/src/lib.rs +++ b/sn_build_info/src/lib.rs @@ -6,14 +6,15 @@ // KIND, either express or implied. Please review the Licences for the specific language governing // permissions and limitations relating to use of the SAFE Network Software. +use chrono::Utc; +use tracing::debug; + /// Git information separated by slashes: ` / / ` pub const fn git_info() -> &'static str { concat!( - env!("VERGEN_GIT_SHA"), - " / ", env!("VERGEN_GIT_BRANCH"), " / ", - env!("VERGEN_GIT_DESCRIBE"), + env!("VERGEN_GIT_SHA"), " / ", env!("VERGEN_BUILD_DATE") ) @@ -33,3 +34,58 @@ pub const fn git_branch() -> &'static str { pub const fn git_sha() -> &'static str { env!("VERGEN_GIT_SHA") } + +/// Nightly version format: YYYY.MM.DD +pub fn nightly_version() -> String { + let now = Utc::now(); + now.format("%Y.%m.%d").to_string() +} + +/// Git information for nightly builds: ` / / ` +pub fn nightly_git_info() -> String { + format!("{} / {} / {}", nightly_version(), git_branch(), git_sha(),) +} + +pub fn package_version() -> String { + format!( + "{}.{}.{}.{}", + env!("RELEASE_YEAR"), + env!("RELEASE_MONTH"), + env!("RELEASE_CYCLE"), + env!("RELEASE_CYCLE_COUNTER") + ) +} + +pub fn full_version_info(crate_version: &str, protocol_version: &str) -> String { + format!( + "v{}\nNetwork version: {}\nPackage version: {}\nGit info: {}", + crate_version, + protocol_version, + package_version(), + git_info() + ) +} + +pub fn version_string(crate_version: &str, protocol_version: &str) -> String { + if cfg!(feature = "nightly") { + format!( + "-- Nightly Release {}\nGit info: {} / {}", + nightly_version(), + git_branch(), + git_sha(), + ) + } else { + full_version_info(crate_version, protocol_version) + } +} + +pub fn log_version_info(crate_version: &str, protocol_version: &str) { + if cfg!(feature = "nightly") { + debug!("nightly build info: {}", nightly_git_info()); + } else { + debug!("version: {}", crate_version); + debug!("network version: {}", protocol_version); + debug!("package version: {}", package_version()); + debug!("git info: {}", git_info()); + } +} \ No newline at end of file diff --git a/sn_cli/Cargo.toml b/sn_cli/Cargo.toml index ebca335d94..ad5b38af19 100644 --- a/sn_cli/Cargo.toml +++ b/sn_cli/Cargo.toml @@ -27,6 +27,7 @@ local-discovery = [ ] metrics = ["sn_logging/process-metrics"] network-contacts = ["sn_peers_acquisition/network-contacts"] +nightly = [] open-metrics = ["sn_client/open-metrics"] [dependencies] diff --git a/sn_cli/src/bin/main.rs b/sn_cli/src/bin/main.rs index 0ac03d458b..87d4efd9a6 100644 --- a/sn_cli/src/bin/main.rs +++ b/sn_cli/src/bin/main.rs @@ -30,6 +30,7 @@ use sn_client::transfers::bls_secret_from_hex; use sn_client::{Client, ClientEvent, ClientEventsBroadcaster, ClientEventsReceiver}; #[cfg(feature = "metrics")] use sn_logging::{metrics::init_metrics, Level, LogBuilder, LogFormat}; +use sn_protocol::version::IDENTIFY_PROTOCOL_STR; use std::{io, path::PathBuf, time::Duration}; use tokio::{sync::broadcast::error::RecvError, task::JoinHandle}; @@ -39,6 +40,22 @@ const CLIENT_KEY: &str = "clientkey"; async fn main() -> Result<()> { color_eyre::install()?; let opt = Opt::parse(); + + if opt.crate_version { + println!("{}", env!("CARGO_PKG_VERSION")); + return Ok(()); + } + + if opt.protocol_version { + println!("{}", IDENTIFY_PROTOCOL_STR.to_string()); + return Ok(()); + } + + if opt.package_version { + println!("{}", sn_build_info::package_version()); + return Ok(()); + } + let logging_targets = vec![ // TODO: Reset to nice and clean defaults once we have a better idea of what we want ("sn_networking".to_string(), Level::INFO), diff --git a/sn_cli/src/bin/subcommands/mod.rs b/sn_cli/src/bin/subcommands/mod.rs index 7a7ba11cad..f002194331 100644 --- a/sn_cli/src/bin/subcommands/mod.rs +++ b/sn_cli/src/bin/subcommands/mod.rs @@ -16,12 +16,13 @@ use clap::Subcommand; use color_eyre::Result; use sn_logging::{LogFormat, LogOutputDest}; use sn_peers_acquisition::PeersArgs; +use sn_protocol::version::IDENTIFY_PROTOCOL_STR; use std::time::Duration; // Please do not remove the blank lines in these doc comments. // They are used for inserting line breaks when the help menu is rendered in the UI. #[derive(Parser)] -#[command(author, version, about, long_about = None)] +#[command(author, version = sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR), about, long_about = None, name = "Autonomi CLI")] pub(crate) struct Opt { /// Specify the logging output destination. /// @@ -60,6 +61,18 @@ pub(crate) struct Opt { /// This may increase operation speed, but offers no guarantees that operations were successful. #[clap(global = true, long = "no-verify", short = 'x')] pub no_verify: bool, + + /// Print the crate version. + #[clap(long)] + pub crate_version: bool, + + /// Print the network protocol version. + #[clap(long)] + pub protocol_version: bool, + + /// Print the package version. + #[clap(long)] + pub package_version: bool, } #[derive(Subcommand, Debug)] @@ -82,4 +95,4 @@ pub(super) enum SubCmd { #[clap(name = "register", subcommand)] /// Commands for register management Register(register::RegisterCmds), -} +} \ No newline at end of file diff --git a/sn_faucet/Cargo.toml b/sn_faucet/Cargo.toml index a82ff0ed2a..5a68c9d953 100644 --- a/sn_faucet/Cargo.toml +++ b/sn_faucet/Cargo.toml @@ -15,6 +15,7 @@ default = ["gifting"] distribution = ["base64", "bitcoin", "minreq"] gifting = [] initial-data = ["reqwest", "futures"] +nightly = [] [[bin]] path = "src/main.rs" diff --git a/sn_faucet/src/main.rs b/sn_faucet/src/main.rs index 833178a8f9..254c2d17d1 100644 --- a/sn_faucet/src/main.rs +++ b/sn_faucet/src/main.rs @@ -22,15 +22,32 @@ use sn_client::{ }; use sn_logging::{Level, LogBuilder, LogOutputDest}; use sn_peers_acquisition::PeersArgs; +use sn_protocol::version::IDENTIFY_PROTOCOL_STR; use sn_transfers::{get_faucet_data_dir, HotWallet, MainPubkey, NanoTokens, Transfer}; use std::{path::PathBuf, time::Duration}; use tokio::{sync::broadcast::error::RecvError, task::JoinHandle}; -use tracing::{debug, error, info}; +use tracing::{error, info}; #[tokio::main] async fn main() -> Result<()> { let opt = Opt::parse(); + if opt.crate_version { + println!("Crate version: {}", env!("CARGO_PKG_VERSION")); + return Ok(()); + } + + if opt.protocol_version { + println!("Network version: {}", IDENTIFY_PROTOCOL_STR.to_string()); + return Ok(()); + } + + #[cfg(not(feature = "nightly"))] + if opt.package_version { + println!("Package version: {}", sn_build_info::package_version()); + return Ok(()); + } + let bootstrap_peers = opt.peers.get_peers().await?; let bootstrap_peers = if bootstrap_peers.is_empty() { // empty vec is returned if `local-discovery` flag is provided @@ -57,14 +74,8 @@ async fn main() -> Result<()> { log_builder.output_dest(opt.log_output_dest); let _log_handles = log_builder.initialize()?; - debug!( - "faucet built with git version: {}", - sn_build_info::git_info() - ); - println!( - "faucet built with git version: {}", - sn_build_info::git_info() - ); + sn_build_info::log_version_info(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR); + info!("Instantiating a SAFE Test Faucet..."); let secret_key = bls::SecretKey::random(); @@ -147,7 +158,7 @@ fn spawn_connection_progress_bar(mut rx: ClientEventsReceiver) -> (ProgressBar, } #[derive(Parser)] -#[command(author, version, about, long_about = None)] +#[command(author, version = sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR), about, long_about = None)] struct Opt { /// Specify the logging output destination. /// @@ -168,6 +179,19 @@ struct Opt { /// Available sub commands. #[clap(subcommand)] pub cmd: SubCmd, + + /// Print the crate version + #[clap(long)] + crate_version: bool, + + /// Print the protocol version + #[clap(long)] + protocol_version: bool, + + /// Print the package version + #[cfg(not(feature = "nightly"))] + #[clap(long)] + package_version: bool, } #[derive(Subcommand, Debug, Clone)] @@ -261,4 +285,4 @@ fn parse_log_output(val: &str) -> Result { // because the path doesn't need to exist. We can create it for the user. value => Ok(LogOutputDest::Path(PathBuf::from(value))), } -} +} \ No newline at end of file diff --git a/sn_node/Cargo.toml b/sn_node/Cargo.toml index 4c735bc9c4..7a3c494a5d 100644 --- a/sn_node/Cargo.toml +++ b/sn_node/Cargo.toml @@ -15,14 +15,15 @@ path = "src/bin/safenode/main.rs" [features] default = ["metrics", "upnp", "reward-forward", "open-metrics"] +encrypt-records = ["sn_networking/encrypt-records"] local-discovery = ["sn_networking/local-discovery"] -otlp = ["sn_logging/otlp"] metrics = ["sn_logging/process-metrics"] network-contacts = ["sn_peers_acquisition/network-contacts"] +nightly = [] open-metrics = ["sn_networking/open-metrics", "prometheus-client"] -encrypt-records = ["sn_networking/encrypt-records"] -upnp = ["sn_networking/upnp"] +otlp = ["sn_logging/otlp"] reward-forward = ["sn_transfers/reward-forward"] +upnp = ["sn_networking/upnp"] [dependencies] assert_fs = "1.0.0" diff --git a/sn_node/src/bin/safenode/main.rs b/sn_node/src/bin/safenode/main.rs index cf30e04c65..aed56a75c8 100644 --- a/sn_node/src/bin/safenode/main.rs +++ b/sn_node/src/bin/safenode/main.rs @@ -11,15 +11,18 @@ extern crate tracing; mod rpc_service; -use clap::Parser; -use eyre::{eyre, Result}; +use clap::{command, Parser}; +use color_eyre::{eyre::eyre, Result}; use libp2p::{identity::Keypair, PeerId}; +use sn_build_info; #[cfg(feature = "metrics")] use sn_logging::metrics::init_metrics; use sn_logging::{Level, LogFormat, LogOutputDest, ReloadHandle}; use sn_node::{Marker, NodeBuilder, NodeEvent, NodeEventsReceiver}; use sn_peers_acquisition::PeersArgs; -use sn_protocol::{node::get_safenode_root_dir, node_rpc::NodeCtrl}; +use sn_protocol::{ + node::get_safenode_root_dir, node_rpc::NodeCtrl, version::IDENTIFY_PROTOCOL_STR, +}; use std::{ env, io::Write, @@ -65,7 +68,7 @@ pub fn parse_log_output(val: &str) -> Result { // Please do not remove the blank lines in these doc comments. // They are used for inserting line breaks when the help menu is rendered in the UI. #[derive(Parser, Debug)] -#[clap(name = "safenode cli", version = env!("CARGO_PKG_VERSION"))] +#[command(version = sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR), about, long_about = None, name = "Autonomi Node")] struct Opt { /// Specify whether the node is operating from a home network and situated behind a NAT without port forwarding /// capabilities. Setting this to true, activates hole-punching to facilitate direct connections from other nodes. @@ -177,12 +180,41 @@ struct Opt { required_if_eq("metrics_server_port", "0") )] enable_metrics_server: bool, + + /// Print the crate version. + #[clap(long)] + crate_version: bool, + + /// Print the network protocol version. + #[clap(long)] + protocol_version: bool, + + /// Print the package version. + #[cfg(not(feature = "nightly"))] + #[clap(long)] + package_version: bool, } fn main() -> Result<()> { color_eyre::install()?; let opt = Opt::parse(); + if opt.crate_version { + println!("Crate version: {}", env!("CARGO_PKG_VERSION")); + return Ok(()); + } + + if opt.protocol_version { + println!("Network version: {}", IDENTIFY_PROTOCOL_STR.to_string()); + return Ok(()); + } + + #[cfg(not(feature = "nightly"))] + if opt.package_version { + println!("Package version: {}", sn_build_info::package_version()); + return Ok(()); + } + let node_socket_addr = SocketAddr::new(opt.ip, opt.port); let (root_dir, keypair) = get_root_dir_and_keypair(&opt.root_dir)?; @@ -197,10 +229,8 @@ fn main() -> Result<()> { env!("CARGO_PKG_VERSION") ); info!("\n{}\n{}", msg, "=".repeat(msg.len())); - debug!( - "safenode built with git version: {}", - sn_build_info::git_info() - ); + + sn_build_info::log_version_info(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR); info!("Node started with initial_peers {bootstrap_peers:?}"); @@ -599,4 +629,4 @@ fn start_new_node_process(retain_peer_id: Option<(PathBuf, u16)>) { return; } }; -} +} \ No newline at end of file diff --git a/sn_node_manager/Cargo.toml b/sn_node_manager/Cargo.toml index 033738bcd5..d9d4260496 100644 --- a/sn_node_manager/Cargo.toml +++ b/sn_node_manager/Cargo.toml @@ -22,6 +22,7 @@ chaos = [] default = ["quic"] local-discovery = [] network-contacts = [] +nightly = [] open-metrics = [] otlp = [] quic = [] @@ -44,6 +45,7 @@ semver = "1.0.20" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" service-manager = "0.7.0" +sn_build_info = { path = "../sn_build_info", version = "0.1.12" } sn_logging = { path = "../sn_logging", version = "0.2.33" } sn_peers_acquisition = { path = "../sn_peers_acquisition", version = "0.5.0" } sn_protocol = { path = "../sn_protocol", version = "0.17.8" } diff --git a/sn_node_manager/src/bin/cli/main.rs b/sn_node_manager/src/bin/cli/main.rs index 7e89275279..360c8555a6 100644 --- a/sn_node_manager/src/bin/cli/main.rs +++ b/sn_node_manager/src/bin/cli/main.rs @@ -16,28 +16,42 @@ use sn_node_manager::{ VerbosityLevel, DEFAULT_NODE_STARTUP_CONNECTION_TIMEOUT_S, }; use sn_peers_acquisition::PeersArgs; +use sn_protocol::version::IDENTIFY_PROTOCOL_STR; use std::{net::Ipv4Addr, path::PathBuf}; use tracing::Level; const DEFAULT_NODE_COUNT: u16 = 25; #[derive(Parser)] -#[command(author, version, about, long_about = None)] +#[command(author, version = sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR), about, long_about = None, name = "Autonomi Node Manager")] pub(crate) struct Cmd { /// Available sub commands. #[clap(subcommand)] pub cmd: SubCmd, - #[clap(short, long, action = clap::ArgAction::Count, default_value_t = 2)] - verbose: u8, + /// Print the crate version. + #[clap(long)] + pub crate_version: bool, /// Output debug-level logging to stderr. #[clap(long, conflicts_with = "trace")] debug: bool, + /// Print the package version. + #[cfg(not(feature = "nightly"))] + #[clap(long)] + pub package_version: bool, + + /// Print the network protocol version. + #[clap(long)] + pub protocol_version: bool, + /// Output trace-level logging to stderr. #[clap(long, conflicts_with = "debug")] trace: bool, + + #[clap(short, long, action = clap::ArgAction::Count, default_value_t = 2)] + verbose: u8, } #[derive(Subcommand, Debug)] @@ -997,6 +1011,23 @@ pub enum LocalSubCmd { async fn main() -> Result<()> { color_eyre::install()?; let args = Cmd::parse(); + + if args.crate_version { + println!("{}", env!("CARGO_PKG_VERSION")); + return Ok(()); + } + + if args.protocol_version { + println!("{}", IDENTIFY_PROTOCOL_STR.to_string()); + return Ok(()); + } + + #[cfg(not(feature = "nightly"))] + if args.package_version { + println!("{}", sn_build_info::package_version()); + return Ok(()); + } + let verbosity = VerbosityLevel::from(args.verbose); let _log_handle = if args.debug || args.trace { diff --git a/sn_node_manager/src/bin/daemon/main.rs b/sn_node_manager/src/bin/daemon/main.rs index 99925943be..12fcc7a14f 100644 --- a/sn_node_manager/src/bin/daemon/main.rs +++ b/sn_node_manager/src/bin/daemon/main.rs @@ -22,21 +22,32 @@ use sn_service_management::{ }, NodeRegistry, }; +use sn_protocol::version::IDENTIFY_PROTOCOL_STR; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use tonic::{transport::Server, Code, Request, Response, Status}; use tracing::Level; #[derive(Parser, Debug)] -#[clap(author, version, about, long_about = None)] +#[command(author, version = sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR), about, long_about = None, name = "Autonomi Node Manager RPC Daemon")] struct Args { - /// Specify a port for the daemon to listen for RPCs. It defaults to 12500 if not set. - #[clap(long, default_value_t = DAEMON_DEFAULT_PORT)] - port: u16, /// Specify an Ipv4Addr for the daemon to listen on. This is useful if you want to manage the nodes remotely. /// /// If not set, the daemon listens locally for commands. #[clap(long, default_value_t = Ipv4Addr::new(127, 0, 0, 1))] address: Ipv4Addr, + /// Print the crate version. + #[clap(long)] + pub crate_version: bool, + /// Print the package version. + #[cfg(not(feature = "nightly"))] + #[clap(long)] + pub package_version: bool, + /// Specify a port for the daemon to listen for RPCs. It defaults to 12500 if not set. + #[clap(long, default_value_t = DAEMON_DEFAULT_PORT)] + port: u16, + /// Print the network protocol version. + #[clap(long)] + pub protocol_version: bool, } struct SafeNodeManagerDaemon {} @@ -131,9 +142,25 @@ async fn main() -> Result<()> { let _log_handles = get_log_builder()?.initialize()?; println!("Starting safenodemand"); let args = Args::parse(); + + if args.crate_version { + println!("{}", sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR)); + return Ok(()); + } + + #[cfg(not(feature = "nightly"))] + if args.package_version { + println!("{}", sn_build_info::package_version()); + return Ok(()); + } + + if args.protocol_version { + println!("{}", IDENTIFY_PROTOCOL_STR.to_string()); + return Ok(()); + } + let service = SafeNodeManagerDaemon {}; - // adding our service to our server. if let Err(err) = Server::builder() .add_service(SafeNodeManagerServer::new(service)) .serve(SocketAddr::new(IpAddr::V4(args.address), args.port)) diff --git a/sn_node_rpc_client/Cargo.toml b/sn_node_rpc_client/Cargo.toml index 582a2f46c2..74bcb0b738 100644 --- a/sn_node_rpc_client/Cargo.toml +++ b/sn_node_rpc_client/Cargo.toml @@ -14,6 +14,9 @@ version = "0.6.28" name = "safenode_rpc_client" path = "src/main.rs" +[features] +nightly = [] + [dependencies] assert_fs = "1.0.0" async-trait = "0.1" @@ -23,6 +26,7 @@ color-eyre = "0.6.2" hex = "~0.4.3" libp2p = { version = "0.54.1", features = ["kad"]} libp2p-identity = { version="0.2.7", features = ["rand"] } +sn_build_info = { path = "../sn_build_info", version = "0.1.12" } sn_client = { path = "../sn_client", version = "0.110.0" } sn_logging = { path = "../sn_logging", version = "0.2.33" } sn_node = { path = "../sn_node", version = "0.111.1" } diff --git a/sn_node_rpc_client/src/main.rs b/sn_node_rpc_client/src/main.rs index 7d019bff95..cdada61557 100644 --- a/sn_node_rpc_client/src/main.rs +++ b/sn_node_rpc_client/src/main.rs @@ -9,26 +9,36 @@ use clap::Parser; use color_eyre::eyre::Result; - use sn_logging::{Level, LogBuilder}; use sn_node::NodeEvent; - use sn_protocol::safenode_proto::{safe_node_client::SafeNodeClient, NodeEventsRequest}; - +use sn_protocol::version::IDENTIFY_PROTOCOL_STR; use sn_service_management::rpc::{RpcActions, RpcClient}; - use std::{net::SocketAddr, time::Duration}; use tokio_stream::StreamExt; use tonic::Request; #[derive(Parser, Debug)] -#[clap(version, name = "safenode RPC client")] +#[command(author, version = sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR), about, long_about = None, name = "Autonomi Node RPC Client")] struct Opt { /// Address of the node's RPC service, e.g. 127.0.0.1:12001. addr: SocketAddr, /// subcommands #[clap(subcommand)] cmd: Cmd, + + /// Print the crate version. + #[clap(long)] + crate_version: bool, + + /// Print the network protocol version. + #[clap(long)] + protocol_version: bool, + + /// Print the package version. + #[cfg(not(feature = "nightly"))] + #[clap(long)] + package_version: bool, } #[derive(Parser, Debug)] @@ -90,6 +100,23 @@ async fn main() -> Result<()> { let _log_appender_guard = LogBuilder::new(logging_targets).initialize()?; let opt = Opt::parse(); + + if opt.crate_version { + println!("Crate version: {}", env!("CARGO_PKG_VERSION")); + return Ok(()); + } + + if opt.protocol_version { + println!("Network version: {}", IDENTIFY_PROTOCOL_STR.to_string()); + return Ok(()); + } + + #[cfg(not(feature = "nightly"))] + if opt.package_version { + println!("Package version: {}", sn_build_info::package_version()); + return Ok(()); + } + let addr = opt.addr; match opt.cmd {