better logging
This commit is contained in:
parent
2e02944958
commit
91f420330b
4 changed files with 34 additions and 11 deletions
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
|
18
src/ping.rs
18
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<RwLockServerState>
|
|||
}
|
||||
}
|
||||
|
||||
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 != write_guard.log_state.was_paused_before {
|
||||
write_guard.log_state.was_paused_before = resp.paused;
|
||||
if resp.paused {
|
||||
debug!("Got paused response from control center.");
|
||||
warn!("Control center has paused this node.");
|
||||
} else {
|
||||
info!("Control center is no longer pausing this node.");
|
||||
}
|
||||
}
|
||||
|
||||
if resp.url != write_guard.url {
|
||||
|
|
18
src/state.rs
18
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) => {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue