File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -355,7 +355,24 @@ impl Host {
355355 WgDeviceAttrs :: Peers ( nlas) => {
356356 for nla in nlas {
357357 let peer = Peer :: from_nlas ( nla) ;
358- self . peers . insert ( peer. public_key . clone ( ) , peer) ;
358+ // On some systems, a dual-stack (IPv4 + IPv6) configuration creates separate peer entries
359+ // for each address family. These entries share the same public key, so inserting a new
360+ // peer would overwrite the existing one. To avoid this, we first check if the peer
361+ // already exists and, if it does, update its statistics instead of replacing it.
362+ // https://github.com/DefGuard/client/issues/617
363+ if let Some ( existing_peer) = self . peers . get_mut ( & peer. public_key ) {
364+ existing_peer. rx_bytes += peer. rx_bytes ;
365+ existing_peer. tx_bytes += peer. tx_bytes ;
366+ existing_peer. last_handshake =
367+ match ( existing_peer. last_handshake , peer. last_handshake ) {
368+ ( Some ( x) , Some ( y) ) => Some ( x. max ( y) ) ,
369+ ( Some ( x) , None ) => Some ( x) ,
370+ ( None , Some ( y) ) => Some ( y) ,
371+ ( None , None ) => None ,
372+ } ;
373+ } else {
374+ self . peers . insert ( peer. public_key . clone ( ) , peer) ;
375+ }
359376 }
360377 }
361378 _ => ( ) ,
You can’t perform that action at this time.
0 commit comments