diff --git a/applications/minotari_console_wallet/src/config.rs b/applications/minotari_console_wallet/src/config.rs index f0a4f7ec59..99495b4da2 100644 --- a/applications/minotari_console_wallet/src/config.rs +++ b/applications/minotari_console_wallet/src/config.rs @@ -45,8 +45,6 @@ impl ApplicationConfig { peer_seeds: PeerSeedsConfig::load_from(cfg)?, }; - config.wallet.p2p.user_agent = format!("tari/wallet/{}", consts::APP_VERSION_NUMBER); - config.wallet.set_base_path(config.common.base_path()); Ok(config) } diff --git a/applications/minotari_console_wallet/src/init/mod.rs b/applications/minotari_console_wallet/src/init/mod.rs index e2cd0f9b1e..749345b82f 100644 --- a/applications/minotari_console_wallet/src/init/mod.rs +++ b/applications/minotari_console_wallet/src/init/mod.rs @@ -27,7 +27,7 @@ use std::{fs, io, path::PathBuf, str::FromStr, sync::Arc, time::Instant}; #[cfg(feature = "ledger")] use ledger_transport_hid::{hidapi::HidApi, TransportNativeHID}; use log::*; -use minotari_app_utilities::identity_management::setup_node_identity; +use minotari_app_utilities::{consts, identity_management::setup_node_identity}; use minotari_wallet::{ error::{WalletError, WalletStorageError}, output_manager_service::storage::database::OutputManagerDatabase, @@ -449,7 +449,7 @@ pub async fn init_wallet( let factories = CryptoFactories::default(); let now = Instant::now(); - + let user_agent = format!("tari/wallet/{}", consts::APP_VERSION_NUMBER); let mut wallet = Wallet::start( wallet_config, config.peer_seeds.clone(), @@ -466,6 +466,7 @@ pub async fn init_wallet( shutdown_signal, master_seed, wallet_type.unwrap(), + user_agent, ) .await .map_err(|e| match e { diff --git a/applications/minotari_node/src/bootstrap.rs b/applications/minotari_node/src/bootstrap.rs index 229ecd25b9..43e16a212c 100644 --- a/applications/minotari_node/src/bootstrap.rs +++ b/applications/minotari_node/src/bootstrap.rs @@ -122,9 +122,11 @@ where B: BlockchainBackend + 'static .map_err(|e| ExitError::new(ExitCode::ConfigError, e))?; p2p_config.transport.tor.identity = tor_identity; + let user_agent = format!("tari/basenode/{}", consts::APP_VERSION_NUMBER); let mut handles = StackBuilder::new(self.interrupt_signal) .add_initializer(P2pInitializer::new( p2p_config.clone(), + user_agent, peer_seeds.clone(), base_node_config.network, self.node_identity.clone(), diff --git a/applications/minotari_node/src/config.rs b/applications/minotari_node/src/config.rs index b24861ac56..ad0fe955ec 100644 --- a/applications/minotari_node/src/config.rs +++ b/applications/minotari_node/src/config.rs @@ -27,7 +27,6 @@ use std::{ }; use config::Config; -use minotari_app_utilities::consts; use serde::{Deserialize, Serialize}; use tari_common::{ configuration::{serializers, CommonConfig, Network, StringList}, @@ -149,7 +148,6 @@ impl Default for BaseNodeConfig { fn default() -> Self { let p2p = P2pConfig { datastore_path: PathBuf::from("peer_db/base_node"), - user_agent: format!("tari/basenode/{}", consts::APP_VERSION_NUMBER), ..Default::default() }; Self { diff --git a/base_layer/chat_ffi/src/lib.rs b/base_layer/chat_ffi/src/lib.rs index dbea07cb37..ba113f2026 100644 --- a/base_layer/chat_ffi/src/lib.rs +++ b/base_layer/chat_ffi/src/lib.rs @@ -147,8 +147,8 @@ pub unsafe extern "C" fn create_chat_client( return ptr::null_mut(); }, }; - - let mut client = Client::new(identity, (*config).clone()); + let user_agent = format!("tari/chat_ffi/{}", env!("CARGO_PKG_VERSION")); + let mut client = Client::new(identity, (*config).clone(), user_agent); if let Ok(()) = runtime.block_on(client.initialize()) { let contacts_handler = match client.contacts.clone() { @@ -247,8 +247,8 @@ pub unsafe extern "C" fn sideload_chat_client( ptr::swap(error_out, &mut error as *mut c_int); return ptr::null_mut(); } - - let mut client = Client::sideload((*config).clone(), (*contacts_handle).clone()); + let user_agent = format!("tari/chat_ffi/{}", env!("CARGO_PKG_VERSION")); + let mut client = Client::sideload((*config).clone(), (*contacts_handle).clone(), user_agent); if let Ok(()) = runtime.block_on(client.initialize()) { let mut callback_handler = CallbackHandler::new( (*contacts_handle).clone(), diff --git a/base_layer/contacts/src/chat_client/src/client.rs b/base_layer/contacts/src/chat_client/src/client.rs index 801f318fc7..b00d572145 100644 --- a/base_layer/contacts/src/chat_client/src/client.rs +++ b/base_layer/contacts/src/chat_client/src/client.rs @@ -58,6 +58,7 @@ pub trait ChatClient { pub struct Client { pub config: ApplicationConfig, + pub user_agent: String, pub contacts: Option, pub identity: Arc, pub shutdown: Shutdown, @@ -80,16 +81,17 @@ impl Drop for Client { } impl Client { - pub fn new(identity: Arc, config: ApplicationConfig) -> Self { + pub fn new(identity: Arc, config: ApplicationConfig, user_agent: String) -> Self { Self { config, + user_agent, contacts: None, identity, shutdown: Shutdown::new(), } } - pub fn sideload(config: ApplicationConfig, contacts: ContactsServiceHandle) -> Self { + pub fn sideload(config: ApplicationConfig, contacts: ContactsServiceHandle, user_agent: String) -> Self { // Create a placeholder ID. It won't be written or used when sideloaded. let identity = Arc::new(NodeIdentity::random( &mut OsRng, @@ -99,6 +101,7 @@ impl Client { Self { config, + user_agent, contacts: Some(contacts), identity, shutdown: Shutdown::new(), @@ -112,9 +115,14 @@ impl Client { if self.contacts.is_none() { let signal = self.shutdown.to_signal(); - let (contacts, comms_node) = networking::start(self.identity.clone(), self.config.clone(), signal) - .await - .map_err(|e| Error::InitializationError(e.to_string()))?; + let (contacts, comms_node) = networking::start( + self.identity.clone(), + self.config.clone(), + signal, + self.user_agent.clone(), + ) + .await + .map_err(|e| Error::InitializationError(e.to_string()))?; if !self.config.peer_seeds.peer_seeds.is_empty() { loop { diff --git a/base_layer/contacts/src/chat_client/src/config.rs b/base_layer/contacts/src/chat_client/src/config.rs index 0c19f7d9ee..c8f0aee7bc 100644 --- a/base_layer/contacts/src/chat_client/src/config.rs +++ b/base_layer/contacts/src/chat_client/src/config.rs @@ -26,7 +26,6 @@ use std::{ }; use config::Config; -use minotari_app_utilities::consts; use serde::{Deserialize, Serialize}; use tari_common::{ configuration::{serializers, CommonConfig, Network, StringList}, @@ -100,7 +99,6 @@ impl Default for ChatClientConfig { fn default() -> Self { let p2p = P2pConfig { datastore_path: PathBuf::from("peer_db/chat_client"), - user_agent: format!("tari/chat_client/{}", consts::APP_VERSION_NUMBER), dht: DhtConfig { database_url: DbConnectionUrl::file("data/chat_client/dht.sqlite"), ..Default::default() @@ -163,7 +161,6 @@ impl ChatClientConfig { log_verbosity: Some(5), // Trace p2p: P2pConfig { datastore_path: PathBuf::from("peer_db/chat_client"), - user_agent: format!("tari/chat_client/{}", consts::APP_VERSION_NUMBER), dht: DhtConfig { database_url: DbConnectionUrl::file("data/chat_client/dht.sqlite"), network_discovery: NetworkDiscoveryConfig { diff --git a/base_layer/contacts/src/chat_client/src/networking.rs b/base_layer/contacts/src/chat_client/src/networking.rs index 0dc3a0f124..fcedb1fdc8 100644 --- a/base_layer/contacts/src/chat_client/src/networking.rs +++ b/base_layer/contacts/src/chat_client/src/networking.rs @@ -53,6 +53,7 @@ pub async fn start( node_identity: Arc, config: ApplicationConfig, shutdown_signal: ShutdownSignal, + user_agent: String, ) -> Result<(ContactsServiceHandle, CommsNode), NetworkingError> { create_chat_storage(&config.chat_client.db_file)?; let backend = connect_to_db(config.chat_client.db_file)?; @@ -69,6 +70,7 @@ pub async fn start( let fut = StackBuilder::new(shutdown_signal) .add_initializer(P2pInitializer::new( p2p_config.clone(), + user_agent, config.peer_seeds.clone(), config.chat_client.network, node_identity, diff --git a/base_layer/contacts/tests/contacts_service.rs b/base_layer/contacts/tests/contacts_service.rs index f9971430e6..3c762874df 100644 --- a/base_layer/contacts/tests/contacts_service.rs +++ b/base_layer/contacts/tests/contacts_service.rs @@ -93,16 +93,17 @@ pub fn setup_contacts_service( allow_test_addresses: true, listener_liveness_allowlist_cidrs: StringList::new(), listener_liveness_max_sessions: 0, - user_agent: "tari/test-contacts-service".to_string(), rpc_max_simultaneous_sessions: 0, rpc_max_sessions_per_peer: 0, listener_self_liveness_check_interval: None, }; let peer_message_subscription_factory = Arc::new(subscription_factory); let shutdown = Shutdown::new(); + let user_agent = format!("tari/tests/{}", env!("CARGO_PKG_VERSION")); let fut = StackBuilder::new(shutdown.to_signal()) .add_initializer(P2pInitializer::new( comms_config, + user_agent, PeerSeedsConfig::default(), Network::LocalNet, node_identity.clone(), diff --git a/base_layer/p2p/src/config.rs b/base_layer/p2p/src/config.rs index 91d38c3eaa..601a71ec5f 100644 --- a/base_layer/p2p/src/config.rs +++ b/base_layer/p2p/src/config.rs @@ -115,8 +115,6 @@ pub struct P2pConfig { pub listener_self_liveness_check_interval: Option, /// CIDR for addresses allowed to enter into liveness check mode on the listener. pub listener_liveness_allowlist_cidrs: StringList, - /// User agent string for this node - pub user_agent: String, /// The address to bind on using the TCP transport _in addition to_ the primary transport. This is typically useful /// for direct comms between a wallet and base node. If this is set to None, no listener will be bound. /// Default: None @@ -148,7 +146,6 @@ impl Default for P2pConfig { listener_liveness_max_sessions: 0, listener_self_liveness_check_interval: None, listener_liveness_allowlist_cidrs: StringList::default(), - user_agent: String::new(), auxiliary_tcp_listener_address: None, rpc_max_simultaneous_sessions: 100, rpc_max_sessions_per_peer: 10, diff --git a/base_layer/p2p/src/initialization.rs b/base_layer/p2p/src/initialization.rs index 4d3ba863d1..5a67de59ae 100644 --- a/base_layer/p2p/src/initialization.rs +++ b/base_layer/p2p/src/initialization.rs @@ -445,6 +445,7 @@ pub async fn add_seed_peers( pub struct P2pInitializer { config: P2pConfig, + user_agent: String, seed_config: PeerSeedsConfig, network: Network, node_identity: Arc, @@ -454,6 +455,7 @@ pub struct P2pInitializer { impl P2pInitializer { pub fn new( config: P2pConfig, + user_agent: String, seed_config: PeerSeedsConfig, network: Network, node_identity: Arc, @@ -461,6 +463,7 @@ impl P2pInitializer { ) -> Self { Self { config, + user_agent, seed_config, network, node_identity, @@ -557,7 +560,7 @@ impl ServiceInitializer for P2pInitializer { major_version: MAJOR_NETWORK_VERSION, minor_version: MINOR_NETWORK_VERSION, network_byte: self.network.as_byte(), - user_agent: config.user_agent.clone(), + user_agent: self.user_agent.clone(), }) .set_self_liveness_check(config.listener_self_liveness_check_interval); diff --git a/base_layer/wallet/src/wallet.rs b/base_layer/wallet/src/wallet.rs index 4594a6be60..3258101720 100644 --- a/base_layer/wallet/src/wallet.rs +++ b/base_layer/wallet/src/wallet.rs @@ -167,6 +167,7 @@ where shutdown_signal: ShutdownSignal, master_seed: CipherSeed, wallet_type: WalletType, + user_agent: String, ) -> Result { let buf_size = cmp::max(WALLET_BUFFER_MIN_SIZE, config.buffer_size); let (publisher, subscription_factory) = pubsub_connector(buf_size); @@ -189,6 +190,7 @@ where let stack = StackBuilder::new(shutdown_signal) .add_initializer(P2pInitializer::new( config.p2p.clone(), + user_agent, peer_seeds, config.network, node_identity.clone(), diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index ec5050a0ca..27ddbe9f76 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -4869,7 +4869,6 @@ pub unsafe extern "C" fn comms_config_create( allow_test_addresses: true, listener_liveness_allowlist_cidrs: StringList::new(), listener_liveness_max_sessions: 0, - user_agent: format!("tari/mobile_wallet/{}", env!("CARGO_PKG_VERSION")), rpc_max_simultaneous_sessions: 0, rpc_max_sessions_per_peer: 0, listener_self_liveness_check_interval: None, @@ -5521,6 +5520,7 @@ pub unsafe extern "C" fn wallet_create( }, }; + let user_agent = format!("tari/wallet_ffi/{}", env!("CARGO_PKG_VERSION")); let w = runtime.block_on(Wallet::start( wallet_config, peer_seeds, @@ -5537,6 +5537,7 @@ pub unsafe extern "C" fn wallet_create( shutdown.to_signal(), master_seed, WalletType::Software, + user_agent, )); match w { diff --git a/common/config/presets/c_base_node_c.toml b/common/config/presets/c_base_node_c.toml index f0754403f0..c086b27e99 100644 --- a/common/config/presets/c_base_node_c.toml +++ b/common/config/presets/c_base_node_c.toml @@ -150,9 +150,6 @@ track_reorgs = true # Enables periodic socket-level liveness checks. Default: Disabled listener_self_liveness_check_interval = 15 -# User agent string for this node -#user_agent = "" - # The maximum simultaneous comms RPC sessions allowed (default value = 100). Setting this to -1 will allow unlimited # sessions. #rpc_max_simultaneous_sessions = 100 diff --git a/integration_tests/src/chat_client.rs b/integration_tests/src/chat_client.rs index 7993310a05..e14f1cea50 100644 --- a/integration_tests/src/chat_client.rs +++ b/integration_tests/src/chat_client.rs @@ -61,8 +61,8 @@ pub async fn spawn_chat_client(name: &str, seed_peers: Vec, base_dir: Path .map(|p| p.to_short_string()) .collect::>() .into(); - - let mut client = Client::new(identity, config); + let user_agent = format!("tari/integration_tests/{}", env!("CARGO_PKG_VERSION")); + let mut client = Client::new(identity, config, user_agent); client.initialize().await.expect("the chat client to spawn"); client