revert buggy commits
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2023-05-07 11:23:55 +02:00
parent 93990307c4
commit 1bc3358faf
2 changed files with 20 additions and 25 deletions

View File

@ -64,8 +64,9 @@ pub async fn run() {
ipevent = ipeventrx.recv() => { ipevent = ipeventrx.recv() => {
let received_ip = ipevent.unwrap(); let received_ip = ipevent.unwrap();
if received_ip.msgtype == "bootstrap".to_string() {
let mut ctx = ctxclone.write().await; let mut ctx = ctxclone.write().await;
if received_ip.msgtype == "bootstrap".to_string() {
for ip_to_send in ctx.get_blocklist_toblock().await { for ip_to_send in ctx.get_blocklist_toblock().await {
let ipe = IpEvent{ let ipe = IpEvent{
msgtype: String::from("init"), msgtype: String::from("init"),
@ -83,13 +84,8 @@ pub async fn run() {
continue continue
} }
let (filtered_ipevent,server);
{
let mut ctx = ctxclone.write().await;
// refresh context blocklist // refresh context blocklist
filtered_ipevent = ctx.update_blocklist(&received_ip).await; let filtered_ipevent = ctx.update_blocklist(&received_ip).await;
server = ctx.flags.server.clone();
}
// send ip list to api and ws sockets // send ip list to api and ws sockets
if let Some(ipevent) = filtered_ipevent { if let Some(ipevent) = filtered_ipevent {
@ -101,8 +97,9 @@ pub async fn run() {
hostname: gethostname(true), hostname: gethostname(true),
ipdata: ipevent.ipdata, ipdata: ipevent.ipdata,
}; };
send_to_ipbl_api(&server, &ipe).await; send_to_ipbl_api(&ctx.flags.server, &ipe).await;
let status = send_to_ipbl_websocket(&mut wssocketrr, &ipe).await; let status = send_to_ipbl_websocket(&mut wssocketrr, &ipe).await;
drop(ctx);
if !status { if !status {
wssocketrr = websocketreqrep(&ctxwsrr).await; wssocketrr = websocketreqrep(&ctxwsrr).await;
continue; continue;

View File

@ -24,28 +24,21 @@ pub async fn apiserver(ctxarc: &Arc<RwLock<Context>>) -> io::Result<()> {
loop { loop {
//apitx.send(String::from("")).await.unwrap(); //apitx.send(String::from("")).await.unwrap();
match listener.accept().await { match listener.accept().await {
Ok((mut stream, _addr)) => { Ok((stream, _addr)) => {
//let mut buf = [0; 1024]; //let mut buf = [0; 1024];
let data; let data;
{ {
let ctx = ctxarc.read().await; let ctx = ctxarc.read().await;
data = serde_json::to_string(&ctx.blocklist).unwrap(); data = serde_json::to_string(&ctx.blocklist);
} }
stream match data {
.write_all(format!("{data}\n").as_bytes()) Ok(dt) => {
.await let (_reader, mut writer) = stream.into_split();
.unwrap(); match writer.write_all(format!("{dt}").as_bytes()).await {
match stream.flush().await {
Ok(_) => {} Ok(_) => {}
Err(e) => { Err(err) => {
println!("error flushing stream: {e}") println!("{err}");
}
}
match stream.shutdown().await {
Ok(_) => {}
Err(e) => {
println!("error shuting down stream: {e}")
} }
} }
} }
@ -54,6 +47,11 @@ pub async fn apiserver(ctxarc: &Arc<RwLock<Context>>) -> io::Result<()> {
} }
} }
} }
Err(err) => {
println!("couldn't get client: {}", err)
}
}
}
}); });
Ok(()) Ok(())
} }