@@ -122,8 +122,8 @@ impl DesktopDaemonService for DaemonService {
122
122
debug ! ( "Done creating a new interface {ifname}" ) ;
123
123
}
124
124
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.
127
127
debug ! ( "Preparing DNS configuration for interface {ifname}" ) ;
128
128
let dns_string = request. dns . unwrap_or_default ( ) ;
129
129
let dns_entries = dns_string. split ( ',' ) . map ( str:: trim) . collect :: < Vec < & str > > ( ) ;
@@ -137,7 +137,10 @@ impl DesktopDaemonService for DaemonService {
137
137
search_domains. push ( entry) ;
138
138
}
139
139
}
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
+ ) ;
141
144
142
145
#[ cfg( not( windows) ) ]
143
146
let configure_interface_result = wgapi. configure_interface ( & config) ;
@@ -161,9 +164,15 @@ impl DesktopDaemonService for DaemonService {
161
164
} ) ?;
162
165
163
166
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
+ ) ;
165
171
} 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
+ ) ;
167
176
wgapi. configure_dns ( & dns, & search_domains) . map_err ( |err| {
168
177
let msg =
169
178
format ! ( "Failed to configure DNS for WireGuard interface {ifname}: {err}" ) ;
@@ -221,7 +230,8 @@ impl DesktopDaemonService for DaemonService {
221
230
let request = request. into_inner ( ) ;
222
231
let ifname = request. interface_name ;
223
232
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}"
225
235
) ;
226
236
let span = info_span ! ( "read_interface_data" , interface_name = & ifname) ;
227
237
@@ -234,58 +244,73 @@ impl DesktopDaemonService for DaemonService {
234
244
info ! ( "Spawning statistics collector task for interface {ifname}" ) ;
235
245
} ) ;
236
246
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
+ }
265
283
}
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 ;
266
295
}
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) => {
271
298
error ! (
272
- "Couldn't send network usage stats update for {ifname}: {err}"
299
+ "Failed to retrieve network usage stats for interface {ifname}: \
300
+ {err}"
273
301
) ;
274
302
break ;
275
303
}
276
304
}
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" ) ;
281
306
}
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 \
286
309
for interface {ifname}, stopping the statistics data collection task."
287
- ) ;
288
- } . instrument ( span) ) ;
310
+ ) ;
311
+ }
312
+ . instrument ( span) ,
313
+ ) ;
289
314
290
315
let output_stream = ReceiverStream :: new ( rx) ;
291
316
Ok ( Response :: new (
0 commit comments