[Temp Commit] Implements more basic skeleton code.

This commit is contained in:
Age Manning
2019-03-04 16:39:37 +11:00
parent 2e020a3efa
commit 3b8f29a914
19 changed files with 195 additions and 93 deletions

View File

@@ -1,7 +1,7 @@
use clap::ArgMatches;
use db::DBType;
use fork_choice::ForkChoiceAlgorithm;
use network::NetworkConfiguration;
use network::NetworkConfig;
use slog::error;
use std::fs;
use std::net::IpAddr;
@@ -13,7 +13,7 @@ use types::ChainSpec;
pub struct ClientConfig {
pub data_dir: PathBuf,
pub spec: ChainSpec,
pub net_conf: network::NetworkConfiguration,
pub net_conf: network::NetworkConfig,
pub fork_choice: ForkChoiceAlgorithm,
pub db_type: DBType,
pub db_name: PathBuf,
@@ -34,7 +34,7 @@ impl Default for ClientConfig {
data_dir: data_dir.clone(),
// default to foundation for chain specs
spec: ChainSpec::foundation(),
net_conf: NetworkConfiguration::default(),
net_conf: NetworkConfig::default(),
// default to bitwise LMD Ghost
fork_choice: ForkChoiceAlgorithm::BitwiseLMDGhost,
// default to memory db for now
@@ -53,12 +53,13 @@ impl ClientConfig {
// Network related args
// Custom listening address ipv4/ipv6
// TODO: Handle list of addresses
if let Some(listen_address_str) = args.value_of("listen_address") {
if let Ok(listen_address) = listen_address_str.parse::<IpAddr>() {
config.net_conf.listen_address = Some(listen_address);
config.net_conf.listen_address = Some(Vec::new(listen_address));
} else {
error!(log, "Invalid Ip Address"; "Address" => listen_address_str);
return Err("Invalid Ip Address");
error!(log, "Invalid IP Address"; "Address" => listen_address_str);
return Err("Invalid IP Address");
}
}
// Custom p2p listen port

View File

@@ -13,14 +13,15 @@ pub use client_types::ClientTypes;
use exit_future::{Exit, Signal};
use std::marker::PhantomData;
//use std::sync::Arc;
use network::NetworkService;
use tokio::runtime::TaskExecutor;
//use network::NetworkService;
/// Main beacon node client service. This provides the connection and initialisation of the clients
/// sub-services in multiple threads.
pub struct Client<T: ClientTypes> {
config: ClientConfig,
// beacon_chain: Arc<BeaconChain<T, U, F>>,
// network: Option<Arc<NetworkService>>,
network: Option<Arc<NetworkService>>,
exit: exit_future::Exit,
exit_signal: Option<Signal>,
log: slog::Logger,
@@ -28,6 +29,7 @@ pub struct Client<T: ClientTypes> {
}
impl<T: ClientTypes> Client<T> {
/// Generate an instance of the client. Spawn and link all internal subprocesses.
pub fn new(
config: ClientConfig,
log: slog::Logger,
@@ -35,16 +37,21 @@ impl<T: ClientTypes> Client<T> {
) -> error::Result<Self> {
let (exit_signal, exit) = exit_future::signal();
// TODO: generate a beacon_chain service.
// start the network service, libp2p and syncing threads
// TODO: Add beacon_chain reference to network parameters
let network_config = config.net_config;
let network_logger = client.log.new(o!("Service" => "Network"));
let (network, network_send) = NetworkService::new(network_config, network_logger);
Ok(Client {
config,
exit,
exit_signal: Some(exit_signal),
log,
network: Some(network),
phantom: PhantomData,
})
}
pub fn logger(&self) -> slog::Logger {
self.log.clone()
}
}

2
beacon_node/client/src/notifier.rs Executable file → Normal file
View File

@@ -17,7 +17,7 @@ pub fn run<T: ClientTypes>(client: &Client<T>, executor: TaskExecutor, exit: Exi
// notification heartbeat
let interval = Interval::new(Instant::now(), Duration::from_secs(5));
let log = client.logger();
let log = client.log.new(o!("Service" => "Notifier"));
// build heartbeat logic here
let heartbeat = move |_| {