]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: get rid of peers.empty boolean in timersActive
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 25 Feb 2021 11:28:53 +0000 (12:28 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sat, 6 Mar 2021 15:44:38 +0000 (08:44 -0700)
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>
device/device.go
device/peer.go
device/timers.go

index 4b131a2cb97f486f1048f70145a99d5b93e59e3e..3b8770b92c38191eefe741294c4a84241ffb8087 100644 (file)
@@ -55,9 +55,13 @@ type Device struct {
                publicKey  NoisePublicKey
        }
 
+       rate struct {
+               underLoadUntil int64
+               limiter        ratelimiter.Ratelimiter
+       }
+
        peers struct {
-               empty        AtomicBool // empty reports whether len(keyMap) == 0
-               sync.RWMutex            // protects keyMap
+               sync.RWMutex // protects keyMap
                keyMap       map[NoisePublicKey]*Peer
        }
 
@@ -65,11 +69,6 @@ type Device struct {
        indexTable    IndexTable
        cookieChecker CookieChecker
 
-       rate struct {
-               underLoadUntil int64
-               limiter        ratelimiter.Ratelimiter
-       }
-
        pool struct {
                messageBuffers   *WaitPool
                inboundElements  *WaitPool
@@ -135,7 +134,6 @@ func removePeerLocked(device *Device, peer *Peer, key NoisePublicKey) {
 
        // remove from peer map
        delete(device.peers.keyMap, key)
-       device.peers.empty.Set(len(device.peers.keyMap) == 0)
 }
 
 // changeState attempts to change the device state to match want.
index 332f7bd190fa414d1c9b0f4049405efcb9d6b7fc..a063b91419e2d04406e081ce4999ca97a8df1fbe 100644 (file)
@@ -111,7 +111,6 @@ func (device *Device) NewPeer(pk NoisePublicKey) (*Peer, error) {
 
        // add
        device.peers.keyMap[pk] = peer
-       device.peers.empty.Set(false)
 
        // start peer
        peer.timersInit()
index fa44874c2cfe4c8fc04a88316f2df3f26bb6b1ec..ee191e55bdd2fc4f8da95fed3ee10dd259d1af05 100644 (file)
@@ -71,7 +71,7 @@ func (timer *Timer) IsPending() 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) {