Add tokio console and more debugging feats
This commit is contained in:
parent
7d8958e0e7
commit
0b46ac57b7
5 changed files with 352 additions and 18 deletions
|
|
@ -10,7 +10,7 @@ crate-type = ["lib", "staticlib"]
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
tokio = { version = "1.21", features = ["rt", "macros", "sync", "io-util", "rt-multi-thread", "time"] }
|
||||
tokio = { version = "1.21", features = ["rt", "macros", "sync", "io-util", "rt-multi-thread", "time", "tracing"] }
|
||||
tun = { version = "0.1", path = "../tun", features = ["serde", "tokio"] }
|
||||
clap = { version = "4.3.2", features = ["derive"] }
|
||||
tracing = "0.1"
|
||||
|
|
@ -40,6 +40,7 @@ async-channel = "2.1.1"
|
|||
schemars = "0.8"
|
||||
futures = "0.3.28"
|
||||
uuid = { version = "1.6.1", features = ["v4"] }
|
||||
console-subscriber = { version = "0.2.0" , optional = true}
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
caps = "0.5.5"
|
||||
|
|
@ -60,3 +61,6 @@ assets = [
|
|||
]
|
||||
post_install_script = "../package/rpm/post_install"
|
||||
pre_uninstall_script = "../package/rpm/pre_uninstall"
|
||||
|
||||
[features]
|
||||
tokio-console = ["dep:console-subscriber"]
|
||||
|
|
@ -98,19 +98,27 @@ async fn initialize_tracing() -> Result<()> {
|
|||
|
||||
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
|
||||
{
|
||||
let maybe_layer = system_log()?;
|
||||
if let Some(layer) = maybe_layer {
|
||||
let logger = layer.with_subscriber(
|
||||
FmtSubscriber::builder()
|
||||
.with_line_number(true)
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.finish(),
|
||||
let maybe_layer = system_log()?;
|
||||
if let Some(layer) = maybe_layer {
|
||||
let registry = tracing_subscriber::registry()
|
||||
.with(layer)
|
||||
.with(tracing_subscriber::fmt::layer()
|
||||
.with_line_number(true)
|
||||
.with_filter(EnvFilter::from_default_env())
|
||||
);
|
||||
tracing::subscriber::set_global_default(logger)
|
||||
.context("Failed to set the global tracing subscriber")?;
|
||||
|
||||
#[cfg(feature = "tokio-console")]
|
||||
let registry = registry.with(
|
||||
console_subscriber::spawn()
|
||||
.with_filter(EnvFilter::from_default_env()
|
||||
.add_directive("tokio=trace".parse()?)
|
||||
.add_directive("runtime=trace".parse()?)
|
||||
)
|
||||
);
|
||||
|
||||
tracing::subscriber::set_global_default(registry).context("Failed to set the global tracing subscriber")?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -115,9 +115,12 @@ impl PeerPcb {
|
|||
}
|
||||
|
||||
pub async fn send(&self, src: &[u8]) -> Result<(), Error> {
|
||||
tracing::debug!("Sending packet: {:?}", src);
|
||||
let mut dst_buf = [0u8; 3000];
|
||||
match self.tunnel.write().await.encapsulate(src, &mut dst_buf[..]) {
|
||||
TunnResult::Done => {}
|
||||
TunnResult::Done => {
|
||||
tracing::debug!("Encapsulate done");
|
||||
}
|
||||
TunnResult::Err(e) => {
|
||||
tracing::error!(message = "Encapsulate error", error = ?e)
|
||||
}
|
||||
|
|
@ -137,6 +140,7 @@ impl PeerPcb {
|
|||
}
|
||||
|
||||
pub async fn update_timers(&self, dst: &mut [u8]) -> Result<(), Error> {
|
||||
tracing::debug!("update timers called...");
|
||||
match self.tunnel.write().await.update_timers(dst) {
|
||||
TunnResult::Done => {}
|
||||
TunnResult::Err(WireGuardError::ConnectionExpired) => {
|
||||
|
|
@ -147,6 +151,7 @@ impl PeerPcb {
|
|||
tracing::error!(message = "Update timers error", error = ?e)
|
||||
}
|
||||
TunnResult::WriteToNetwork(packet) => {
|
||||
tracing::debug!("Sending Packet for timer update: {:?}", packet);
|
||||
self.open_if_closed().await?;
|
||||
let handle = self.socket.read().await;
|
||||
let Some(socket) = handle.as_ref() else {
|
||||
|
|
@ -154,9 +159,11 @@ impl PeerPcb {
|
|||
return Ok(())
|
||||
};
|
||||
socket.send(packet).await?;
|
||||
tracing::debug!("Sent Packet for timer update");
|
||||
}
|
||||
_ => panic!("Unexpected result from update_timers"),
|
||||
};
|
||||
tracing::debug!("update timers exit...");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue