2019-03-01 01:45:01 +00:00
|
|
|
extern crate slog;
|
|
|
|
|
|
|
|
mod client_config;
|
|
|
|
|
|
|
|
pub mod client_types;
|
|
|
|
pub mod error;
|
|
|
|
pub mod notifier;
|
|
|
|
|
|
|
|
pub use client_config::ClientConfig;
|
|
|
|
pub use client_types::ClientTypes;
|
|
|
|
|
|
|
|
//use beacon_chain::BeaconChain;
|
|
|
|
use exit_future::{Exit, Signal};
|
2019-03-04 07:31:01 +00:00
|
|
|
use network::Service as NetworkService;
|
|
|
|
use slog::o;
|
2019-03-01 01:45:01 +00:00
|
|
|
use std::marker::PhantomData;
|
2019-03-04 07:31:01 +00:00
|
|
|
use std::sync::Arc;
|
2019-03-01 01:45:01 +00:00
|
|
|
use tokio::runtime::TaskExecutor;
|
|
|
|
|
2019-03-04 05:39:37 +00:00
|
|
|
/// Main beacon node client service. This provides the connection and initialisation of the clients
|
|
|
|
/// sub-services in multiple threads.
|
2019-03-01 01:45:01 +00:00
|
|
|
pub struct Client<T: ClientTypes> {
|
|
|
|
config: ClientConfig,
|
|
|
|
// beacon_chain: Arc<BeaconChain<T, U, F>>,
|
2019-03-04 05:39:37 +00:00
|
|
|
network: Option<Arc<NetworkService>>,
|
2019-03-01 01:45:01 +00:00
|
|
|
exit: exit_future::Exit,
|
|
|
|
exit_signal: Option<Signal>,
|
|
|
|
log: slog::Logger,
|
|
|
|
phantom: PhantomData<T>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: ClientTypes> Client<T> {
|
2019-03-04 05:39:37 +00:00
|
|
|
/// Generate an instance of the client. Spawn and link all internal subprocesses.
|
2019-03-01 01:45:01 +00:00
|
|
|
pub fn new(
|
|
|
|
config: ClientConfig,
|
|
|
|
log: slog::Logger,
|
|
|
|
executor: TaskExecutor,
|
|
|
|
) -> error::Result<Self> {
|
|
|
|
let (exit_signal, exit) = exit_future::signal();
|
|
|
|
|
2019-03-04 05:39:37 +00:00
|
|
|
// TODO: generate a beacon_chain service.
|
|
|
|
|
2019-03-04 07:31:01 +00:00
|
|
|
// Start the network service, libp2p and syncing threads
|
2019-03-04 05:39:37 +00:00
|
|
|
// TODO: Add beacon_chain reference to network parameters
|
2019-03-04 07:31:01 +00:00
|
|
|
let network_config = config.net_conf.clone();
|
|
|
|
let network_logger = log.new(o!("Service" => "Network"));
|
|
|
|
let (network, network_send) = NetworkService::new(network_config, network_logger)?;
|
2019-03-04 05:39:37 +00:00
|
|
|
|
2019-03-01 01:45:01 +00:00
|
|
|
Ok(Client {
|
|
|
|
config,
|
|
|
|
exit,
|
|
|
|
exit_signal: Some(exit_signal),
|
|
|
|
log,
|
2019-03-04 05:39:37 +00:00
|
|
|
network: Some(network),
|
2019-03-01 01:45:01 +00:00
|
|
|
phantom: PhantomData,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|