Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dquic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ tracing-appender = { workspace = true }
default = ["datagram"]
telemetry = ["qconnection/telemetry"]
datagram = ["qconnection/datagram"]
netwatcher = ["qconnection/netwatcher"]

[dev-dependencies.tracing-subscriber]
workspace = true
Expand Down
1 change: 1 addition & 0 deletions qconnection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ qdatagram = { workspace = true, optional = true }
[features]
default = ["datagram"]
datagram = ["dep:qdatagram"]
netwatcher = ["qinterface/netwatcher"]
telemetry = ["qevent/telemetry"]

[dev-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion qinterface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ derive_more = { workspace = true, features = ["deref"] }
futures = { workspace = true }
http = { workspace = true }
netdev = { workspace = true }
netwatcher = { workspace = true }
netwatcher = { workspace = true, optional = true }
parking_lot = { workspace = true }
qbase = { workspace = true }
qevent = { workspace = true }
Expand All @@ -37,4 +37,5 @@ tokio = { workspace = true, features = [
] }

[features]
netwatcher = ["dep:netwatcher"]
qudp = ["dep:qudp"]
12 changes: 10 additions & 2 deletions qinterface/src/device.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#[cfg(feature = "netwatcher")]
use std::sync::Mutex;
use std::{
collections::HashMap,
fmt::Debug,
net::IpAddr,
sync::{Arc, Mutex, OnceLock, RwLock},
sync::{Arc, OnceLock, RwLock},
time::Duration,
};

use derive_more::{Deref, DerefMut};
pub use netdev::Interface;
#[cfg(feature = "netwatcher")]
pub use netwatcher::Error as WatcherError;
#[cfg(feature = "netwatcher")]
use netwatcher::WatchHandle;
use qbase::{
net::Family,
Expand Down Expand Up @@ -321,6 +325,7 @@ impl State {

pub struct Devices {
state: Arc<State>,
#[cfg(feature = "netwatcher")]
watcher: Mutex<Result<WatchHandle, WatcherError>>,
_timer: AbortOnDropHandle<()>,
}
Expand All @@ -329,7 +334,6 @@ impl Debug for Devices {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Devices")
.field("state", &self.state)
.field("watcher", &"...")
.field("_timer", &self._timer)
.finish()
}
Expand Down Expand Up @@ -357,6 +361,7 @@ impl Devices {
.in_current_span()
}));

#[cfg(feature = "netwatcher")]
let watcher = netwatcher::watch_interfaces_with_callback({
let state = state.clone();
move |_update| {
Expand All @@ -365,17 +370,20 @@ impl Devices {
}
});

#[cfg(feature = "netwatcher")]
if let Err(initial_watcher_error) = &watcher {
tracing::warn!(target: "interface", "failed to start interfaces watcher: {initial_watcher_error}");
}

Self {
state,
_timer: timer,
#[cfg(feature = "netwatcher")]
watcher: watcher.into(),
}
}

#[cfg(feature = "netwatcher")]
#[inline]
pub fn restart_watcher(&self) -> Result<(), WatcherError> {
let new_watcher = netwatcher::watch_interfaces_with_callback({
Expand Down
Loading