From 18b6627f33883e28dd69b2990c52359002856694 Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Mon, 3 Jun 2019 15:46:46 -0400 Subject: device, ratelimiter: replace uses of time.Now().Sub() with time.Since() Simplification found by staticcheck: $ staticcheck ./... | grep S1012 device/cookie.go:90:5: should use time.Since instead of time.Now().Sub (S1012) device/cookie.go:127:5: should use time.Since instead of time.Now().Sub (S1012) device/cookie.go:242:5: should use time.Since instead of time.Now().Sub (S1012) device/noise-protocol.go:304:13: should use time.Since instead of time.Now().Sub (S1012) device/receive.go:82:46: should use time.Since instead of time.Now().Sub (S1012) device/send.go:132:5: should use time.Since instead of time.Now().Sub (S1012) device/send.go:139:5: should use time.Since instead of time.Now().Sub (S1012) device/send.go:235:59: should use time.Since instead of time.Now().Sub (S1012) device/send.go:393:9: should use time.Since instead of time.Now().Sub (S1012) ratelimiter/ratelimiter.go:79:10: should use time.Since instead of time.Now().Sub (S1012) ratelimiter/ratelimiter.go:87:10: should use time.Since instead of time.Now().Sub (S1012) Change applied using: $ find . -type f -name "*.go" -exec sed -i "s/Now().Sub(/Since(/g" {} \; Signed-off-by: Matt Layher --- device/cookie.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'device/cookie.go') 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 } -- cgit v1.2.3-59-g8ed1b