From 91f420330b0e7e4cf3962616e69259c91e5c36a7 Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Mon, 22 Mar 2021 23:19:56 -0400 Subject: [PATCH] better logging --- src/main.rs | 3 ++- src/ping.rs | 22 +++++++++++++++++----- src/state.rs | 18 ++++++++++++++---- src/stop.rs | 2 +- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index bdcaee6..1dcb1e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use std::{num::ParseIntError, sync::atomic::Ordering}; use actix_web::rt::{spawn, time, System}; use actix_web::web::{self, Data}; use actix_web::{App, HttpServer}; -use log::{error, warn, LevelFilter}; +use log::{debug, error, warn, LevelFilter}; use parking_lot::RwLock; use rustls::{NoClientAuth, ServerConfig}; use simple_logger::SimpleLogger; @@ -74,6 +74,7 @@ async fn main() -> Result<(), std::io::Error> { let mut data = Arc::clone(&data_0); loop { interval.tick().await; + debug!("Sending ping!"); ping::update_server_state(&config, &mut data).await; } }); diff --git a/src/ping.rs b/src/ping.rs index 371a6e0..a58a924 100644 --- a/src/ping.rs +++ b/src/ping.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use log::{debug, error, info, warn}; +use log::{error, info, warn}; use serde::{Deserialize, Serialize}; use sodiumoxide::crypto::box_::PrecomputedKey; use url::Url; @@ -89,18 +89,30 @@ pub async fn update_server_state(req: &Config, data: &mut Arc } } - write_guard.force_tokens = resp.force_tokens; + if write_guard.force_tokens != resp.force_tokens { + write_guard.force_tokens = resp.force_tokens; + if resp.force_tokens { + info!("Client received command to enforce token validity."); + } else { + info!("Client received command to no longer enforce token validity"); + } + } if let Some(tls) = resp.tls { write_guard.tls_config = tls; } if resp.compromised { - warn!("Got compromised response from control center!"); + error!("Got compromised response from control center!"); } - if resp.paused { - debug!("Got paused response from control center."); + if resp.paused != write_guard.log_state.was_paused_before { + write_guard.log_state.was_paused_before = resp.paused; + if resp.paused { + warn!("Control center has paused this node."); + } else { + info!("Control center is no longer pausing this node."); + } } if resp.url != write_guard.url { diff --git a/src/state.rs b/src/state.rs index 6a27522..79e616d 100644 --- a/src/state.rs +++ b/src/state.rs @@ -3,7 +3,7 @@ use std::{io::BufReader, sync::Arc}; use crate::cache::Cache; use crate::ping::{Request, Response, Tls, CONTROL_CENTER_PING_URL}; use crate::Config; -use log::{debug, error, info, warn}; +use log::{error, info, warn}; use parking_lot::RwLock; use rustls::internal::pemfile::{certs, rsa_private_keys}; use rustls::sign::{CertifiedKey, RSASigningKey}; @@ -18,6 +18,11 @@ pub struct ServerState { pub force_tokens: bool, pub url: String, pub cache: Cache, + pub log_state: LogState, +} + +pub struct LogState { + pub was_paused_before: bool, } impl ServerState { @@ -47,17 +52,19 @@ impl ServerState { .unwrap(); if resp.compromised { - warn!("Got compromised response from control center!"); + error!("Got compromised response from control center!"); } if resp.paused { - debug!("Got paused response from control center."); + warn!("Control center has paused this node!"); } info!("This client's URL has been set to {}", resp.url); if resp.force_tokens { - info!("This client will validate tokens"); + info!("This client will validate tokens."); + } else { + info!("This client will not validate tokens."); } Ok(Self { @@ -71,6 +78,9 @@ impl ServerState { config.disk_quota, config.disk_path.clone(), ), + log_state: LogState { + was_paused_before: resp.paused, + }, }) } Err(e) => { diff --git a/src/stop.rs b/src/stop.rs index 5204416..e61a176 100644 --- a/src/stop.rs +++ b/src/stop.rs @@ -19,7 +19,7 @@ pub async fn send_stop(secret: &str) { { Ok(resp) => { if resp.status() == 200 { - info!("Successfully sent stop message."); + info!("Successfully sent stop message to control center."); } else { warn!("Got weird response from server: {:?}", resp.headers()); }