don't fill logs with compromised response

feature/v32-tokens
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 url::Url;
use crate::config::VALIDATE_TOKENS;
use crate::state::RwLockServerState;
use crate::{client_api_version, config::CliArgs};
use crate::config::CliArgs;
use crate::state::PREVIOUSLY_PAUSED;
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";
@ -180,12 +181,19 @@ pub async fn update_server_state(secret: &str, cli: &CliArgs, data: &mut Arc<RwL
write_guard.tls_config = tls;
}
if resp.compromised {
error!("Got compromised response from control center!");
let previously_compromised = PREVIOUSLY_COMPROMISED.load(Ordering::Acquire);
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 {
write_guard.log_state.was_paused_before = resp.paused;
let previously_paused = PREVIOUSLY_PAUSED.load(Ordering::Acquire);
if resp.paused != previously_paused {
PREVIOUSLY_PAUSED.store(resp.paused, Ordering::Release);
if resp.paused {
warn!("Control center has paused this node.");
} 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::ping::{Request, Response, Tls, CONTROL_CENTER_PING_URL};
@ -15,12 +16,10 @@ pub struct ServerState {
pub tls_config: Tls,
pub url: Url,
pub url_overridden: bool,
pub log_state: LogState,
}
pub struct LogState {
pub was_paused_before: bool,
}
pub static PREVIOUSLY_PAUSED: AtomicBool = AtomicBool::new(false);
pub static PREVIOUSLY_COMPROMISED: AtomicBool = AtomicBool::new(false);
impl ServerState {
pub async fn init(secret: &str, config: &CliArgs) -> Result<Self, ()> {
@ -53,10 +52,12 @@ impl ServerState {
})
.unwrap();
PREVIOUSLY_COMPROMISED.store(resp.paused, Ordering::Release);
if resp.compromised {
error!("Got compromised response from control center!");
}
PREVIOUSLY_PAUSED.store(resp.paused, Ordering::Release);
if resp.paused {
warn!("Control center has paused this node!");
}
@ -86,9 +87,6 @@ impl ServerState {
tls_config: resp.tls.unwrap(),
url: resp.url,
url_overridden: config.override_upstream.is_some(),
log_state: LogState {
was_paused_before: resp.paused,
},
})
}
Err(e) => {