aboutsummaryrefslogtreecommitdiffstats
path: root/receive.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-13 19:33:41 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-13 19:34:28 +0200
commit2326d6a4d75f9f3736046cc526eb593a403d4c7a (patch)
treeda31622899bb84e256b22addd1604b8250582c44 /receive.go
parentCleanup ratelimiter (diff)
downloadwireguard-go-2326d6a4d75f9f3736046cc526eb593a403d4c7a.tar.xz
wireguard-go-2326d6a4d75f9f3736046cc526eb593a403d4c7a.zip
Odds and ends
Diffstat (limited to '')
-rw-r--r--receive.go26
1 files changed, 15 insertions, 11 deletions
diff --git a/receive.go b/receive.go
index 60a2510..32ff512 100644
--- a/receive.go
+++ b/receive.go
@@ -600,20 +600,24 @@ func (peer *Peer) RoutineSequentialReceiver() {
// check if using new key-pair
kp := &peer.keypairs
- kp.mutex.Lock() //TODO: make this into an RW lock to reduce contention here for the equality check which is rarely true
if kp.next == elem.keypair {
- old := kp.previous
- kp.previous = kp.current
- device.DeleteKeypair(old)
- kp.current = kp.next
- kp.next = nil
- peer.timersHandshakeComplete()
- select {
- case peer.signals.newKeypairArrived <- struct{}{}:
- default:
+ kp.mutex.Lock()
+ if kp.next != elem.keypair {
+ kp.mutex.Unlock()
+ } else {
+ old := kp.previous
+ kp.previous = kp.current
+ device.DeleteKeypair(old)
+ kp.current = kp.next
+ kp.next = nil
+ kp.mutex.Unlock()
+ peer.timersHandshakeComplete()
+ select {
+ case peer.signals.newKeypairArrived <- struct{}{}:
+ default:
+ }
}
}
- kp.mutex.Unlock()
peer.keepKeyFreshReceiving()
peer.timersAnyAuthenticatedPacketTraversal()