* NOTE: Not thread safe, but called by sequential receiver!
*/
func (peer *Peer) keepKeyFreshReceiving() {
- if peer.timers.sentLastMinuteHandshake {
+ if peer.timers.sentLastMinuteHandshake.Get() {
return
}
keypair := peer.keypairs.Current()
if keypair != nil && keypair.isInitiator && time.Now().Sub(keypair.created) > (RejectAfterTime-KeepaliveTimeout-RekeyTimeout) {
- peer.timers.sentLastMinuteHandshake = true
+ peer.timers.sentLastMinuteHandshake.Set(true)
peer.SendHandshakeInitiation(false)
}
}
}
func expiredRetransmitHandshake(peer *Peer) {
- if peer.timers.handshakeAttempts > MaxTimerHandshakes {
+ if atomic.LoadUint32(&peer.timers.handshakeAttempts) > MaxTimerHandshakes {
peer.device.log.Debug.Printf("%s: Handshake did not complete after %d attempts, giving up\n", peer, MaxTimerHandshakes+2)
if peer.timersActive() {
peer.timers.zeroKeyMaterial.Mod(RejectAfterTime * 3)
}
} else {
- peer.timers.handshakeAttempts++
- peer.device.log.Debug.Printf("%s: Handshake did not complete after %d seconds, retrying (try %d)\n", peer, int(RekeyTimeout.Seconds()), peer.timers.handshakeAttempts+1)
+ atomic.AddUint32(&peer.timers.handshakeAttempts, 1)
+ peer.device.log.Debug.Printf("%s: Handshake did not complete after %d seconds, retrying (try %d)\n", peer, int(RekeyTimeout.Seconds()), atomic.LoadUint32(&peer.timers.handshakeAttempts)+1)
/* We clear the endpoint address src address, in case this is the cause of trouble. */
peer.mutex.Lock()
func expiredSendKeepalive(peer *Peer) {
peer.SendKeepalive()
- if peer.timers.needAnotherKeepalive {
- peer.timers.needAnotherKeepalive = false
+ if peer.timers.needAnotherKeepalive.Get() {
+ peer.timers.needAnotherKeepalive.Set(false)
if peer.timersActive() {
peer.timers.sendKeepalive.Mod(KeepaliveTimeout)
}
if !peer.timers.sendKeepalive.IsPending() {
peer.timers.sendKeepalive.Mod(KeepaliveTimeout)
} else {
- peer.timers.needAnotherKeepalive = true
+ peer.timers.needAnotherKeepalive.Set(true)
}
}
}
if peer.timersActive() {
peer.timers.retransmitHandshake.Del()
}
- peer.timers.handshakeAttempts = 0
- peer.timers.sentLastMinuteHandshake = false
+ atomic.StoreUint32(&peer.timers.handshakeAttempts, 0)
+ peer.timers.sentLastMinuteHandshake.Set(false)
atomic.StoreInt64(&peer.stats.lastHandshakeNano, time.Now().UnixNano())
}
peer.timers.newHandshake = peer.NewTimer(expiredNewHandshake)
peer.timers.zeroKeyMaterial = peer.NewTimer(expiredZeroKeyMaterial)
peer.timers.persistentKeepalive = peer.NewTimer(expiredPersistentKeepalive)
- peer.timers.handshakeAttempts = 0
- peer.timers.sentLastMinuteHandshake = false
- peer.timers.needAnotherKeepalive = false
+ atomic.StoreUint32(&peer.timers.handshakeAttempts, 0)
+ peer.timers.sentLastMinuteHandshake.Set(false)
+ peer.timers.needAnotherKeepalive.Set(false)
}
func (peer *Peer) timersStop() {