mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2025-08-18 04:35:47 +02:00
Add missing locks and fix debug output, and try to flush queues
Flushing queues on exit is sort of a partial solution, but this could be better. Really what we want is for no more packets to be enqueued after isUp is set to false.
This commit is contained in:
15
device.go
15
device.go
@@ -339,6 +339,8 @@ func (device *Device) RemovePeer(key NoisePublicKey) {
|
||||
}
|
||||
|
||||
func (device *Device) RemoveAllPeers() {
|
||||
device.noise.mutex.Lock()
|
||||
defer device.noise.mutex.Unlock()
|
||||
|
||||
device.routing.mutex.Lock()
|
||||
defer device.routing.mutex.Unlock()
|
||||
@@ -354,16 +356,25 @@ func (device *Device) RemoveAllPeers() {
|
||||
}
|
||||
|
||||
func (device *Device) Close() {
|
||||
device.log.Info.Println("Device closing")
|
||||
if device.isClosed.Swap(true) {
|
||||
return
|
||||
}
|
||||
device.signal.stop.Broadcast()
|
||||
device.log.Info.Println("Device closing")
|
||||
device.state.changing.Set(true)
|
||||
device.state.mutex.Lock()
|
||||
defer device.state.mutex.Unlock()
|
||||
|
||||
device.tun.device.Close()
|
||||
device.BindClose()
|
||||
|
||||
device.isUp.Set(false)
|
||||
|
||||
device.signal.stop.Broadcast()
|
||||
|
||||
device.RemoveAllPeers()
|
||||
device.rate.limiter.Close()
|
||||
|
||||
device.state.changing.Set(false)
|
||||
device.log.Info.Println("Interface closed")
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user