From 67a3dfe05218085c56e49fd333368917cb67ac23 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Thu, 21 Mar 2019 12:45:23 +1100 Subject: [PATCH] Remove node private key from config --- beacon_node/eth2-libp2p/src/config.rs | 75 ++++++++++++++++++++++++++ beacon_node/eth2-libp2p/src/service.rs | 6 ++- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 beacon_node/eth2-libp2p/src/config.rs diff --git a/beacon_node/eth2-libp2p/src/config.rs b/beacon_node/eth2-libp2p/src/config.rs new file mode 100644 index 0000000000..a86045b78b --- /dev/null +++ b/beacon_node/eth2-libp2p/src/config.rs @@ -0,0 +1,75 @@ +use crate::Multiaddr; +use libp2p::gossipsub::{GossipsubConfig, GossipsubConfigBuilder}; + +#[derive(Clone, Debug)] +/// Network configuration for lighthouse. +pub struct Config { + //TODO: stubbing networking initial params, change in the future + /// IP address to listen on. + pub listen_addresses: Vec, + /// Listen port UDP/TCP. + pub listen_port: u16, + /// Gossipsub configuration parameters. + pub gs_config: GossipsubConfig, + /// Configuration parameters for node identification protocol. + pub identify_config: IdentifyConfig, + /// List of nodes to initially connect to. + pub boot_nodes: Vec, + /// Client version + pub client_version: String, + /// List of topics to subscribe to as strings + pub topics: Vec, +} + +impl Default for Config { + /// Generate a default network configuration. + fn default() -> Self { + Config { + listen_addresses: vec!["/ip4/127.0.0.1/tcp/9000" + .parse() + .expect("is a correct multi-address")], + listen_port: 9000, + gs_config: GossipsubConfigBuilder::new().build(), + identify_config: IdentifyConfig::new(&version::version()), + boot_nodes: Vec::new(), + client_version: version::version(), + topics: vec![String::from("beacon_chain")], + } + } +} + +impl Config { + pub fn new(boot_nodes: Vec) -> Self { + let mut conf = Config::default(); + conf.boot_nodes = boot_nodes; + + conf + } +} + +/// The configuration parameters for the Identify protocol +#[derive(Debug, Clone)] +pub struct IdentifyConfig { + /// The protocol version to listen on. + pub version: String, + /// The client's name and version for identification. + pub user_agent: String, +} + +impl Default for IdentifyConfig { + fn default() -> Self { + Self { + version: "/eth/serenity/1.0".to_string(), + user_agent: "Lighthouse".to_string(), + } + } +} + +impl IdentifyConfig { + /// Adds the version to the user agent. + pub fn new(version: &String) -> Self { + let mut config = IdentifyConfig::default(); + config.user_agent += version; + config + } +} diff --git a/beacon_node/eth2-libp2p/src/service.rs b/beacon_node/eth2-libp2p/src/service.rs index 7a39378834..ca20465a6a 100644 --- a/beacon_node/eth2-libp2p/src/service.rs +++ b/beacon_node/eth2-libp2p/src/service.rs @@ -33,7 +33,11 @@ impl Service { pub fn new(config: NetworkConfig, log: slog::Logger) -> error::Result { debug!(log, "Libp2p Service starting"); - let local_private_key = config.local_private_key.clone(); + // TODO: Currently using secp256k1 key pairs. Wire protocol specifies RSA. Waiting for this + // PR to be merged to generate RSA keys: https://github.com/briansmith/ring/pull/733 + // TODO: Save and recover node key from disk + let local_private_key = secio::SecioKeyPair::secp256k1_generated().unwrap(); + let local_public_key = local_private_key.to_public_key(); let local_peer_id = local_private_key.to_peer_id(); info!(log, "Local peer id: {:?}", local_peer_id);