From 121bff725e7bc4a1789b544afa741c0c053ebcca Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Thu, 23 Aug 2018 15:11:02 +1000 Subject: [PATCH] Tidy client struct --- lighthouse/client/mod.rs | 15 +++++++++++---- lighthouse/main.rs | 4 +--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lighthouse/client/mod.rs b/lighthouse/client/mod.rs index ad6ebb7ca..8474bf105 100644 --- a/lighthouse/client/mod.rs +++ b/lighthouse/client/mod.rs @@ -10,12 +10,19 @@ use super::network_libp2p::state::NetworkState; use super::slog::Logger; use super::sync::start_sync; +/// Represents the co-ordination of the +/// networking, syncing and RPC (not-yet-implemented) threads. pub struct Client { pub db: Arc>, - pub threads: Vec> + pub network_thread: thread::JoinHandle<()>, + pub sync_thread: thread::JoinHandle<()>, } impl Client { + /// Instantiates a new "Client". + /// + /// Presently, this means starting network and sync threads + /// and plumbing them together. pub fn new(config: LighthouseConfig, log: Logger) -> Self @@ -30,8 +37,7 @@ impl Client { let network_state = NetworkState::new( &config.data_dir, &config.p2p_listen_port, - &log).expect("Network setup failed"); - let (network_thread, network_tx, network_rx) = { + &log).expect("Network setup failed"); let (network_thread, network_tx, network_rx) = { let (message_sender, message_receiver) = unbounded(); let (event_sender, event_receiver) = unbounded(); let network_log = log.new(o!()); @@ -68,7 +74,8 @@ impl Client { // Return the client struct Self { db: db, - threads: vec![sync_thread, network_thread] + network_thread, + sync_thread, } } } diff --git a/lighthouse/main.rs b/lighthouse/main.rs index 5bac541aa..867a3ed00 100644 --- a/lighthouse/main.rs +++ b/lighthouse/main.rs @@ -66,9 +66,7 @@ fn main() { "port" => &config.p2p_listen_port); let client = Client::new(config, log.new(o!())); - for thread in client.threads { - thread.join().unwrap(); - } + client.sync_thread.join().unwrap(); info!(log, "Exiting."); }