From 99f5c8e26f79ad228efd85f33534abd28757bff0 Mon Sep 17 00:00:00 2001
From: Jono Wenger <jono@elixxir.io>
Date: Fri, 22 Apr 2022 10:42:05 -0700
Subject: [PATCH] Replace usages of time.Now() with netTime.Now()

---
 api/client.go                 | 5 +++--
 auth/store/store_test.go      | 3 ++-
 auth/utils_test.go            | 4 ++--
 cmix/identity/tracker_test.go | 4 ++--
 cmix/polltracker_test.go      | 5 +++--
 cmix/utils_test.go            | 2 +-
 e2e/manager.go                | 5 +++--
 storage/utility/bucket.go     | 2 +-
 xxmutils/restoreContacts.go   | 3 ++-
 9 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/api/client.go b/api/client.go
index a8e641a49..7145b1f80 100644
--- a/api/client.go
+++ b/api/client.go
@@ -9,6 +9,7 @@ package api
 
 import (
 	"encoding/json"
+	"gitlab.com/xx_network/primitives/netTime"
 	"math"
 	"time"
 
@@ -94,10 +95,10 @@ func NewClient(ndfJSON, storageDir string, password []byte,
 	}
 
 	cmixGrp, e2eGrp := decodeGroups(def)
-	start := time.Now()
+	start := netTime.Now()
 	protoUser := createNewUser(rngStreamGen, cmixGrp, e2eGrp)
 	jww.DEBUG.Printf("PortableUserInfo generation took: %s",
-		time.Now().Sub(start))
+		netTime.Now().Sub(start))
 
 	_, err = checkVersionAndSetupStorage(def, storageDir, password,
 		protoUser, cmixGrp, e2eGrp, rngStreamGen,
diff --git a/auth/store/store_test.go b/auth/store/store_test.go
index 882ac6ac1..e6b14e7e0 100644
--- a/auth/store/store_test.go
+++ b/auth/store/store_test.go
@@ -25,6 +25,7 @@ import (
 	"gitlab.com/xx_network/crypto/csprng"
 	"gitlab.com/xx_network/crypto/large"
 	"gitlab.com/xx_network/primitives/id"
+	"gitlab.com/xx_network/primitives/netTime"
 	"io"
 	"math/rand"
 	"reflect"
@@ -923,7 +924,7 @@ func makeTestRound(t *testing.T) rounds.Round {
 			State:                      2,
 			BatchSize:                  5,
 			Topology:                   [][]byte{[]byte("one"), []byte("two")},
-			Timestamps:                 []uint64{uint64(time.Now().UnixNano()), uint64(time.Now().UnixNano())},
+			Timestamps:                 []uint64{uint64(netTime.Now().UnixNano()), uint64(netTime.Now().UnixNano())},
 			Errors:                     nil,
 			ClientErrors:               nil,
 			ResourceQueueTimeoutMillis: 0,
diff --git a/auth/utils_test.go b/auth/utils_test.go
index 2a6c16ecc..da9f6d7c0 100644
--- a/auth/utils_test.go
+++ b/auth/utils_test.go
@@ -9,9 +9,9 @@ import (
 	"gitlab.com/xx_network/comms/connect"
 	"gitlab.com/xx_network/crypto/large"
 	"gitlab.com/xx_network/primitives/id"
+	"gitlab.com/xx_network/primitives/netTime"
 	"math/rand"
 	"testing"
-	"time"
 )
 
 type mockSentRequestHandler struct{}
@@ -75,7 +75,7 @@ func makeTestRound(t *testing.T) rounds.Round {
 			State:                      2,
 			BatchSize:                  5,
 			Topology:                   [][]byte{[]byte("test"), []byte("test")},
-			Timestamps:                 []uint64{uint64(time.Now().UnixNano()), uint64(time.Now().UnixNano())},
+			Timestamps:                 []uint64{uint64(netTime.Now().UnixNano()), uint64(netTime.Now().UnixNano())},
 			Errors:                     nil,
 			ClientErrors:               nil,
 			ResourceQueueTimeoutMillis: 0,
diff --git a/cmix/identity/tracker_test.go b/cmix/identity/tracker_test.go
index ef7241c64..f8b28740d 100644
--- a/cmix/identity/tracker_test.go
+++ b/cmix/identity/tracker_test.go
@@ -36,7 +36,7 @@ func TestManager_processIdentities_expired(t *testing.T) {
 	// Add some expired test IDs
 	for i := uint64(0); i < 10; i++ {
 		testId := id.NewIdFromUInt(i, id.User, t)
-		validUntil := time.Now()
+		validUntil := netTime.Now()
 		m.tracked = append(m.tracked, TrackedID{
 			NextGeneration: netTime.Now().Add(-time.Second),
 			LastGeneration: time.Time{},
@@ -75,7 +75,7 @@ func TestManager_processIdentities(t *testing.T) {
 
 	// Add some expired test IDs
 	testId := id.NewIdFromUInt(0, id.User, t)
-	validUntil := time.Now().Add(time.Minute)
+	validUntil := netTime.Now().Add(time.Minute)
 	m.tracked = append(m.tracked, TrackedID{
 		NextGeneration: netTime.Now(),
 		LastGeneration: time.Time{},
diff --git a/cmix/polltracker_test.go b/cmix/polltracker_test.go
index 9b0812d04..8fb6d9686 100644
--- a/cmix/polltracker_test.go
+++ b/cmix/polltracker_test.go
@@ -3,6 +3,7 @@ package cmix
 import (
 	xxid "gitlab.com/xx_network/primitives/id"
 	"gitlab.com/xx_network/primitives/id/ephemeral"
+	"gitlab.com/xx_network/primitives/netTime"
 	"strings"
 	"testing"
 	"time"
@@ -14,11 +15,11 @@ func TestPollTracker(t *testing.T) {
 
 	// Init ID and first EID
 	id := xxid.NewIdFromString("zezima", xxid.User, t)
-	eid, _, _, err := ephemeral.GetId(id, 16, time.Now().UnixNano())
+	eid, _, _, err := ephemeral.GetId(id, 16, netTime.Now().UnixNano())
 	if err != nil {
 		t.Errorf("Failed to create eid for ID %s", id.String())
 	}
-	eid2, _, _, err := ephemeral.GetId(id, 16, time.Now().Add(time.Hour*24).UnixNano())
+	eid2, _, _, err := ephemeral.GetId(id, 16, netTime.Now().Add(time.Hour*24).UnixNano())
 	if err != nil {
 		t.Errorf("Failed to create second eid for ID %s", id.String())
 	}
diff --git a/cmix/utils_test.go b/cmix/utils_test.go
index 2d45401c6..6fffb13db 100644
--- a/cmix/utils_test.go
+++ b/cmix/utils_test.go
@@ -227,7 +227,7 @@ func newTestClient(t *testing.T) (*client, error) {
 	}
 	pubKey := pk.GetPublic()
 
-	now := time.Now()
+	now := netTime.Now()
 	timestamps := []uint64{
 		uint64(now.Add(-30 * time.Second).UnixNano()), //PENDING
 		uint64(now.Add(-25 * time.Second).UnixNano()), //PRECOMPUTING
diff --git a/e2e/manager.go b/e2e/manager.go
index 885748a08..de6f09d78 100644
--- a/e2e/manager.go
+++ b/e2e/manager.go
@@ -2,6 +2,7 @@ package e2e
 
 import (
 	"encoding/json"
+	"gitlab.com/xx_network/primitives/netTime"
 	"strings"
 	"time"
 
@@ -55,7 +56,7 @@ func initE2E(kv *versioned.KV, myID *id.ID, privKey *cyclic.Int,
 	}
 	err = kv.Set(e2eRekeyParamsKey, e2eRekeyParamsVer, &versioned.Object{
 		Version:   e2eRekeyParamsVer,
-		Timestamp: time.Now(),
+		Timestamp: netTime.Now(),
 		Data:      rekeyParamsData,
 	})
 	if err != nil {
@@ -101,7 +102,7 @@ func LoadLegacy(kv *versioned.KV, net cmix.Client, myID *id.ID,
 	// Store the rekey params to disk/memory
 	err = kv.Set(e2eRekeyParamsKey, e2eRekeyParamsVer, &versioned.Object{
 		Version:   e2eRekeyParamsVer,
-		Timestamp: time.Now(),
+		Timestamp: netTime.Now(),
 		Data:      rekeyParamsData,
 	})
 
diff --git a/storage/utility/bucket.go b/storage/utility/bucket.go
index 5548cdfe5..46b3da9a9 100644
--- a/storage/utility/bucket.go
+++ b/storage/utility/bucket.go
@@ -42,7 +42,7 @@ func NewStoredBucket(capacity, leaked uint32, leakDuration time.Duration,
 		kv: kv.Prefix(bucketStorePrefix),
 	}
 
-	bs.save(0, time.Now().UnixNano())
+	bs.save(0, netTime.Now().UnixNano())
 
 	return rateLimiting.CreateBucket(capacity, leaked, leakDuration, bs.save)
 }
diff --git a/xxmutils/restoreContacts.go b/xxmutils/restoreContacts.go
index b64947418..6b8afad70 100644
--- a/xxmutils/restoreContacts.go
+++ b/xxmutils/restoreContacts.go
@@ -11,6 +11,7 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
+	"gitlab.com/xx_network/primitives/netTime"
 	"math"
 	"strings"
 	"sync"
@@ -287,7 +288,7 @@ func (s stateStore) set(user *contact.Contact, state restoreState) error {
 	data = append(data, user.Marshal()...)
 	val := &versioned.Object{
 		Version:   0,
-		Timestamp: time.Now(),
+		Timestamp: netTime.Now(),
 		Data:      data,
 	}
 	return s.apiStore.Set(key, val)
-- 
GitLab