Skip to content

Commit 5290a10

Browse files
committed
device: switch to regular mutex for keypair guard
name old time/op new time/op delta TrieIPv4Peers100Addresses1000-32 83.5ns ± 0% 83.3ns ± 0% ~ (p=1.000 n=1+1) TrieIPv4Peers10Addresses10-32 33.6ns ± 0% 33.4ns ± 0% ~ (p=1.000 n=1+1) TrieIPv6Peers100Addresses1000-32 83.3ns ± 0% 83.2ns ± 0% ~ (p=1.000 n=1+1) TrieIPv6Peers10Addresses10-32 33.5ns ± 0% 33.2ns ± 0% ~ (p=1.000 n=1+1) Latency-32 216µs ± 0% 216µs ± 0% ~ (p=1.000 n=1+1) Throughput-32 2.31µs ± 0% 2.28µs ± 0% ~ (p=1.000 n=1+1) UAPIGet-32 2.28µs ± 0% 2.13µs ± 0% ~ (p=1.000 n=1+1) WaitPool-32 4.18µs ± 0% 4.14µs ± 0% ~ (p=1.000 n=1+1) name old packet-loss new packet-loss delta Throughput-32 0.00 ± 0% 0.01 ± 0% ~ (p=1.000 n=1+1) name old alloc/op new alloc/op delta UAPIGet-32 224B ± 0% 224B ± 0% ~ (all equal) name old allocs/op new allocs/op delta UAPIGet-32 17.0 ± 0% 17.0 ± 0% ~ (all equal)
1 parent 657e769 commit 5290a10

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

Diff for: device/device.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,8 @@ func (device *Device) SendKeepalivesToPeersWithCurrentKeypair() {
392392

393393
device.peers.RLock()
394394
for _, peer := range device.peers.keyMap {
395-
peer.keypairs.RLock()
396-
sendKeepalive := peer.keypairs.current != nil && !peer.keypairs.current.created.Add(RejectAfterTime).Before(time.Now())
397-
peer.keypairs.RUnlock()
398-
if sendKeepalive {
395+
current := peer.keypairs.Current()
396+
if current.created.Add(RejectAfterTime).Before(time.Now()) {
399397
peer.SendKeepalive()
400398
}
401399
}

Diff for: device/keypair.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ type Keypair struct {
3333
}
3434

3535
type Keypairs struct {
36-
sync.RWMutex
36+
sync.Mutex
3737
current *Keypair
3838
previous *Keypair
3939
next *Keypair
4040
}
4141

4242
func (kp *Keypairs) Current() *Keypair {
43-
kp.RLock()
44-
defer kp.RUnlock()
43+
kp.Lock()
44+
defer kp.Unlock()
4545
return kp.current
4646
}
4747

0 commit comments

Comments
 (0)