From 05c1e9c771fcf68b17df98933adc71c93b597814 Mon Sep 17 00:00:00 2001 From: Jim Posen Date: Wed, 6 Jun 2018 14:19:12 -0700 Subject: [PATCH] Include node identity in the P2P advertised client version. --- parity/configuration.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/parity/configuration.rs b/parity/configuration.rs index 2b8bd820f18..bbf92d31209 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -754,7 +754,15 @@ impl Configuration { ret.config_path = Some(net_path.to_str().unwrap().to_owned()); ret.reserved_nodes = self.init_reserved_nodes()?; ret.allow_non_reserved = !self.args.flag_reserved_only; - ret.client_version = version(); + ret.client_version = { + let mut client_version = version(); + if !self.args.arg_identity.is_empty() { + // Insert name after the "Parity/" at the beginning of version string. + let idx = client_version.find('/').unwrap_or(client_version.len()); + client_version.insert_str(idx, &format!("/{}", self.args.arg_identity)); + } + client_version + }; Ok(ret) } @@ -1787,6 +1795,19 @@ mod tests { } } + #[test] + fn test_identity_arg() { + let args = vec!["parity", "--identity", "Somebody"]; + let conf = Configuration::parse_cli(&args).unwrap(); + match conf.into_command().unwrap().cmd { + Cmd::Run(c) => { + assert_eq!(c.name, "Somebody"); + assert!(c.net_conf.client_version.starts_with("Parity/Somebody/")); + } + _ => panic!("Should be Cmd::Run"), + } + } + #[test] fn should_apply_ports_shift() { // given