From 31b62e2e767ccab8f90d3d39c99331ec4320ec04 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 13 Apr 2023 13:10:13 +0200 Subject: [PATCH 1/3] Rename ClientConfig::system_* options to client_* --- light-base/examples/basic.rs | 4 ++-- light-base/src/lib.rs | 30 ++++++++++++++---------------- wasm-node/rust/src/init.rs | 4 ++-- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/light-base/examples/basic.rs b/light-base/examples/basic.rs index 82768f1bf2..c0075cedd6 100644 --- a/light-base/examples/basic.rs +++ b/light-base/examples/basic.rs @@ -36,8 +36,8 @@ fn main() { tasks_spawner: Box::new(move |_name, task| { async_std::task::spawn(task); }), - system_name: env!("CARGO_PKG_NAME").into(), - system_version: env!("CARGO_PKG_VERSION").into(), + client_name: env!("CARGO_PKG_NAME").into(), + client_version: env!("CARGO_PKG_VERSION").into(), }); // Ask the client to connect to a chain. diff --git a/light-base/src/lib.rs b/light-base/src/lib.rs index 9af0744a3e..7ce1788714 100644 --- a/light-base/src/lib.rs +++ b/light-base/src/lib.rs @@ -106,13 +106,13 @@ pub struct ClientConfig { /// The first parameter is the name of the task, which can be useful for debugging purposes. pub tasks_spawner: Box) + Send + Sync>, - /// Value returned when a JSON-RPC client requests the name of the client. Reasonable value - /// is `env!("CARGO_PKG_NAME")`. - pub system_name: String, + /// Value returned when a JSON-RPC client requests the name of the client, or when a peer + /// performs an identification request. Reasonable value is `env!("CARGO_PKG_NAME")`. + pub client_name: String, - /// Value returned when a JSON-RPC client requests the version of the client. Reasonable value - /// is `env!("CARGO_PKG_VERSION")`. - pub system_version: String, + /// Value returned when a JSON-RPC client requests the version of the client, or when a peer + /// performs an identification request. Reasonable value is `env!("CARGO_PKG_VERSION")`. + pub client_version: String, } /// See [`Client::add_chain`]. @@ -178,13 +178,11 @@ pub struct Client { // TODO: use SipHasher chains_by_key: HashMap, fnv::FnvBuildHasher>, - /// Value to return when the `system_name` RPC is called. Should be set to the name of the - /// final executable. - system_name: String, + /// See [`ClientConfig::client_name`]. + client_name: String, - /// Value to return when the `system_version` RPC is called. Should be set to the version of - /// the final executable. - system_version: String, + /// See [`ClientConfig::client_version`]. + client_version: String, } struct PublicApiChain { @@ -322,8 +320,8 @@ impl Client { spawn_new_task: config.tasks_spawner.into(), public_api_chains: slab::Slab::with_capacity(expected_chains), chains_by_key: HashMap::with_capacity_and_hasher(expected_chains, Default::default()), - system_name: config.system_name, - system_version: config.system_version, + client_name: config.client_name, + client_version: config.client_version, } } @@ -825,8 +823,8 @@ impl Client { }); let spawn_new_task = self.spawn_new_task.clone(); - let system_name = self.system_name.clone(); - let system_version = self.system_version.clone(); + let system_name = self.client_name.clone(); + let system_version = self.client_version.clone(); let init_future = async move { // Wait for the chain to finish initializing before starting the JSON-RPC service. diff --git a/wasm-node/rust/src/init.rs b/wasm-node/rust/src/init.rs index 9e8540ffc5..5115d7809c 100644 --- a/wasm-node/rust/src/init.rs +++ b/wasm-node/rust/src/init.rs @@ -203,8 +203,8 @@ pub(crate) fn init( tasks_spawner: Box::new(move |name, task| { new_task_tx.unbounded_send((name, task)).unwrap() }), - system_name: env!("CARGO_PKG_NAME").into(), - system_version: env!("CARGO_PKG_VERSION").into(), + client_name: env!("CARGO_PKG_NAME").into(), + client_version: env!("CARGO_PKG_VERSION").into(), }); Client { From 844c62274cc1ce7d592da70b50f30287cd1da2e9 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 13 Apr 2023 13:20:39 +0200 Subject: [PATCH 2/3] Send back name and version to identify requests --- full-node/src/run.rs | 1 + full-node/src/run/network_service.rs | 11 ++++++++++- light-base/src/lib.rs | 7 +++++++ light-base/src/network_service.rs | 11 ++++++++++- wasm-node/CHANGELOG.md | 4 ++++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/full-node/src/run.rs b/full-node/src/run.rs index 90974b99c3..c64cc5b991 100644 --- a/full-node/src/run.rs +++ b/full-node/src/run.rs @@ -433,6 +433,7 @@ pub async fn run(cli_options: cli::CliOptionsRun) { .into_iter(), ) .collect(), + identify_agent_version: concat!(env!("CARGO_PKG_NAME"), " ", env!("CARGO_PKG_VERSION")).to_owned(), noise_key, tasks_executor: &mut |task| threads_pool.spawn_ok(task), jaeger_service: jaeger_service.clone(), diff --git a/full-node/src/run/network_service.rs b/full-node/src/run/network_service.rs index 25b8cc6ab9..324b67f1d6 100644 --- a/full-node/src/run/network_service.rs +++ b/full-node/src/run/network_service.rs @@ -74,6 +74,9 @@ pub struct Config<'a> { /// List of block chains to be connected to. pub chains: Vec, + /// Value sent back for the agent version when receiving an identification request. + pub identify_agent_version: String, + /// Key used for the encryption layer. /// This is a Noise static key, according to the Noise specification. /// Signed using the actual libp2p key. @@ -144,6 +147,9 @@ struct Inner { /// Fields behind a mutex. guarded: Mutex, + /// Value provided through [`Config::identify_agent_version`]. + identify_agent_version: String, + /// Event to notify when the background task needs to be waken up. /// /// Waking up this event guarantees a full loop of the background task. In other words, @@ -274,6 +280,7 @@ impl NetworkService { *network.noise_key().libp2p_public_ed25519_key(), ) .into_peer_id(), + identify_agent_version: config.identify_agent_version, wake_up_main_background_task: event_listener::Event::new(), databases, guarded: Mutex::new(Guarded { @@ -896,7 +903,9 @@ async fn update_round(inner: &Arc, event_senders: &mut [mpsc::Sender { log::debug!("identify-request; peer_id={}", peer_id); - guarded.network.respond_identify(request_id, "smoldot"); + guarded + .network + .respond_identify(request_id, &inner.identify_agent_version); } service::Event::BlocksRequestIn { peer_id, diff --git a/light-base/src/lib.rs b/light-base/src/lib.rs index 7ce1788714..a6e4c009a1 100644 --- a/light-base/src/lib.rs +++ b/light-base/src/lib.rs @@ -632,6 +632,10 @@ impl Client { // peer-to-peer network. let network_noise_key = connection::NoiseKey::new(&rand::random()); + // Version of the client when requested through the networking. + let network_identify_agent_version = + format!("{} {}", self.client_name, self.client_version); + // Spawn a background task that initializes the services of the new chain and // yields a `ChainServices`. let running_chain_init_future: future::RemoteHandle> = { @@ -673,6 +677,7 @@ impl Client { .scale_encoding_vec(chain_spec.block_number_bytes().into()), chain_spec, relay_chain.as_ref().map(|(r, _)| r), + network_identify_agent_version, network_noise_key, ) .await; @@ -999,6 +1004,7 @@ async fn start_services( genesis_block_scale_encoded_header: Vec, chain_spec: chain_spec::ChainSpec, relay_chain: Option<&ChainServices>, + network_identify_agent_version: String, network_noise_key: connection::NoiseKey, ) -> ChainServices { // Since `network_noise_key` is moved out below, use it to build the network identity ahead @@ -1014,6 +1020,7 @@ async fn start_services( move |name, fut| spawn_new_task(name, fut) }), num_events_receivers: 1, // Configures the length of `network_event_receivers` + identify_agent_version: network_identify_agent_version, noise_key: network_noise_key, chains: vec![network_service::ConfigChain { log_name: log_name.clone(), diff --git a/light-base/src/network_service.rs b/light-base/src/network_service.rs index 5a8c8d9f02..7bbb04d44b 100644 --- a/light-base/src/network_service.rs +++ b/light-base/src/network_service.rs @@ -69,6 +69,9 @@ pub struct Config { /// Closure that spawns background tasks. pub tasks_executor: Box) + Send>, + /// Value sent back for the agent version when receiving an identification request. + pub identify_agent_version: String, + /// Key to use for the encryption layer of all the connections. Gives the node its identity. pub noise_key: connection::NoiseKey, @@ -126,6 +129,9 @@ struct Shared { /// Fields protected by a mutex. guarded: Mutex>, + /// Value provided through [`Config::identify_agent_version`]. + identify_agent_version: String, + /// Names of the various chains the network service connects to. Used only for logging /// purposes. log_chain_names: Vec, @@ -272,6 +278,7 @@ impl NetworkService { Default::default(), ), }), + identify_agent_version: config.identify_agent_version, log_chain_names, wake_up_main_background_task: event_listener::Event::new(), }); @@ -1222,7 +1229,9 @@ async fn update_round( "Connection({}) => IdentifyRequest", peer_id, ); - guarded.network.respond_identify(request_id, "smoldot"); + guarded + .network + .respond_identify(request_id, &shared.identify_agent_version); } service::Event::BlocksRequestIn { .. } => unreachable!(), service::Event::RequestInCancel { .. } => { diff --git a/wasm-node/CHANGELOG.md b/wasm-node/CHANGELOG.md index 2c47f2e801..f2fed6909a 100644 --- a/wasm-node/CHANGELOG.md +++ b/wasm-node/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Changed + +- When receiving an identify request through the libp2p protocol, smoldot now sends back `smoldot-light-wasm vX.X.X` (with proper version numbers) as its agent name and version, instead of previously just `smoldot`. + ## 1.0.2 - 2023-04-12 ### Changed From 7aa35acb2578b7459872411320dac0c39f52b69a Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 13 Apr 2023 13:21:28 +0200 Subject: [PATCH 3/3] CHANGELOG PR link --- wasm-node/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm-node/CHANGELOG.md b/wasm-node/CHANGELOG.md index f2fed6909a..5704587349 100644 --- a/wasm-node/CHANGELOG.md +++ b/wasm-node/CHANGELOG.md @@ -4,7 +4,7 @@ ### Changed -- When receiving an identify request through the libp2p protocol, smoldot now sends back `smoldot-light-wasm vX.X.X` (with proper version numbers) as its agent name and version, instead of previously just `smoldot`. +- When receiving an identify request through the libp2p protocol, smoldot now sends back `smoldot-light-wasm vX.X.X` (with proper version numbers) as its agent name and version, instead of previously just `smoldot`. ([#417](https://github.com/smol-dot/smoldot/pull/417)) ## 1.0.2 - 2023-04-12