Remove unused dependency. Improve trace logging perf.

This commit is contained in:
Aram 🍐 2022-01-08 14:41:12 -05:00
parent 2e204d80fd
commit 2b18bd4ec3
3 changed files with 42 additions and 14 deletions

11
Cargo.lock generated
View file

@ -171,16 +171,6 @@ dependencies = [
"unreachable", "unreachable",
] ]
[[package]]
name = "dashmap"
version = "4.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c"
dependencies = [
"cfg-if",
"num_cpus",
]
[[package]] [[package]]
name = "either" name = "either"
version = "1.6.1" version = "1.6.1"
@ -549,7 +539,6 @@ dependencies = [
"async-trait", "async-trait",
"boringtun", "boringtun",
"clap", "clap",
"dashmap",
"futures", "futures",
"log", "log",
"nom", "nom",

View file

@ -17,5 +17,4 @@ futures = "0.3.17"
rand = "0.8.4" rand = "0.8.4"
nom = "7" nom = "7"
async-trait = "0.1.51" async-trait = "0.1.51"
dashmap = "4.0.2"
priority-queue = "1.2.0" priority-queue = "1.2.0"

View file

@ -1,3 +1,4 @@
use std::fmt::{Display, Formatter};
use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Arc; use std::sync::Arc;
@ -26,6 +27,45 @@ pub enum Event {
VirtualDeviceFed(PortProtocol), VirtualDeviceFed(PortProtocol),
} }
impl Display for Event {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Event::Dumb => {
write!(f, "Dumb{{}}")
}
Event::ClientConnectionInitiated(pf, vp) => {
write!(f, "ClientConnectionInitiated{{ pf={} vp={} }}", pf, vp)
}
Event::ClientConnectionDropped(vp) => {
write!(f, "ClientConnectionDropped{{ vp={} }}", vp)
}
Event::LocalData(pf, vp, data) => {
let size = data.len();
write!(f, "LocalData{{ pf={} vp={} size={} }}", pf, vp, size)
}
Event::RemoteData(vp, data) => {
let size = data.len();
write!(f, "RemoteData{{ vp={} size={} }}", vp, size)
}
Event::InboundInternetPacket(proto, data) => {
let size = data.len();
write!(
f,
"InboundInternetPacket{{ proto={} size={} }}",
proto, size
)
}
Event::OutboundInternetPacket(data) => {
let size = data.len();
write!(f, "OutboundInternetPacket{{ size={} }}", size)
}
Event::VirtualDeviceFed(proto) => {
write!(f, "VirtualDeviceFed{{ proto={} }}", proto)
}
}
}
}
#[derive(Clone)] #[derive(Clone)]
pub struct Bus { pub struct Bus {
counter: Arc<AtomicU32>, counter: Arc<AtomicU32>,
@ -84,7 +124,7 @@ impl BusEndpoint {
// If the event was sent by this endpoint, it is skipped // If the event was sent by this endpoint, it is skipped
continue; continue;
} else { } else {
trace!("#{} <- {:?}", self.id, event); trace!("#{} <- {}", self.id, event);
return event; return event;
} }
} }
@ -111,7 +151,7 @@ pub struct BusSender {
impl BusSender { impl BusSender {
/// Sends the event on the bus. Note that the messages sent by this endpoint won't reach itself. /// Sends the event on the bus. Note that the messages sent by this endpoint won't reach itself.
pub fn send(&self, event: Event) { pub fn send(&self, event: Event) {
trace!("#{} -> {:?}", self.id, event); trace!("#{} -> {}", self.id, event);
match self.tx.send((self.id, event)) { match self.tx.send((self.id, event)) {
Ok(_) => {} Ok(_) => {}
Err(_) => error!("Failed to send event to bus from endpoint #{}", self.id), Err(_) => error!("Failed to send event to bus from endpoint #{}", self.id),