mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 16:51:41 +00:00
Add websocket config to CLI
This commit is contained in:
@@ -8,6 +8,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
beacon_chain = { path = "../beacon_chain" }
|
||||
clap = "2.32.0"
|
||||
exit-future = "0.1.3"
|
||||
futures = "0.1.25"
|
||||
serde = "1.0"
|
||||
|
||||
45
beacon_node/websocket_server/src/config.rs
Normal file
45
beacon_node/websocket_server/src/config.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use clap::ArgMatches;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
/// The core configuration of a Lighthouse beacon node.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub enabled: bool,
|
||||
/// The IPv4 address the REST API HTTP server will listen on.
|
||||
pub listen_address: Ipv4Addr,
|
||||
/// The port the REST API HTTP server will listen on.
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Config {
|
||||
enabled: true,
|
||||
listen_address: Ipv4Addr::new(127, 0, 0, 1),
|
||||
port: 5053,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn apply_cli_args(&mut self, args: &ArgMatches) -> Result<(), &'static str> {
|
||||
if args.is_present("no-ws") {
|
||||
self.enabled = false;
|
||||
}
|
||||
|
||||
if let Some(rpc_address) = args.value_of("ws-address") {
|
||||
self.listen_address = rpc_address
|
||||
.parse::<Ipv4Addr>()
|
||||
.map_err(|_| "ws-address is not a valid IPv4 address.")?;
|
||||
}
|
||||
|
||||
if let Some(rpc_port) = args.value_of("ws-port") {
|
||||
self.port = rpc_port
|
||||
.parse::<u16>()
|
||||
.map_err(|_| "ws-port is not a valid u16.")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,13 @@
|
||||
use beacon_chain::events::{EventHandler, EventKind};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use slog::{error, info, Logger};
|
||||
use std::marker::PhantomData;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::thread;
|
||||
use types::EthSpec;
|
||||
use ws::{Sender, WebSocket};
|
||||
|
||||
/// The core configuration of a Lighthouse beacon node.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub enabled: bool,
|
||||
/// The IPv4 address the REST API HTTP server will listen on.
|
||||
pub listen_address: Ipv4Addr,
|
||||
/// The port the REST API HTTP server will listen on.
|
||||
pub port: u16,
|
||||
}
|
||||
mod config;
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Config {
|
||||
enabled: true,
|
||||
listen_address: Ipv4Addr::new(127, 0, 0, 1),
|
||||
port: 5053,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub use config::Config;
|
||||
|
||||
pub struct WebSocketSender<T: EthSpec> {
|
||||
sender: Option<Sender>,
|
||||
|
||||
Reference in New Issue
Block a user