Added an option to save current node status to file.
This commit is contained in:
+22
-2
@@ -16,8 +16,8 @@ use simplelog::*;
|
||||
use winapi::um::wincon::{AttachConsole, FreeConsole, ATTACH_PARENT_PROCESS};
|
||||
extern crate lazy_static;
|
||||
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::{Seek, SeekFrom};
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Seek, SeekFrom, Write};
|
||||
use std::process::exit;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
@@ -56,6 +56,7 @@ fn main() {
|
||||
opts.optflag("g", "generate", "Generate new config file. Generated config will be printed to console.");
|
||||
opts.optopt("k", "gen-key", "Generate new keys and save them to file.", "FILE");
|
||||
opts.optopt("l", "log", "Write log to file", "FILE");
|
||||
opts.optopt("s", "status", "Write status to file", "FILE");
|
||||
opts.optopt("c", "config", "Path to config file", "FILE");
|
||||
opts.optopt("w", "work-dir", "Path to working directory", "DIRECTORY");
|
||||
opts.optopt("u", "upgrade", "Path to config file that you want to upgrade. Upgraded config will be printed to console.", "FILE");
|
||||
@@ -108,6 +109,25 @@ fn main() {
|
||||
};
|
||||
|
||||
setup_logger(&opt_matches);
|
||||
if let Some(status) = opt_matches.opt_str("s") {
|
||||
register(move |_, event| {
|
||||
match event {
|
||||
Event::NetworkStatus { blocks, domains, keys, nodes } => {
|
||||
match File::create(Path::new(&status)) {
|
||||
Ok(mut f) => {
|
||||
let data = format!("{{ \"blocks\":{}, \"domains\":{}, \"keys\":{}, \"nodes\":{} }}", blocks, domains, keys, nodes);
|
||||
f.write_all(data.as_bytes()).expect("Error writing status file!");
|
||||
let _ = f.flush();
|
||||
}
|
||||
Err(_) => { error!("Error writing status file!"); }
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
true
|
||||
});
|
||||
}
|
||||
|
||||
info!(target: LOG_TARGET_MAIN, "Starting ALFIS {}", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
let settings = Settings::load(&config_name).expect(&format!("Cannot load settings from {}!", &config_name));
|
||||
|
||||
+4
-6
@@ -206,7 +206,7 @@ fn action_loaded(context: &Arc<Mutex<Context>>, web_view: &mut WebView<()>) {
|
||||
0 => num_cpus::get(),
|
||||
_ => threads
|
||||
};
|
||||
let status = Arc::new(Mutex::new(Status::new(threads)));
|
||||
let status = Arc::new(Mutex::new(UiStatus::new(threads)));
|
||||
let context_copy = Arc::clone(&context);
|
||||
let c = context.lock().unwrap();
|
||||
|
||||
@@ -600,22 +600,20 @@ pub enum Cmd {
|
||||
Open { link: String }
|
||||
}
|
||||
|
||||
struct Status {
|
||||
struct UiStatus {
|
||||
pub mining: bool,
|
||||
pub syncing: bool,
|
||||
pub synced_blocks: u64,
|
||||
pub sync_height: u64,
|
||||
pub nodes_connected: usize,
|
||||
pub chain_height: u64,
|
||||
pub max_diff: u32,
|
||||
pub speed: Vec<u64>
|
||||
}
|
||||
|
||||
impl Status {
|
||||
impl UiStatus {
|
||||
fn new(threads: usize) -> Self {
|
||||
let mut speed = Vec::with_capacity(threads);
|
||||
speed.resize(threads, 0u64);
|
||||
Status { mining: false, syncing: false, synced_blocks: 0, sync_height: 0, nodes_connected: 0, chain_height: 0, max_diff: 0, speed }
|
||||
UiStatus { mining: false, syncing: false, synced_blocks: 0, sync_height: 0, max_diff: 0, speed }
|
||||
}
|
||||
|
||||
fn set_thread_speed(&mut self, thread: u32, speed: u64) {
|
||||
|
||||
Reference in New Issue
Block a user