Skip to content

Commit 597482e

Browse files
committed
Re-format
1 parent 7bf70e3 commit 597482e

File tree

2 files changed

+76
-51
lines changed

2 files changed

+76
-51
lines changed

src-tauri/src/service/mod.rs

Lines changed: 74 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ impl DesktopDaemonService for DaemonService {
122122
debug!("Done creating a new interface {ifname}");
123123
}
124124

125-
// The WireGuard DNS config value can be a list of IP addresses and domain names, which will be
126-
// used as DNS servers and search domains respectively.
125+
// The WireGuard DNS config value can be a list of IP addresses and domain names, which will
126+
// be used as DNS servers and search domains respectively.
127127
debug!("Preparing DNS configuration for interface {ifname}");
128128
let dns_string = request.dns.unwrap_or_default();
129129
let dns_entries = dns_string.split(',').map(str::trim).collect::<Vec<&str>>();
@@ -137,7 +137,10 @@ impl DesktopDaemonService for DaemonService {
137137
search_domains.push(entry);
138138
}
139139
}
140-
debug!("DNS configuration for interface {ifname}: DNS: {dns:?}, Search domains: {search_domains:?}");
140+
debug!(
141+
"DNS configuration for interface {ifname}: DNS: {dns:?}, Search domains: \
142+
{search_domains:?}"
143+
);
141144

142145
#[cfg(not(windows))]
143146
let configure_interface_result = wgapi.configure_interface(&config);
@@ -161,9 +164,15 @@ impl DesktopDaemonService for DaemonService {
161164
})?;
162165

163166
if dns.is_empty() {
164-
debug!("No DNS configuration provided for interface {ifname}, skipping DNS configuration");
167+
debug!(
168+
"No DNS configuration provided for interface {ifname}, skipping DNS \
169+
configuration"
170+
);
165171
} else {
166-
debug!("The following DNS servers will be set: {dns:?}, search domains: {search_domains:?}");
172+
debug!(
173+
"The following DNS servers will be set: {dns:?}, search domains: \
174+
{search_domains:?}"
175+
);
167176
wgapi.configure_dns(&dns, &search_domains).map_err(|err| {
168177
let msg =
169178
format!("Failed to configure DNS for WireGuard interface {ifname}: {err}");
@@ -221,7 +230,8 @@ impl DesktopDaemonService for DaemonService {
221230
let request = request.into_inner();
222231
let ifname = request.interface_name;
223232
debug!(
224-
"Received a request to start a new network usage stats data stream for interface {ifname}"
233+
"Received a request to start a new network usage stats data stream for interface \
234+
{ifname}"
225235
);
226236
let span = info_span!("read_interface_data", interface_name = &ifname);
227237

@@ -234,58 +244,73 @@ impl DesktopDaemonService for DaemonService {
234244
info!("Spawning statistics collector task for interface {ifname}");
235245
});
236246

237-
tokio::spawn(async move {
238-
// Helper map to track if peer data is actually changing to avoid sending duplicate stats.
239-
let mut peer_map = HashMap::new();
240-
241-
loop {
242-
// Loop delay
243-
interval.tick().await;
244-
debug!("Gathering network usage statistics for client's network activity on {ifname}");
245-
match wgapi.read_interface_data() {
246-
Ok(mut host) => {
247-
let peers = &mut host.peers;
248-
debug!(
249-
"Found {} peers configured on WireGuard interface",
250-
peers.len()
251-
);
252-
// Filter out never connected peers.
253-
peers.retain(|_, peer| {
254-
// Last handshake time-stamp must exist...
255-
if let Some(last_hs) = peer.last_handshake {
256-
// ...and not be UNIX epoch.
257-
if last_hs != SystemTime::UNIX_EPOCH &&
258-
match peer_map.get(&peer.public_key) {
259-
Some(last_peer) => last_peer != peer,
260-
None => true,
261-
} {
262-
debug!("Peer {} statistics changed; keeping it.", peer.public_key);
263-
peer_map.insert(peer.public_key.clone(), peer.clone());
264-
return true;
247+
tokio::spawn(
248+
async move {
249+
// Helper map to track if peer data is actually changing to avoid sending duplicate
250+
// stats.
251+
let mut peer_map = HashMap::new();
252+
253+
loop {
254+
// Loop delay
255+
interval.tick().await;
256+
debug!(
257+
"Gathering network usage statistics for client's network activity on {ifname}");
258+
match wgapi.read_interface_data() {
259+
Ok(mut host) => {
260+
let peers = &mut host.peers;
261+
debug!(
262+
"Found {} peers configured on WireGuard interface",
263+
peers.len()
264+
);
265+
// Filter out never connected peers.
266+
peers.retain(|_, peer| {
267+
// Last handshake time-stamp must exist...
268+
if let Some(last_hs) = peer.last_handshake {
269+
// ...and not be UNIX epoch.
270+
if last_hs != SystemTime::UNIX_EPOCH
271+
&& match peer_map.get(&peer.public_key) {
272+
Some(last_peer) => last_peer != peer,
273+
None => true,
274+
}
275+
{
276+
debug!(
277+
"Peer {} statistics changed; keeping it.",
278+
peer.public_key
279+
);
280+
peer_map.insert(peer.public_key.clone(), peer.clone());
281+
return true;
282+
}
265283
}
284+
debug!(
285+
"Peer {} statistics didn't change; ignoring it.",
286+
peer.public_key
287+
);
288+
false
289+
});
290+
if let Err(err) = tx.send(Ok(host.into())).await {
291+
error!(
292+
"Couldn't send network usage stats update for {ifname}: {err}"
293+
);
294+
break;
266295
}
267-
debug!("Peer {} statistics didn't change; ignoring it.", peer.public_key);
268-
false
269-
});
270-
if let Err(err) = tx.send(Ok(host.into())).await {
296+
}
297+
Err(err) => {
271298
error!(
272-
"Couldn't send network usage stats update for {ifname}: {err}"
299+
"Failed to retrieve network usage stats for interface {ifname}: \
300+
{err}"
273301
);
274302
break;
275303
}
276304
}
277-
Err(err) => {
278-
error!("Failed to retrieve network usage stats for interface {ifname}: {err}");
279-
break;
280-
}
305+
debug!("Network activity statistics for interface {ifname} sent to the client");
281306
}
282-
debug!("Network activity statistics for interface {ifname} sent to the client");
283-
}
284-
debug!(
285-
"The client has disconnected from the network usage statistics data stream \
307+
debug!(
308+
"The client has disconnected from the network usage statistics data stream \
286309
for interface {ifname}, stopping the statistics data collection task."
287-
);
288-
}.instrument(span));
310+
);
311+
}
312+
.instrument(span),
313+
);
289314

290315
let output_stream = ReceiverStream::new(rx);
291316
Ok(Response::new(

src-tauri/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,8 @@ pub(crate) async fn disconnect_interface(
749749
);
750750
let _ = execute_command(pre_down);
751751
info!(
752-
"Executed defined PreDown command before setting up the interface {} for \
753-
the tunnel {tunnel}: {pre_down}",
752+
"Executed defined PreDown command before setting up the interface {} for the \
753+
tunnel {tunnel}: {pre_down}",
754754
active_connection.interface_name
755755
);
756756
}

0 commit comments

Comments
 (0)