Remove node private key from config

This commit is contained in:
Age Manning 2019-03-21 12:45:23 +11:00
parent 7ec37939c8
commit 67a3dfe052
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93
2 changed files with 80 additions and 1 deletions

View File

@ -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<Multiaddr>,
/// 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<Multiaddr>,
/// Client version
pub client_version: String,
/// List of topics to subscribe to as strings
pub topics: Vec<String>,
}
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<Multiaddr>) -> 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
}
}

View File

@ -33,7 +33,11 @@ impl Service {
pub fn new(config: NetworkConfig, log: slog::Logger) -> error::Result<Self> {
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);