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<()> { pub async fn run(&mut self) -> Result<()> {
tracing::info!("BEGIN");
while let Ok(command) = self.rx.recv().await { while let Ok(command) = self.rx.recv().await {
let response = self.proc_command(command).await; let response = self.proc_command(command).await;
info!("Daemon response: {:?}", response); info!("Daemon response: {:?}", response);

View file

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

View file

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