mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-21 23:03:08 +01:00
device: get rid of peers.empty boolean in timersActive
There's no way for len(peers)==0 when a current peer has isRunning==false. This requires some struct reshuffling so that the uint64 pointer is aligned. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
3c11c0308e
commit
593658d975
@ -55,9 +55,13 @@ type Device struct {
|
|||||||
publicKey NoisePublicKey
|
publicKey NoisePublicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rate struct {
|
||||||
|
underLoadUntil int64
|
||||||
|
limiter ratelimiter.Ratelimiter
|
||||||
|
}
|
||||||
|
|
||||||
peers struct {
|
peers struct {
|
||||||
empty AtomicBool // empty reports whether len(keyMap) == 0
|
sync.RWMutex // protects keyMap
|
||||||
sync.RWMutex // protects keyMap
|
|
||||||
keyMap map[NoisePublicKey]*Peer
|
keyMap map[NoisePublicKey]*Peer
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,11 +69,6 @@ type Device struct {
|
|||||||
indexTable IndexTable
|
indexTable IndexTable
|
||||||
cookieChecker CookieChecker
|
cookieChecker CookieChecker
|
||||||
|
|
||||||
rate struct {
|
|
||||||
underLoadUntil int64
|
|
||||||
limiter ratelimiter.Ratelimiter
|
|
||||||
}
|
|
||||||
|
|
||||||
pool struct {
|
pool struct {
|
||||||
messageBuffers *WaitPool
|
messageBuffers *WaitPool
|
||||||
inboundElements *WaitPool
|
inboundElements *WaitPool
|
||||||
@ -135,7 +134,6 @@ func removePeerLocked(device *Device, peer *Peer, key NoisePublicKey) {
|
|||||||
|
|
||||||
// remove from peer map
|
// remove from peer map
|
||||||
delete(device.peers.keyMap, key)
|
delete(device.peers.keyMap, key)
|
||||||
device.peers.empty.Set(len(device.peers.keyMap) == 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// changeState attempts to change the device state to match want.
|
// changeState attempts to change the device state to match want.
|
||||||
|
@ -111,7 +111,6 @@ func (device *Device) NewPeer(pk NoisePublicKey) (*Peer, error) {
|
|||||||
|
|
||||||
// add
|
// add
|
||||||
device.peers.keyMap[pk] = peer
|
device.peers.keyMap[pk] = peer
|
||||||
device.peers.empty.Set(false)
|
|
||||||
|
|
||||||
// start peer
|
// start peer
|
||||||
peer.timersInit()
|
peer.timersInit()
|
||||||
|
@ -71,7 +71,7 @@ func (timer *Timer) IsPending() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (peer *Peer) timersActive() bool {
|
func (peer *Peer) timersActive() bool {
|
||||||
return peer.isRunning.Get() && peer.device != nil && peer.device.isUp() && !peer.device.peers.empty.Get()
|
return peer.isRunning.Get() && peer.device != nil && peer.device.isUp()
|
||||||
}
|
}
|
||||||
|
|
||||||
func expiredRetransmitHandshake(peer *Peer) {
|
func expiredRetransmitHandshake(peer *Peer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user