mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 13:24:44 +00:00
[Temp Commit] Implements more basic skeleton code.
This commit is contained in:
8
beacon_node/network/src/error.rs
Normal file
8
beacon_node/network/src/error.rs
Normal 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! {}
|
||||
@@ -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;
|
||||
|
||||
18
beacon_node/network/src/message_handler.rs
Normal file
18
beacon_node/network/src/message_handler.rs
Normal 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),
|
||||
}
|
||||
27
beacon_node/network/src/messages.rs
Normal file
27
beacon_node/network/src/messages.rs
Normal 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),
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
0
beacon_node/network/src/service.rs
Normal file
0
beacon_node/network/src/service.rs
Normal file
Reference in New Issue
Block a user