@@ -196,7 +196,10 @@ func (self *WgProxy) SetClients(clients map[netip.Addr]*WgClient) (returnErr err
196196 return
197197 }
198198
199- self .clients = maps .Clone (clients )
199+ clear (self .clients )
200+ for addr , client := range clients {
201+ self .clients [addr ] = client
202+ }
200203 for addr , activeTun := range self .activeClients {
201204 if client , ok := self .clients [addr ]; ok {
202205 tun , err := client .Tun ()
@@ -221,7 +224,17 @@ func (self *WgProxy) AddClients(clients map[netip.Addr]*WgClient) (returnErr err
221224 self .stateLock .Lock ()
222225 defer self .stateLock .Unlock ()
223226
224- peers := createPeerConfigs (clients )
227+ newClients := maps .Clone (clients )
228+ for addr , _ := range newClients {
229+ if _ , ok := self .clients [addr ]; ok {
230+ delete (newClients , addr )
231+ }
232+ }
233+ if len (newClients ) == 0 {
234+ return
235+ }
236+
237+ peers := createPeerConfigs (newClients )
225238
226239 config := wgtypes.Config {
227240 ReplacePeers : false ,
@@ -233,8 +246,10 @@ func (self *WgProxy) AddClients(clients map[netip.Addr]*WgClient) (returnErr err
233246 return
234247 }
235248
236- self .clients = maps .Clone (clients )
237- for addr , client := range clients {
249+ for addr , client := range newClients {
250+ self .clients [addr ] = client
251+ }
252+ for addr , client := range newClients {
238253 if _ , ok := self .activeClients [addr ]; ok {
239254 // refresh the tun
240255 tun , err := client .Tun ()
0 commit comments