Skip to content

Commit 70b7b71

Browse files
committed
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 <[email protected]>
1 parent 3c11c03 commit 70b7b71

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

Diff for: device/device.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,20 @@ type Device struct {
5555
publicKey NoisePublicKey
5656
}
5757

58+
rate struct {
59+
underLoadUntil int64
60+
limiter ratelimiter.Ratelimiter
61+
}
62+
5863
peers struct {
59-
empty AtomicBool // empty reports whether len(keyMap) == 0
60-
sync.RWMutex // protects keyMap
64+
sync.RWMutex // protects keyMap
6165
keyMap map[NoisePublicKey]*Peer
6266
}
6367

6468
allowedips AllowedIPs
6569
indexTable IndexTable
6670
cookieChecker CookieChecker
6771

68-
rate struct {
69-
underLoadUntil int64
70-
limiter ratelimiter.Ratelimiter
71-
}
72-
7372
pool struct {
7473
messageBuffers *WaitPool
7574
inboundElements *WaitPool
@@ -135,7 +134,6 @@ func removePeerLocked(device *Device, peer *Peer, key NoisePublicKey) {
135134

136135
// remove from peer map
137136
delete(device.peers.keyMap, key)
138-
device.peers.empty.Set(len(device.peers.keyMap) == 0)
139137
}
140138

141139
// changeState attempts to change the device state to match want.

Diff for: device/peer.go

-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ func (device *Device) NewPeer(pk NoisePublicKey) (*Peer, error) {
111111

112112
// add
113113
device.peers.keyMap[pk] = peer
114-
device.peers.empty.Set(false)
115114

116115
// start peer
117116
peer.timersInit()

Diff for: device/timers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (timer *Timer) IsPending() bool {
7171
}
7272

7373
func (peer *Peer) timersActive() bool {
74-
return peer.isRunning.Get() && peer.device != nil && peer.device.isUp() && !peer.device.peers.empty.Get()
74+
return peer.isRunning.Get() && peer.device != nil && peer.device.isUp()
7575
}
7676

7777
func expiredRetransmitHandshake(peer *Peer) {

0 commit comments

Comments
 (0)