Tidy networking crates
This commit is contained in:
parent
dc014d07bc
commit
e7f87112fb
@ -3,7 +3,7 @@ use beacon_chain::{
|
||||
db::{ClientDB, DiskDB, MemoryDB},
|
||||
fork_choice::BitwiseLMDGhost,
|
||||
initialise,
|
||||
slot_clock::{SlotClock, SystemTimeSlotClock, TestingSlotClock},
|
||||
slot_clock::{SlotClock, SystemTimeSlotClock},
|
||||
BeaconChain,
|
||||
};
|
||||
use fork_choice::ForkChoice;
|
||||
|
@ -11,7 +11,7 @@ pub use client_types::ClientTypes;
|
||||
|
||||
//use beacon_chain::BeaconChain;
|
||||
use beacon_chain::BeaconChain;
|
||||
use exit_future::{Exit, Signal};
|
||||
use exit_future::Signal;
|
||||
use network::Service as NetworkService;
|
||||
use slog::o;
|
||||
use std::marker::PhantomData;
|
||||
@ -55,7 +55,7 @@ impl<TClientType: ClientTypes> Client<TClientType> {
|
||||
// TODO: Add beacon_chain reference to network parameters
|
||||
let network_config = &config.net_conf;
|
||||
let network_logger = log.new(o!("Service" => "Network"));
|
||||
let (network, network_send) = NetworkService::new(
|
||||
let (network, _network_send) = NetworkService::new(
|
||||
beacon_chain.clone(),
|
||||
network_config,
|
||||
executor,
|
||||
|
@ -1,12 +1,8 @@
|
||||
use crate::Client;
|
||||
use crate::ClientTypes;
|
||||
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, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::runtime::TaskExecutor;
|
||||
@ -27,12 +23,13 @@ pub fn run<T: ClientTypes>(client: &Client<T>, executor: TaskExecutor, exit: Exi
|
||||
// build heartbeat logic here
|
||||
let heartbeat = move |_| {
|
||||
info!(log, "Temp heartbeat output");
|
||||
//TODO: Remove this logic. Testing only
|
||||
let mut count = counter.lock().unwrap();
|
||||
*count += 1;
|
||||
|
||||
if *count % 5 == 0 {
|
||||
debug!(log, "Sending Message");
|
||||
network.send_message(String::from("Testing network channel"))
|
||||
network.send_message();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -2,10 +2,8 @@
|
||||
pub mod beacon_chain;
|
||||
pub mod error;
|
||||
mod message_handler;
|
||||
mod messages;
|
||||
mod service;
|
||||
pub mod sync;
|
||||
|
||||
pub use libp2p::NetworkConfig;
|
||||
pub use messages::NodeMessage;
|
||||
pub use service::Service;
|
||||
|
@ -1,11 +1,9 @@
|
||||
use crate::beacon_chain::BeaconChain;
|
||||
use crate::error;
|
||||
use crate::messages::NodeMessage;
|
||||
use crate::service::{NetworkMessage, OutgoingMessage};
|
||||
use crate::sync::SimpleSync;
|
||||
use crossbeam_channel::{unbounded as channel, Sender};
|
||||
use futures::future;
|
||||
use futures::prelude::*;
|
||||
use libp2p::{
|
||||
rpc::{RPCMethod, RPCRequest, RPCResponse},
|
||||
HelloMessage, PeerId, RPCEvent,
|
||||
@ -15,7 +13,6 @@ use slog::{debug, trace};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
use types::Hash256;
|
||||
|
||||
/// Timeout for RPC requests.
|
||||
const REQUEST_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
@ -45,8 +42,6 @@ pub enum HandlerMessage {
|
||||
PeerDialed(PeerId),
|
||||
/// Peer has disconnected,
|
||||
PeerDisconnected(PeerId),
|
||||
/// A Node message has been received.
|
||||
Message(PeerId, NodeMessage),
|
||||
/// An RPC response/request has been received.
|
||||
RPC(PeerId, RPCEvent),
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
use libp2p::PeerId;
|
||||
use libp2p::{HelloMessage, RPCEvent};
|
||||
use types::{Hash256, Slot};
|
||||
|
||||
//TODO: This module can be entirely replaced in the RPC rewrite
|
||||
|
||||
/// Messages between nodes across the network.
|
||||
//TODO: Remove this in the RPC rewrite
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum NodeMessage {
|
||||
RPC(RPCEvent),
|
||||
BlockRequest,
|
||||
// TODO: only for testing - remove
|
||||
Message(String),
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
use crate::beacon_chain::BeaconChain;
|
||||
use crate::error;
|
||||
use crate::message_handler::{HandlerMessage, MessageHandler};
|
||||
use crate::messages::NodeMessage;
|
||||
use crate::NetworkConfig;
|
||||
use crossbeam_channel::{unbounded as channel, Sender, TryRecvError};
|
||||
use futures::prelude::*;
|
||||
@ -53,21 +52,22 @@ impl Service {
|
||||
executor,
|
||||
log,
|
||||
)?;
|
||||
let network = Service {
|
||||
let network_service = Service {
|
||||
libp2p_exit,
|
||||
network_send: network_send.clone(),
|
||||
};
|
||||
|
||||
Ok((Arc::new(network), network_send))
|
||||
Ok((Arc::new(network_service), network_send))
|
||||
}
|
||||
|
||||
// TODO: Testing only
|
||||
pub fn send_message(&self, message: String) {
|
||||
let node_message = NodeMessage::Message(message);
|
||||
self.network_send.send(NetworkMessage::Send(
|
||||
PeerId::random(),
|
||||
OutgoingMessage::NotifierTest,
|
||||
));
|
||||
pub fn send_message(&self) {
|
||||
self.network_send
|
||||
.send(NetworkMessage::Send(
|
||||
PeerId::random(),
|
||||
OutgoingMessage::NotifierTest,
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ mod run;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use client::ClientConfig;
|
||||
use slog::{o, Drain};
|
||||
use slog::{error, o, Drain};
|
||||
|
||||
fn main() {
|
||||
let decorator = slog_term::TermDecorator::new().build();
|
||||
@ -42,5 +42,8 @@ fn main() {
|
||||
// invalid arguments, panic
|
||||
let config = ClientConfig::parse_args(matches, &logger).unwrap();
|
||||
|
||||
run::run_beacon_node(config, logger);
|
||||
match run::run_beacon_node(config, &logger) {
|
||||
Ok(_) => {}
|
||||
Err(e) => error!(logger, "Beacon node failed because {:?}", e),
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use client::client_types::{StandardClientType, TestingClientType};
|
||||
use client::client_types::TestingClientType;
|
||||
use client::error;
|
||||
use client::{notifier, Client, ClientConfig};
|
||||
use futures::sync::oneshot;
|
||||
@ -7,7 +7,7 @@ use slog::info;
|
||||
use std::cell::RefCell;
|
||||
use tokio::runtime::Builder;
|
||||
|
||||
pub fn run_beacon_node(config: ClientConfig, log: slog::Logger) -> error::Result<()> {
|
||||
pub fn run_beacon_node(config: ClientConfig, log: &slog::Logger) -> error::Result<()> {
|
||||
let mut runtime = Builder::new()
|
||||
.name_prefix("main-")
|
||||
.build()
|
||||
@ -25,7 +25,8 @@ pub fn run_beacon_node(config: ClientConfig, log: slog::Logger) -> error::Result
|
||||
if let Some(ctrlc_send) = ctrlc_send_c.try_borrow_mut().unwrap().take() {
|
||||
ctrlc_send.send(()).expect("Error sending ctrl-c message");
|
||||
}
|
||||
});
|
||||
})
|
||||
.map_err(|e| format!("Could not set ctrlc hander: {:?}", e))?;
|
||||
|
||||
let (exit_signal, exit) = exit_future::signal();
|
||||
|
||||
@ -35,7 +36,9 @@ pub fn run_beacon_node(config: ClientConfig, log: slog::Logger) -> error::Result
|
||||
let client: Client<TestingClientType> = Client::new(config, log.clone(), &executor)?;
|
||||
notifier::run(&client, executor, exit);
|
||||
|
||||
runtime.block_on(ctrlc);
|
||||
runtime
|
||||
.block_on(ctrlc)
|
||||
.map_err(|e| format!("Ctrlc oneshot failed: {:?}", e))?;
|
||||
|
||||
// perform global shutdown operations.
|
||||
info!(log, "Shutting down..");
|
||||
|
Loading…
Reference in New Issue
Block a user