From c718e81eaf0c01bf8905c1d4947db1924269f1ce Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 30 Nov 2020 22:55:08 +0000 Subject: [PATCH] Add privacy option (#2016) Adds a `--privacy` CLI flag to the beacon node that users may opt into. This does two things: - Removes client identifying information from the identify libp2p protocol - Changes the default graffiti to "" if no graffiti is set. --- beacon_node/eth2_libp2p/src/behaviour/mod.rs | 18 +++++++++++++----- beacon_node/eth2_libp2p/src/config.rs | 5 +++++ beacon_node/src/cli.rs | 6 ++++++ beacon_node/src/config.rs | 6 ++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/beacon_node/eth2_libp2p/src/behaviour/mod.rs b/beacon_node/eth2_libp2p/src/behaviour/mod.rs index e09a34980..55e295661 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/mod.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/mod.rs @@ -151,11 +151,19 @@ impl Behaviour { ) -> error::Result { let behaviour_log = log.new(o!()); - let identify = Identify::new( - "lighthouse/libp2p".into(), - lighthouse_version::version_with_platform(), - local_key.public(), - ); + let identify = if net_conf.private { + Identify::new( + "".into(), + "".into(), + local_key.public(), // Still send legitimate public key + ) + } else { + Identify::new( + "lighthouse/libp2p".into(), + lighthouse_version::version_with_platform(), + local_key.public(), + ) + }; let enr_fork_id = network_globals .local_enr() diff --git a/beacon_node/eth2_libp2p/src/config.rs b/beacon_node/eth2_libp2p/src/config.rs index 8f2f2c16e..f9ce72059 100644 --- a/beacon_node/eth2_libp2p/src/config.rs +++ b/beacon_node/eth2_libp2p/src/config.rs @@ -88,6 +88,10 @@ pub struct Config { /// runtime. pub import_all_attestations: bool, + /// Indicates if the user has set the network to be in private mode. Currently this + /// prevents sending client identifying information over identify. + pub private: bool, + /// List of extra topics to initially subscribe to as strings. pub topics: Vec, } @@ -188,6 +192,7 @@ impl Default for Config { client_version: lighthouse_version::version_with_platform(), disable_discovery: false, upnp_enabled: true, + private: false, subscribe_all_subnets: false, import_all_attestations: false, topics: Vec::new(), diff --git a/beacon_node/src/cli.rs b/beacon_node/src/cli.rs index 233135d0b..492c8ceb6 100644 --- a/beacon_node/src/cli.rs +++ b/beacon_node/src/cli.rs @@ -97,6 +97,12 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { .help("Disables UPnP support. Setting this will prevent Lighthouse from attempting to automatically establish external port mappings.") .takes_value(false), ) + .arg( + Arg::with_name("private") + .long("private") + .help("Prevents sending various client identification information.") + .takes_value(false), + ) .arg( Arg::with_name("enr-udp-port") .long("enr-udp-port") diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 367d43e10..c9645bbb4 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -305,6 +305,8 @@ pub fn get_config( } graffiti.as_bytes() + } else if cli_args.is_present("private") { + b"" } else { lighthouse_version::VERSION.as_bytes() }; @@ -577,6 +579,10 @@ pub fn set_network_config( config.upnp_enabled = false; } + if cli_args.is_present("private") { + config.private = true; + } + Ok(()) }