Update logging

This commit is contained in:
Jett Chen 2023-12-17 17:59:37 +08:00
parent 286ecfa590
commit 889ed37f80
3 changed files with 12 additions and 19 deletions

View file

@ -111,7 +111,6 @@ impl DaemonInstance {
}
pub async fn run(&mut self) -> Result<()> {
tracing::info!("BEGIN");
while let Ok(command) = self.rx.recv().await {
let response = self.proc_command(command).await;
info!("Daemon response: {:?}", response);

View file

@ -7,7 +7,7 @@ use crate::daemon::{daemon_main, DaemonClient};
#[no_mangle]
pub extern "C" fn start_srv() {
info!("Rust: Starting server");
info!("Starting server");
let _handle = thread::spawn(move || {
let rt = Runtime::new().unwrap();
rt.block_on(async {
@ -20,10 +20,8 @@ pub extern "C" fn start_srv() {
rt.block_on(async {
loop {
match DaemonClient::new().await {
Ok(_) => break,
Err(_e) => {
// error!("Error when connecting to daemon: {}", e)
}
Ok(..) => info!("Server successfully started"),
Err(e) => error!("Could not connect to server: {}", e)
}
}
});

View file

@ -90,56 +90,52 @@ impl Interface {
}
pub async fn run(&self) -> anyhow::Result<()> {
debug!("RUN: starting interface");
let pcbs = self.pcbs.clone();
let tun = self
.tun
.clone()
.ok_or(anyhow::anyhow!("tun interface does not exist"))?;
log::info!("starting interface");
log::info!("Starting interface");
let outgoing = async move {
loop {
// tracing::debug!("starting loop...");
let mut buf = [0u8; 3000];
let src = {
let src = match tun.read().await.recv(&mut buf[..]).await {
Ok(len) => &buf[..len],
Err(e) => {
error!("failed to read from interface: {}", e);
error!("Failed to read from interface: {}", e);
continue;
}
};
debug!("read {} bytes from interface", src.len());
debug!("bytes: {:?}", src);
debug!("Read {} bytes from interface", src.len());
src
};
let dst_addr = match Tunnel::dst_address(src) {
Some(addr) => addr,
None => {
tracing::debug!("no destination found");
debug!("No destination found");
continue;
}
};
tracing::debug!("dst_addr: {}", dst_addr);
debug!("src_addr: {}", Tunnel::src_address(src).unwrap());
debug!("Routing packet to {}", dst_addr);
let Some(idx) = pcbs.find(dst_addr) else {
continue
};
tracing::debug!("found peer:{}", idx);
debug!("Found peer:{}", idx);
match pcbs.pcbs[idx].send(src).await {
Ok(..) => {
let addr = pcbs.pcbs[idx].endpoint;
tracing::debug!("sent packet to peer {}", addr);
debug!("Sent packet to peer {}", addr);
}
Err(e) => {
log::error!("failed to send packet {}", e);
log::error!("Failed to send packet {}", e);
continue;
}
};
@ -171,7 +167,7 @@ impl Interface {
log::error!("failed to run pcb: {}", e);
return;
} else {
tracing::debug!("pcb ran successfully");
debug!("pcb ran successfully");
}
};
debug!("task made..");