From 7848f791b6f0813d7d9aa2f4dbcdfcc55f0b1ad7 Mon Sep 17 00:00:00 2001 From: Kai Renken Date: Fri, 8 Sep 2023 23:17:46 +0200 Subject: [PATCH 1/4] use secure keystore in default config --- veilid-server/src/settings.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/veilid-server/src/settings.rs b/veilid-server/src/settings.rs index 498882fd..3743d9d5 100644 --- a/veilid-server/src/settings.rs +++ b/veilid-server/src/settings.rs @@ -51,7 +51,7 @@ core: disable: [] protected_store: allow_insecure_fallback: true - always_use_insecure_storage: true + always_use_insecure_storage: false directory: '%DIRECTORY%' delete: false device_encryption_key_password: '%DEVICE_ENCRYPTION_KEY_PASSWORD%' From f2f4526b0ba645619c7111f53b477f946decefdb Mon Sep 17 00:00:00 2001 From: Kai Renken Date: Mon, 25 Sep 2023 09:52:40 +0200 Subject: [PATCH 2/4] add timestamp to CLI --- veilid-cli/Cargo.toml | 2 ++ veilid-cli/src/ui.rs | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/veilid-cli/Cargo.toml b/veilid-cli/Cargo.toml index 11b6e51b..a1f26837 100644 --- a/veilid-cli/Cargo.toml +++ b/veilid-cli/Cargo.toml @@ -62,5 +62,7 @@ flume = { version = "^0", features = ["async"] } data-encoding = { version = "^2" } indent = { version = "0.1.1" } +chrono = "0.4.26" + [dev-dependencies] serial_test = "^0" diff --git a/veilid-cli/src/ui.rs b/veilid-cli/src/ui.rs index 24fcc803..65176913 100644 --- a/veilid-cli/src/ui.rs +++ b/veilid-cli/src/ui.rs @@ -17,6 +17,7 @@ use cursive_flexi_logger_view::{CursiveLogWriter, FlexiLoggerView}; use std::collections::{HashMap, VecDeque}; use std::io::Write; use thiserror::Error; +use chrono::Local; ////////////////////////////////////////////////////////////// /// struct Dirty { @@ -101,7 +102,6 @@ pub enum DumbError { impl UI { ///////////////////////////////////////////////////////////////////////////////////// // Private functions - fn command_processor(s: &mut Cursive) -> CommandProcessor { let inner = Self::inner(s); inner.cmdproc.as_ref().unwrap().clone() @@ -349,7 +349,7 @@ impl UI { cursive_flexi_logger_view::parse_lines_to_log( ColorStyle::primary().into(), - format!("> {}", text), + format!("> {} {}",Local::now().format("%Y-%m-%dT%H:%M:%S:%3f"), text), ); match Self::run_command(s, text) { Ok(_) => {} @@ -463,7 +463,7 @@ impl UI { let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap(); cursive_flexi_logger_view::parse_lines_to_log( color.into(), - format!(">> Copied: {}", text.as_ref()), + format!(">> {} Copied: {}", Local::now().format("%Y-%m-%dT%H:%M:%S:%3f") ,text.as_ref()), ); } else { let color = *Self::inner_mut(s).log_colors.get(&Level::Warn).unwrap(); @@ -488,7 +488,7 @@ impl UI { let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap(); cursive_flexi_logger_view::parse_lines_to_log( color.into(), - format!(">> Copied: {}", text.as_ref()), + format!(">> {} Copied: {}", Local::now().format("%Y-%m-%dT%H:%M:%S:%3f"), text.as_ref()), ); } } @@ -1039,7 +1039,7 @@ impl UISender { { let inner = self.inner.lock(); let color = *inner.log_colors.get(&log_color).unwrap(); - cursive_flexi_logger_view::parse_lines_to_log(color.into(), event); + cursive_flexi_logger_view::parse_lines_to_log(color.into(), format!("{}: {}", Local::now().format("%Y-%m-%dT%H:%M:%S:%3f"), event)); } let _ = self.cb_sink.send(Box::new(UI::update_cb)); } From 395d105640225cc1540978d13594f257c855a96a Mon Sep 17 00:00:00 2001 From: Kai Renken Date: Sun, 1 Oct 2023 23:20:39 +0200 Subject: [PATCH 3/4] cleanup for timestamps in ui and refactor to function --- veilid-cli/src/ui.rs | 60 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/veilid-cli/src/ui.rs b/veilid-cli/src/ui.rs index 65176913..aaebfea0 100644 --- a/veilid-cli/src/ui.rs +++ b/veilid-cli/src/ui.rs @@ -2,6 +2,7 @@ use crate::command_processor::*; use crate::peers_table_view::*; use crate::settings::Settings; use crate::tools::*; +use async_tungstenite::tungstenite::http::header::STRICT_TRANSPORT_SECURITY; use crossbeam_channel::Sender; use cursive::align::*; use cursive::event::*; @@ -16,8 +17,11 @@ use cursive_flexi_logger_view::{CursiveLogWriter, FlexiLoggerView}; // use cursive_multiplex::*; use std::collections::{HashMap, VecDeque}; use std::io::Write; +use std::time::{SystemTime, UNIX_EPOCH}; use thiserror::Error; -use chrono::Local; +use std::sync::atomic::{AtomicU64, Ordering}; +use chrono::{Datelike, Timelike}; + ////////////////////////////////////////////////////////////// /// struct Dirty { @@ -48,6 +52,10 @@ impl Dirty { pub type UICallback = Box; + + +static START_TIME: AtomicU64 = AtomicU64::new(0); + struct UIState { attachment_state: Dirty, public_internet_ready: Dirty, @@ -349,7 +357,7 @@ impl UI { cursive_flexi_logger_view::parse_lines_to_log( ColorStyle::primary().into(), - format!("> {} {}",Local::now().format("%Y-%m-%dT%H:%M:%S:%3f"), text), + format!("> {} {}", UI::cli_ts(Self::get_start_time()) , text), ); match Self::run_command(s, text) { Ok(_) => {} @@ -357,7 +365,7 @@ impl UI { let color = *Self::inner_mut(s).log_colors.get(&Level::Error).unwrap(); cursive_flexi_logger_view::parse_lines_to_log( color.into(), - format!(" Error: {}", e), + format!(" {} Error: {}", UI::cli_ts(Self::get_start_time()), e) ); } } @@ -463,13 +471,13 @@ impl UI { let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap(); cursive_flexi_logger_view::parse_lines_to_log( color.into(), - format!(">> {} Copied: {}", Local::now().format("%Y-%m-%dT%H:%M:%S:%3f") ,text.as_ref()), + format!(">> {} Copied: {}", UI::cli_ts(Self::get_start_time()), text.as_ref()), ); } else { let color = *Self::inner_mut(s).log_colors.get(&Level::Warn).unwrap(); cursive_flexi_logger_view::parse_lines_to_log( color.into(), - format!(">> Could not copy to clipboard"), + format!(">> {} Could not copy to clipboard", UI::cli_ts(Self::get_start_time())), ); } } else { @@ -488,7 +496,7 @@ impl UI { let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap(); cursive_flexi_logger_view::parse_lines_to_log( color.into(), - format!(">> {} Copied: {}", Local::now().format("%Y-%m-%dT%H:%M:%S:%3f"), text.as_ref()), + format!(">> {} Copied: {}", UI::cli_ts(Self::get_start_time()), text.as_ref()), ); } } @@ -779,12 +787,49 @@ impl UI { } } + + //////////////////////////////////////////////////////////////////////////// // Public functions + pub fn cli_ts(ts: u64) -> String { + //let ts = get_timestamp(); + + let now = chrono::DateTime::::from(SystemTime::now()); + let date = chrono::DateTime::::from(UNIX_EPOCH + Duration::from_micros(ts)); + + let show_year = now.year() != date.year(); + let show_month = show_year || now.month() != date.month(); + let show_date = show_month || now.day() != date.day(); + + if show_year || show_month || show_date { + UI::set_start_time(); + } + format!("{}{}", + if show_year || show_month || show_date { + format!("Day changed: {:04}/{:02}/{:02} \n",now.year(), now.month(), now.day()) + } else { + "".to_owned() + }, + format!("{:02}:{:02}:{:02}", + now.hour(), + now.minute(), + now.second() + )) + } + + pub fn set_start_time() { + START_TIME.store(get_timestamp(), Ordering::Relaxed) + } + + pub fn get_start_time() -> u64 { + START_TIME.load(Ordering::Relaxed) + } + pub fn new(node_log_scrollback: usize, settings: &Settings) -> (Self, UISender) { cursive_flexi_logger_view::resize(node_log_scrollback); + UI::set_start_time(); // Instantiate the cursive runnable let runnable = CursiveRunnable::new( || -> Result, Box> { @@ -939,6 +984,7 @@ impl UI { // pub fn run(&mut self) { // self.siv.run(); // } + } #[derive(Clone)] @@ -1039,7 +1085,7 @@ impl UISender { { let inner = self.inner.lock(); let color = *inner.log_colors.get(&log_color).unwrap(); - cursive_flexi_logger_view::parse_lines_to_log(color.into(), format!("{}: {}", Local::now().format("%Y-%m-%dT%H:%M:%S:%3f"), event)); + cursive_flexi_logger_view::parse_lines_to_log(color.into(), format!("{}: {}", UI::cli_ts(UI::get_start_time()), event)); } let _ = self.cb_sink.send(Box::new(UI::update_cb)); } From 301a0ba5ec7da22cd793f18d1cc53255cffa5cca Mon Sep 17 00:00:00 2001 From: Kai Renken Date: Sun, 1 Oct 2023 23:39:53 +0200 Subject: [PATCH 4/4] fixing merge conflict --- veilid-cli/src/ui.rs | 14 +------------- veilid-server/src/settings.rs | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/veilid-cli/src/ui.rs b/veilid-cli/src/ui.rs index 42828b14..13e6126d 100644 --- a/veilid-cli/src/ui.rs +++ b/veilid-cli/src/ui.rs @@ -477,11 +477,7 @@ impl UI { let color = *Self::inner_mut(s).log_colors.get(&Level::Warn).unwrap(); cursive_flexi_logger_view::parse_lines_to_log( color.into(), -<<<<<<< HEAD - format!(">> {} Could not copy to clipboard", UI::cli_ts(Self::get_start_time())), -======= - ">> Could not copy to clipboard".to_string(), ->>>>>>> f59c4509ea7e0c0e8b1088138a6eb5297844b112 + format!(">> {} Could not copy to clipboard", UI::cli_ts(Self::get_start_time())) ); } } else { @@ -497,7 +493,6 @@ impl UI { .is_ok() && std::io::stdout().flush().is_ok() { -<<<<<<< HEAD if std::io::stdout().flush().is_ok() { let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap(); cursive_flexi_logger_view::parse_lines_to_log( @@ -505,13 +500,6 @@ impl UI { format!(">> {} Copied: {}", UI::cli_ts(Self::get_start_time()), text.as_ref()), ); } -======= - let color = *Self::inner_mut(s).log_colors.get(&Level::Info).unwrap(); - cursive_flexi_logger_view::parse_lines_to_log( - color.into(), - format!(">> Copied: {}", text.as_ref()), - ); ->>>>>>> f59c4509ea7e0c0e8b1088138a6eb5297844b112 } } } diff --git a/veilid-server/src/settings.rs b/veilid-server/src/settings.rs index 23b9de80..abc73335 100644 --- a/veilid-server/src/settings.rs +++ b/veilid-server/src/settings.rs @@ -49,7 +49,7 @@ core: disable: [] protected_store: allow_insecure_fallback: true - always_use_insecure_storage: false + always_use_insecure_storage: true directory: '%DIRECTORY%' delete: false device_encryption_key_password: '%DEVICE_ENCRYPTION_KEY_PASSWORD%'