This commit is contained in:
parent
93990307c4
commit
1bc3358faf
13
src/ipblc.rs
13
src/ipblc.rs
@ -64,8 +64,9 @@ pub async fn run() {
|
||||
ipevent = ipeventrx.recv() => {
|
||||
let received_ip = ipevent.unwrap();
|
||||
|
||||
if received_ip.msgtype == "bootstrap".to_string() {
|
||||
let mut ctx = ctxclone.write().await;
|
||||
|
||||
if received_ip.msgtype == "bootstrap".to_string() {
|
||||
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();
|
||||
}
|
||||
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;
|
||||
|
@ -24,28 +24,21 @@ 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 {
|
||||
match data {
|
||||
Ok(dt) => {
|
||||
let (_reader, mut writer) = stream.into_split();
|
||||
match writer.write_all(format!("{dt}").as_bytes()).await {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!("error flushing stream: {e}")
|
||||
}
|
||||
}
|
||||
match stream.shutdown().await {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!("error shuting down stream: {e}")
|
||||
Err(err) => {
|
||||
println!("{err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,6 +47,11 @@ pub async fn apiserver(ctxarc: &Arc<RwLock<Context>>) -> io::Result<()> {
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
println!("couldn't get client: {}", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user