don't fill logs with compromised response

This commit is contained in:
Edward Shen 2021-04-23 00:34:23 -04:00
parent 3268321711
commit 0918b210ea
Signed by: edward
GPG key ID: 19182661E818369F
2 changed files with 21 additions and 15 deletions

View file

@ -11,9 +11,10 @@ use serde::{Deserialize, Serialize};
use sodiumoxide::crypto::box_::PrecomputedKey; use sodiumoxide::crypto::box_::PrecomputedKey;
use url::Url; use url::Url;
use crate::config::VALIDATE_TOKENS; use crate::config::CliArgs;
use crate::state::RwLockServerState; use crate::state::PREVIOUSLY_PAUSED;
use crate::{client_api_version, config::CliArgs}; use crate::{client_api_version, state::PREVIOUSLY_COMPROMISED};
use crate::{config::VALIDATE_TOKENS, state::RwLockServerState};
pub const CONTROL_CENTER_PING_URL: &str = "https://api.mangadex.network/ping"; pub const CONTROL_CENTER_PING_URL: &str = "https://api.mangadex.network/ping";
@ -180,12 +181,19 @@ pub async fn update_server_state(secret: &str, cli: &CliArgs, data: &mut Arc<RwL
write_guard.tls_config = tls; write_guard.tls_config = tls;
} }
if resp.compromised { let previously_compromised = PREVIOUSLY_COMPROMISED.load(Ordering::Acquire);
error!("Got compromised response from control center!"); if resp.compromised != previously_compromised {
PREVIOUSLY_COMPROMISED.store(resp.compromised, Ordering::Release);
if resp.compromised {
error!("Got compromised response from control center!");
} else {
info!("No longer compromised!");
}
} }
if resp.paused != write_guard.log_state.was_paused_before { let previously_paused = PREVIOUSLY_PAUSED.load(Ordering::Acquire);
write_guard.log_state.was_paused_before = resp.paused; if resp.paused != previously_paused {
PREVIOUSLY_PAUSED.store(resp.paused, Ordering::Release);
if resp.paused { if resp.paused {
warn!("Control center has paused this node."); warn!("Control center has paused this node.");
} else { } else {

View file

@ -1,4 +1,5 @@
use std::sync::{atomic::Ordering, Arc}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use crate::config::{CliArgs, SEND_SERVER_VERSION, VALIDATE_TOKENS}; use crate::config::{CliArgs, SEND_SERVER_VERSION, VALIDATE_TOKENS};
use crate::ping::{Request, Response, Tls, CONTROL_CENTER_PING_URL}; use crate::ping::{Request, Response, Tls, CONTROL_CENTER_PING_URL};
@ -15,12 +16,10 @@ pub struct ServerState {
pub tls_config: Tls, pub tls_config: Tls,
pub url: Url, pub url: Url,
pub url_overridden: bool, pub url_overridden: bool,
pub log_state: LogState,
} }
pub struct LogState { pub static PREVIOUSLY_PAUSED: AtomicBool = AtomicBool::new(false);
pub was_paused_before: bool, pub static PREVIOUSLY_COMPROMISED: AtomicBool = AtomicBool::new(false);
}
impl ServerState { impl ServerState {
pub async fn init(secret: &str, config: &CliArgs) -> Result<Self, ()> { pub async fn init(secret: &str, config: &CliArgs) -> Result<Self, ()> {
@ -53,10 +52,12 @@ impl ServerState {
}) })
.unwrap(); .unwrap();
PREVIOUSLY_COMPROMISED.store(resp.paused, Ordering::Release);
if resp.compromised { if resp.compromised {
error!("Got compromised response from control center!"); error!("Got compromised response from control center!");
} }
PREVIOUSLY_PAUSED.store(resp.paused, Ordering::Release);
if resp.paused { if resp.paused {
warn!("Control center has paused this node!"); warn!("Control center has paused this node!");
} }
@ -86,9 +87,6 @@ impl ServerState {
tls_config: resp.tls.unwrap(), tls_config: resp.tls.unwrap(),
url: resp.url, url: resp.url,
url_overridden: config.override_upstream.is_some(), url_overridden: config.override_upstream.is_some(),
log_state: LogState {
was_paused_before: resp.paused,
},
}) })
} }
Err(e) => { Err(e) => {