From 179211b2c70e8a3f20e68299173f154af33a548e Mon Sep 17 00:00:00 2001 From: oars Date: Wed, 13 Aug 2025 18:17:00 +0300 Subject: [PATCH] bin,example/dchat,script: DEP-006: retrieve app_name and app_version from CARGO_PKG_NAME and CARGO_PKG_VERSION for use in net Version message --- bin/darkfid/src/main.rs | 5 ++++- bin/darkirc/src/main.rs | 4 ++-- bin/fud/fud/src/main.rs | 5 +++-- bin/genev/genevd/src/main.rs | 4 +++- bin/tau/taud/src/main.rs | 6 +++++- example/dchat/dchatd/src/main.rs | 4 +++- script/evgrd/bin/evgrd.rs | 11 ++++++----- script/evgrd/bin/rpc.rs | 2 +- script/evgrd/example/recv.rs | 2 +- script/evgrd/src/lib.rs | 2 +- script/research/dam/damd/src/main.rs | 4 +++- script/research/generic-node/src/main.rs | 6 ++++-- 12 files changed, 36 insertions(+), 19 deletions(-) diff --git a/bin/darkfid/src/main.rs b/bin/darkfid/src/main.rs index 91db2f569..57af48e92 100644 --- a/bin/darkfid/src/main.rs +++ b/bin/darkfid/src/main.rs @@ -227,12 +227,15 @@ async fn realmain(args: Args, ex: Arc>) -> Result<()> { return Ok(()) } + let p2p_settings: darkfi::net::Settings = + (env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), blockchain_config.net).try_into()?; + // Generate the daemon let daemon = Darkfid::init( network, &sled_db, &config, - &blockchain_config.net.into(), + &p2p_settings, &blockchain_config.txs_batch_size, &ex, ) diff --git a/bin/darkirc/src/main.rs b/bin/darkirc/src/main.rs index d9d4c38a4..3ce38d81b 100644 --- a/bin/darkirc/src/main.rs +++ b/bin/darkirc/src/main.rs @@ -339,8 +339,8 @@ async fn realmain(args: Args, ex: Arc>) -> Result<()> { return Err(e.into()); } }; - let mut p2p_settings: darkfi::net::Settings = args.net.into(); - p2p_settings.app_version = semver::Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); + let p2p_settings: darkfi::net::Settings = + (env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), args.net).try_into()?; let p2p = match P2p::new(p2p_settings, ex.clone()).await { Ok(p2p) => p2p, Err(e) => { diff --git a/bin/fud/fud/src/main.rs b/bin/fud/fud/src/main.rs index 53bff423c..dba2816d3 100644 --- a/bin/fud/fud/src/main.rs +++ b/bin/fud/fud/src/main.rs @@ -60,8 +60,9 @@ async fn realmain(args: Args, ex: Arc>) -> Result<()> { // We will use the peers defined in the settings as direct connections (instead of manual) // let direct_peers = net_settings.peers.clone(); // net_settings.peers = vec![]; - let net_settings: NetSettings = args.net.into(); - let p2p = P2p::new(net_settings.clone(), ex.clone()).await?; + let net_settings: NetSettings = + (env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), args.net).try_into()?; + let p2p = P2p::new(net_settings, ex.clone()).await?; info!(target: "fud", "Starting dnet subs task"); let dnet_sub = JsonSubscriber::new("dnet.subscribe_events"); diff --git a/bin/genev/genevd/src/main.rs b/bin/genev/genevd/src/main.rs index d85ca4120..0deb106d4 100644 --- a/bin/genev/genevd/src/main.rs +++ b/bin/genev/genevd/src/main.rs @@ -119,7 +119,9 @@ async fn realmain(settings: Args, executor: Arc>) -> Res let replay_mode = settings.replay_mode; let sled_db = sled::open(datastore_path.clone())?; - let p2p = P2p::new(settings.net.into(), executor.clone()).await?; + let p2p_settings: darkfi::net::Settings = + (env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), settings.net).try_into()?; + let p2p = P2p::new(p2p_settings, executor.clone()).await?; let event_graph = EventGraph::new( p2p.clone(), sled_db.clone(), diff --git a/bin/tau/taud/src/main.rs b/bin/tau/taud/src/main.rs index af267995b..6f500d6be 100644 --- a/bin/tau/taud/src/main.rs +++ b/bin/tau/taud/src/main.rs @@ -519,7 +519,11 @@ async fn realmain(settings: Args, executor: Arc>) -> Res info!(target: "taud", "Instantiating event DAG"); let sled_db = sled::open(datastore)?; - let p2p = P2p::new(settings.net.clone().into(), executor.clone()).await?; + + let p2p_settings: darkfi::net::Settings = + (env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), settings.net.clone()).try_into()?; + + let p2p = P2p::new(p2p_settings, executor.clone()).await?; let event_graph = EventGraph::new( p2p.clone(), sled_db.clone(), diff --git a/example/dchat/dchatd/src/main.rs b/example/dchat/dchatd/src/main.rs index 844467378..e8dfc6967 100644 --- a/example/dchat/dchatd/src/main.rs +++ b/example/dchat/dchatd/src/main.rs @@ -99,7 +99,9 @@ impl Dchat { // ANCHOR: main async_daemonize!(realmain); async fn realmain(args: Args, ex: Arc>) -> Result<()> { - let p2p = net::P2p::new(args.net.into(), ex.clone()).await?; + let p2p_settings: net::Settings = + (env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), args.net).try_into()?; + let p2p = net::P2p::new(p2p_settings, ex.clone()).await?; // ANCHOR: dnet info!("Starting dnet subs task"); diff --git a/script/evgrd/bin/evgrd.rs b/script/evgrd/bin/evgrd.rs index d435e5d2f..74e47f51f 100644 --- a/script/evgrd/bin/evgrd.rs +++ b/script/evgrd/bin/evgrd.rs @@ -16,6 +16,8 @@ * along with this program. If not, see . */ +use std::{collections::HashSet, convert::TryInto, path::PathBuf, sync::Arc}; + use darkfi::{ async_daemonize, cli_desc, event_graph::{ @@ -38,12 +40,11 @@ use darkfi::{ Error, Result, }; use darkfi_serial::{AsyncDecodable, AsyncEncodable}; -use futures::{FutureExt, AsyncWriteExt}; -use tracing::{debug, error, info}; +use futures::{AsyncWriteExt, FutureExt}; use sled_overlay::sled; use smol::{fs, lock::Mutex, stream::StreamExt, Executor}; -use std::{collections::HashSet, path::PathBuf, sync::Arc}; use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml}; +use tracing::{debug, error, info}; use url::Url; use evgrd::{FetchEventsMessage, VersionMessage, MSG_EVENT, MSG_FETCHEVENTS, MSG_SENDEVENT}; @@ -274,8 +275,8 @@ async fn realmain(args: Args, ex: Arc>) -> Result<()> { info!(target: "evgrd", "Instantiating event DAG"); let sled_db = sled::open(datastore)?; - let mut p2p_settings: darkfi::net::Settings = args.net.into(); - p2p_settings.app_version = semver::Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); + let mut p2p_settings: darkfi::net::Settings = + (env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), args.net).try_into()?; p2p_settings.seeds.push(url::Url::parse("tcp+tls://lilith1.dark.fi:5262").unwrap()); let p2p = P2p::new(p2p_settings, ex.clone()).await?; let event_graph = EventGraph::new( diff --git a/script/evgrd/bin/rpc.rs b/script/evgrd/bin/rpc.rs index 0161ffdb5..dd770db59 100644 --- a/script/evgrd/bin/rpc.rs +++ b/script/evgrd/bin/rpc.rs @@ -29,8 +29,8 @@ use darkfi::{ }, system::StoppableTaskPtr, }; -use tracing::debug; use smol::lock::MutexGuard; +use tracing::debug; use super::Daemon; diff --git a/script/evgrd/example/recv.rs b/script/evgrd/example/recv.rs index c6b374021..5de7471e7 100644 --- a/script/evgrd/example/recv.rs +++ b/script/evgrd/example/recv.rs @@ -26,9 +26,9 @@ use darkfi_serial::{ async_trait, deserialize_async_partial, AsyncDecodable, AsyncEncodable, SerialDecodable, SerialEncodable, }; -use tracing::{error, info}; use sled_overlay::sled; use smol::fs; +use tracing::{error, info}; use url::Url; use evgrd::{FetchEventsMessage, LocalEventGraph, VersionMessage, MSG_EVENT, MSG_FETCHEVENTS}; diff --git a/script/evgrd/src/lib.rs b/script/evgrd/src/lib.rs index 822c8dec1..5d7c78b9d 100644 --- a/script/evgrd/src/lib.rs +++ b/script/evgrd/src/lib.rs @@ -27,7 +27,6 @@ use darkfi::{ use darkfi_serial::{ async_trait, deserialize_async, serialize_async, SerialDecodable, SerialEncodable, }; -use tracing::{debug, error, info}; use sled_overlay::{sled, SledTreeOverlay}; use smol::{ lock::{OnceCell, RwLock}, @@ -37,6 +36,7 @@ use std::{ collections::{BTreeMap, HashSet}, sync::Arc, }; +use tracing::{debug, error, info}; pub const PROTOCOL_VERSION: u32 = 1; diff --git a/script/research/dam/damd/src/main.rs b/script/research/dam/damd/src/main.rs index 8e5be1e26..676866375 100644 --- a/script/research/dam/damd/src/main.rs +++ b/script/research/dam/damd/src/main.rs @@ -61,7 +61,9 @@ struct Args { async_daemonize!(realmain); async fn realmain(args: Args, ex: Arc>) -> Result<()> { info!(target: "damd", "Starting Denial-of-service Analysis Multitool daemon..."); - let daemon = Damd::init(&args.net.into(), &ex).await?; + let net_settings: darkfi::net::Settings = + (env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), args.net).try_into()?; + let daemon = Damd::init(&net_settings, &ex).await?; daemon.start(&ex, &args.rpc.into()).await?; // Signal handling for graceful termination. diff --git a/script/research/generic-node/src/main.rs b/script/research/generic-node/src/main.rs index 269d1301c..354216f90 100644 --- a/script/research/generic-node/src/main.rs +++ b/script/research/generic-node/src/main.rs @@ -18,10 +18,10 @@ use std::{collections::HashSet, sync::Arc}; -use tracing::{error, info}; use rand::{rngs::OsRng, Rng}; use smol::{stream::StreamExt, Executor}; use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml}; +use tracing::{error, info}; use darkfi::{ async_daemonize, cli_desc, impl_p2p_message, @@ -344,7 +344,9 @@ async_daemonize!(realmain); async fn realmain(args: Args, ex: Arc>) -> Result<()> { info!(target: "generic-node", "Initializing generic node..."); - let genericd = Genericd::new(args.node_id, &args.net.into(), &ex).await?; + let net_settings: Settings = + (env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), args.net).try_into()?; + let genericd = Genericd::new(args.node_id, &net_settings, &ex).await?; genericd.start().await?; // Signal handling for graceful termination.