diff --git a/device/cookie.go b/device/cookie.go index 3a88a0c..f134128 100644 --- a/device/cookie.go +++ b/device/cookie.go @@ -87,7 +87,7 @@ func (st *CookieChecker) CheckMAC2(msg []byte, src []byte) bool { st.RLock() defer st.RUnlock() - if time.Now().Sub(st.mac2.secretSet) > CookieRefreshTime { + if time.Since(st.mac2.secretSet) > CookieRefreshTime { return false } @@ -124,7 +124,7 @@ func (st *CookieChecker) CreateReply( // refresh cookie secret - if time.Now().Sub(st.mac2.secretSet) > CookieRefreshTime { + if time.Since(st.mac2.secretSet) > CookieRefreshTime { st.RUnlock() st.Lock() _, err := rand.Read(st.mac2.secret[:]) @@ -239,7 +239,7 @@ func (st *CookieGenerator) AddMacs(msg []byte) { // set mac2 - if time.Now().Sub(st.mac2.cookieSet) > CookieRefreshTime { + if time.Since(st.mac2.cookieSet) > CookieRefreshTime { return } diff --git a/device/noise-protocol.go b/device/noise-protocol.go index 1f70e81..dd75cc3 100644 --- a/device/noise-protocol.go +++ b/device/noise-protocol.go @@ -301,7 +301,7 @@ func (device *Device) ConsumeMessageInitiation(msg *MessageInitiation) *Peer { var ok bool ok = timestamp.After(handshake.lastTimestamp) - ok = ok && time.Now().Sub(handshake.lastInitiationConsumption) > HandshakeInitationRate + ok = ok && time.Since(handshake.lastInitiationConsumption) > HandshakeInitationRate handshake.mutex.RUnlock() if !ok { return nil diff --git a/device/receive.go b/device/receive.go index 22870f2..32d632b 100644 --- a/device/receive.go +++ b/device/receive.go @@ -79,7 +79,7 @@ func (peer *Peer) keepKeyFreshReceiving() { return } keypair := peer.keypairs.Current() - if keypair != nil && keypair.isInitiator && time.Now().Sub(keypair.created) > (RejectAfterTime-KeepaliveTimeout-RekeyTimeout) { + if keypair != nil && keypair.isInitiator && time.Since(keypair.created) > (RejectAfterTime-KeepaliveTimeout-RekeyTimeout) { peer.timers.sentLastMinuteHandshake.Set(true) peer.SendHandshakeInitiation(false) } diff --git a/device/send.go b/device/send.go index ae96aa2..2198427 100644 --- a/device/send.go +++ b/device/send.go @@ -129,14 +129,14 @@ func (peer *Peer) SendHandshakeInitiation(isRetry bool) error { } peer.handshake.mutex.RLock() - if time.Now().Sub(peer.handshake.lastSentHandshake) < RekeyTimeout { + if time.Since(peer.handshake.lastSentHandshake) < RekeyTimeout { peer.handshake.mutex.RUnlock() return nil } peer.handshake.mutex.RUnlock() peer.handshake.mutex.Lock() - if time.Now().Sub(peer.handshake.lastSentHandshake) < RekeyTimeout { + if time.Since(peer.handshake.lastSentHandshake) < RekeyTimeout { peer.handshake.mutex.Unlock() return nil } @@ -232,7 +232,7 @@ func (peer *Peer) keepKeyFreshSending() { return } nonce := atomic.LoadUint64(&keypair.sendNonce) - if nonce > RekeyAfterMessages || (keypair.isInitiator && time.Now().Sub(keypair.created) > RekeyAfterTime) { + if nonce > RekeyAfterMessages || (keypair.isInitiator && time.Since(keypair.created) > RekeyAfterTime) { peer.SendHandshakeInitiation(false) } } @@ -390,7 +390,7 @@ func (peer *Peer) RoutineNonce() { keypair = peer.keypairs.Current() if keypair != nil && keypair.sendNonce < RejectAfterMessages { - if time.Now().Sub(keypair.created) < RejectAfterTime { + if time.Since(keypair.created) < RejectAfterTime { break } } diff --git a/ratelimiter/ratelimiter.go b/ratelimiter/ratelimiter.go index 595e5a5..772c45a 100644 --- a/ratelimiter/ratelimiter.go +++ b/ratelimiter/ratelimiter.go @@ -76,7 +76,7 @@ func (rate *Ratelimiter) Init() { for key, entry := range rate.tableIPv4 { entry.Lock() - if time.Now().Sub(entry.lastTime) > garbageCollectTime { + if time.Since(entry.lastTime) > garbageCollectTime { delete(rate.tableIPv4, key) } entry.Unlock() @@ -84,7 +84,7 @@ func (rate *Ratelimiter) Init() { for key, entry := range rate.tableIPv6 { entry.Lock() - if time.Now().Sub(entry.lastTime) > garbageCollectTime { + if time.Since(entry.lastTime) > garbageCollectTime { delete(rate.tableIPv6, key) } entry.Unlock()