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

View File

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