misc changes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2023-04-22 19:28:38 +02:00
parent 699d12324b
commit f444137684
3 changed files with 39 additions and 17 deletions

View File

@ -17,7 +17,7 @@ use std::path::Path;
pub const GIT_VERSION: &str = git_version!();
const MASTERSERVER: &str = "ipbl.paulbsd.com";
const WSSUBSCRIPTION: &str = "ipbl";
const CONFIG_RETRY: u64 = 10;
const CONFIG_RETRY: u64 = 5;
#[derive(Debug, Clone)]
pub struct Context {
@ -131,18 +131,29 @@ impl Context {
if cfg!(test) {
return Ok(());
}
let mut last_in_err = false;
loop {
match self.cfg.load(self.to_owned()).await {
Ok(()) => {
if last_in_err {
println!("loaded config");
}
break;
}
Err(err) => {
println!("error loading config: {err}, retrying in {CONFIG_RETRY} secs");
last_in_err = true;
sleep_s(CONFIG_RETRY).await;
}
};
}
if last_in_err {
println!("creating sas");
}
self.create_sas().await?;
if last_in_err {
println!("created sas");
}
Ok(())
}

View File

@ -74,11 +74,11 @@ pub async fn run() {
ipdata: ip_to_send,
};
if !send_to_ipbl_websocket(&mut wssocketrr, &ipe).await {
drop(ctx);
wssocketrr = websocketreqrep(&ctxwsrr).await;
break;
}
}
drop(ctx);
continue
}
@ -98,8 +98,8 @@ pub async fn run() {
};
send_to_ipbl_api(&ctx.client, &ctx.flags.server, &ipe).await;
let status = send_to_ipbl_websocket(&mut wssocketrr, &ipe).await;
if !status {
drop(ctx);
if !status {
wssocketrr = websocketreqrep(&ctxwsrr).await;
continue;
}

View File

@ -102,22 +102,33 @@ pub async fn send_to_ipbl_websocket(
) -> bool {
let msg = format!("{val}", val = serde_json::to_string(&ip).unwrap());
if ws.can_write() {
match ws.write_message(Message::Text(msg)) {
Ok(_) => {}
Err(e) => {
println!("err send write: {e:?}");
ws.close(None).unwrap();
return false;
println!("err send read: {e:?}");
return handle_websocket_error(ws);
}
};
} else {
return handle_websocket_error(ws);
};
if ws.can_read() {
match ws.read_message() {
Ok(_) => {}
Err(e) => {
println!("err send read: {e:?}");
ws.close(None).unwrap();
return false;
return handle_websocket_error(ws);
}
};
} else {
return handle_websocket_error(ws);
};
true
}
fn handle_websocket_error(ws: &mut WebSocket<MaybeTlsStream<TcpStream>>) -> bool {
ws.close(None).unwrap();
return false;
}