[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

@@ -0,0 +1,8 @@
// generates error types
use error_chain::{
error_chain, error_chain_processing, impl_error_chain_kind, impl_error_chain_processed,
impl_extract_backtrace,
};
error_chain! {}

View File

@@ -1,4 +1,6 @@
/// This crate provides the network server for Lighthouse.
mod network_configuration;
mod network_config;
mod service;
pub use network_configuration::NetworkConfiguration;
pub use network_config::NetworkConfig;
pub use service::NetworkService;

View File

@@ -0,0 +1,18 @@
use crate::node_message::NodeMessage;
/// Handles messages received from the network and client and organises syncing.
pub struct MessageHandler {
sync: Syncer,
//TODO: Implement beacon chain
//chain: BeaconChain
}
/// Types of messages the handler can receive.
pub enum HandlerMessage {
/// Peer has connected.
PeerConnected(PeerId),
/// Peer has disconnected,
PeerDisconnected(PeerId),
/// A Node message has been received.
Message(Peer, NodeMessage),
}

View File

@@ -0,0 +1,27 @@
use types::{H256,Slot}
/// Messages between nodes across the network.
pub enum NodeMessage {
Status(Status),
BlockRequest,
}
pub struct Status {
/// Current node version.
version: u8
/// Genesis Hash.
genesis_hash: H256
/// Best known slot number.
best_slot: Slot
/// Best known slot hash.
best_slot_hash: H256
}
/// Types of messages that the network service can receive.
pub enum NetworkMessage {
/// Send a message to libp2p service.
//TODO: Define typing for messages accross the wire
Send(Node, Message),
}

View File

@@ -4,10 +4,10 @@ use version;
#[derive(Debug, Clone)]
/// Network configuration for lighthouse.
pub struct NetworkConfiguration {
pub struct NetworkConfig {
//TODO: stubbing networking initial params, change in the future
/// IP address to listen on.
pub listen_address: Option<IpAddr>,
pub listen_addresses: Option<Vec<IpAddr>>,
/// Listen port UDP/TCP.
pub listen_port: Option<u16>,
/// Gossipsub configuration parameters.
@@ -16,14 +16,13 @@ pub struct NetworkConfiguration {
pub boot_nodes: Vec<String>,
/// Client version
pub client_version: String,
//TODO: more to be added
}
impl Default for NetworkConfiguration {
impl Default for NetworkConfig {
/// Generate a default network configuration.
fn default() -> Self {
NetworkConfiguration {
listen_address: None,
NetworkConfig {
listen_addresses: None,
listen_port: None,
gs_config: GossipsubConfigBuilder::new().build(),
boot_nodes: Vec::new(),
@@ -32,8 +31,8 @@ impl Default for NetworkConfiguration {
}
}
impl NetworkConfiguration {
impl NetworkConfig {
pub fn new() -> Self {
NetworkConfiguration::default()
NetworkConfig::default()
}
}

View File