mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 18:21:45 +00:00
Basic networking service with channel
This commit is contained in:
@@ -22,9 +22,9 @@ use tokio::runtime::TaskExecutor;
|
||||
pub struct Client<T: ClientTypes> {
|
||||
config: ClientConfig,
|
||||
// beacon_chain: Arc<BeaconChain<T, U, F>>,
|
||||
network: Option<Arc<NetworkService>>,
|
||||
exit: exit_future::Exit,
|
||||
exit_signal: Option<Signal>,
|
||||
pub network: Arc<NetworkService>,
|
||||
pub exit: exit_future::Exit,
|
||||
pub exit_signal: Signal,
|
||||
log: slog::Logger,
|
||||
phantom: PhantomData<T>,
|
||||
}
|
||||
@@ -44,14 +44,15 @@ impl<T: ClientTypes> Client<T> {
|
||||
// TODO: Add beacon_chain reference to network parameters
|
||||
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)?;
|
||||
let (network, network_send) =
|
||||
NetworkService::new(network_config, executor, network_logger)?;
|
||||
|
||||
Ok(Client {
|
||||
config,
|
||||
exit,
|
||||
exit_signal: Some(exit_signal),
|
||||
exit_signal: exit_signal,
|
||||
log,
|
||||
network: Some(network),
|
||||
network: network,
|
||||
phantom: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ use db::ClientDB;
|
||||
use exit_future::Exit;
|
||||
use fork_choice::ForkChoice;
|
||||
use futures::{Future, Stream};
|
||||
use network::NodeMessage;
|
||||
use slog::{debug, info, o};
|
||||
use slot_clock::SlotClock;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::runtime::TaskExecutor;
|
||||
use tokio::timer::Interval;
|
||||
@@ -19,9 +20,21 @@ pub fn run<T: ClientTypes>(client: &Client<T>, executor: TaskExecutor, exit: Exi
|
||||
|
||||
let log = client.log.new(o!("Service" => "Notifier"));
|
||||
|
||||
// TODO: Debugging only
|
||||
let counter = Arc::new(Mutex::new(0));
|
||||
let network = client.network.clone();
|
||||
|
||||
// build heartbeat logic here
|
||||
let heartbeat = move |_| {
|
||||
info!(log, "Temp heartbeat output");
|
||||
let mut count = counter.lock().unwrap();
|
||||
*count += 1;
|
||||
|
||||
if *count % 5 == 0 {
|
||||
debug!(log, "Sending Message");
|
||||
network.send_message(String::from("Testing network channel"))
|
||||
}
|
||||
|
||||
Ok(())
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user