diff --git a/bindings/timeNow.go b/bindings/timeNow.go new file mode 100644 index 0000000000000000000000000000000000000000..dbeda1696669f98b9a489990ced0f66f51c9757b --- /dev/null +++ b/bindings/timeNow.go @@ -0,0 +1,24 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 xx network SEZC // +// // +// Use of this source code is governed by a license that can be found in the // +// LICENSE file // +/////////////////////////////////////////////////////////////////////////////// + +package bindings + +import ( + "gitlab.com/xx_network/primitives/netTime" + "time" +) + +type TimeSource interface { + NowMs() int +} + +// SetTimeSource sets the network time to a custom source. +func SetTimeSource(timeNow TimeSource) { + netTime.Now = func() time.Time { + return time.Unix(0, int64(timeNow.NowMs()*int(time.Millisecond))) + } +} diff --git a/go.mod b/go.mod index d58a8c4f7c16931789c5723151f92504175e43c7..14d509875a284a29a4dc1bb1f6e19e5003ddd12b 100644 --- a/go.mod +++ b/go.mod @@ -19,13 +19,13 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/viper v1.7.1 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 - gitlab.com/elixxir/comms v0.0.4-0.20210401210158-6053ad2e224c + gitlab.com/elixxir/comms v0.0.4-0.20210402222700-7fac5f85c596 gitlab.com/elixxir/crypto v0.0.7-0.20210401210040-b7f1da24ef13 gitlab.com/elixxir/ekv v0.1.4 gitlab.com/elixxir/primitives v0.0.3-0.20210401175645-9b7b92f74ec4 gitlab.com/xx_network/comms v0.0.4-0.20210401160731-7b8890cdd8ad gitlab.com/xx_network/crypto v0.0.5-0.20210401160648-4f06cace9123 - gitlab.com/xx_network/primitives v0.0.4-0.20210331161816-ed23858bdb93 + gitlab.com/xx_network/primitives v0.0.4-0.20210402222416-37c1c4d3fac4 golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect google.golang.org/genproto v0.0.0-20210105202744-fe13368bc0e1 // indirect diff --git a/go.sum b/go.sum index 2c4b93e22ed3b5723c898c43a5f9e289dacb1d56..91e103b4070c80b9c1f3ee06a2ba27099a0e852c 100644 --- a/go.sum +++ b/go.sum @@ -85,10 +85,7 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -257,24 +254,18 @@ github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0= github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 h1:Gi6rj4mAlK0BJIk1HIzBVMjWNjIUfstrsXC2VqLYPcA= gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k= -gitlab.com/elixxir/comms v0.0.4-0.20210324213817-bcf120b56ea9 h1:7oDwmGrFtOWrg0gwViSdSj1ntdHcWy8o//pwAcqTNoY= -gitlab.com/elixxir/comms v0.0.4-0.20210324213817-bcf120b56ea9/go.mod h1:2mXUixKz4sTwuXXmAoFKyrfU8uQxWdAd0gLiSpAOV38= -gitlab.com/elixxir/comms v0.0.4-0.20210326171912-e70c1821bf11 h1:B1HilXNXFgE3M3e0AiaKydepNDPepmYGW+pBN7lzinQ= -gitlab.com/elixxir/comms v0.0.4-0.20210326171912-e70c1821bf11/go.mod h1:+8BoGqi7XAGGsX0oYsmA2Mv0gQ2ETujqgx/Q5Be0EU8= -gitlab.com/elixxir/comms v0.0.4-0.20210401161030-7ace84f51ba1 h1:8NQRw+SXHgbbiUAKoPLdE6/AGbUWdKLIVW6mTm44mFs= -gitlab.com/elixxir/comms v0.0.4-0.20210401161030-7ace84f51ba1/go.mod h1:A95i072Mpvgv298+SJBhpLoC/7ow1qQ1ClJOrmx39hg= -gitlab.com/elixxir/comms v0.0.4-0.20210401210158-6053ad2e224c h1:NRo6oQanUuHRdrLQrZJYk1HbcbdkJyMUsG6ac4ZLQiQ= -gitlab.com/elixxir/comms v0.0.4-0.20210401210158-6053ad2e224c/go.mod h1:QXRI0znExoj6ozFASj+cIsOXOLwD+9v9uViRCex/ZC8= +gitlab.com/elixxir/comms v0.0.4-0.20210402183711-0350710740e7 h1:JfR2UVZDqAIQeicHq7ZIPuJyPzkcr59OT5uGz4XyFiI= +gitlab.com/elixxir/comms v0.0.4-0.20210402183711-0350710740e7/go.mod h1:3ikLStVfz4wUMgzL/WkDE9umkeizAKMlO5GQcnDmH5c= +gitlab.com/elixxir/comms v0.0.4-0.20210402205438-eca60a717c47 h1:w0SarO3yraN81dZJan7lDz6OjexoqP52kRAdlnfCr4o= +gitlab.com/elixxir/comms v0.0.4-0.20210402205438-eca60a717c47/go.mod h1:Hd9NbUwdRXFcs5ZgukPYsChmM8AqxJRjzMNvQuUXqh4= +gitlab.com/elixxir/comms v0.0.4-0.20210402205854-0ea056917a98 h1:6GF+txzdbf5EKZKXcwfHagH7G+vmDmMjQZAoMSsHXm4= +gitlab.com/elixxir/comms v0.0.4-0.20210402205854-0ea056917a98/go.mod h1:Hd9NbUwdRXFcs5ZgukPYsChmM8AqxJRjzMNvQuUXqh4= +gitlab.com/elixxir/comms v0.0.4-0.20210402222700-7fac5f85c596 h1:jX6H4vu//StDLKZn5lcmxp9S3IhzS/8Uttg0K5r7Iqo= +gitlab.com/elixxir/comms v0.0.4-0.20210402222700-7fac5f85c596/go.mod h1:jqqUYnsftpfQXJ57BPYp5A+i7qfA5IXhKUE9ZOSrqaE= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4 h1:28ftZDeYEko7xptCZzeFWS1Iam95dj46TWFVVlKmw6A= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.3 h1:znCt/x2bL4y8czTPaaFkwzdgSgW3BJc/1+dxyf1jqVw= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= -gitlab.com/elixxir/crypto v0.0.7-0.20210319231554-b73b6e62ddbc h1:r2nJ1opPnvaY/46nqOHxBEh/QlbNH3O7hurfDtJC0Wk= -gitlab.com/elixxir/crypto v0.0.7-0.20210319231554-b73b6e62ddbc/go.mod h1:Th9bJRvEQecOFW0coD21AzzIBoNDOXcP3+hIGXELCXE= -gitlab.com/elixxir/crypto v0.0.7-0.20210326171146-c137bd7b0c6e h1:+zoFtqHyHUflsF1DPf+vty8o1hur5gQyBy6FERmPKyg= -gitlab.com/elixxir/crypto v0.0.7-0.20210326171146-c137bd7b0c6e/go.mod h1:bmCiS3OH4BGWL6Y/hnvA3jsNYd736UERL4UU9ScdbZQ= -gitlab.com/elixxir/crypto v0.0.7-0.20210401160850-96cbf25fc59e h1:jShX0uoSujeCsfOmd488Y2/5eBC95DpuAgE9hCvxQxE= -gitlab.com/elixxir/crypto v0.0.7-0.20210401160850-96cbf25fc59e/go.mod h1:FB/p76sl1IOZy6biKSs+ESj4pC75Wc4qMpdWwCnddWk= gitlab.com/elixxir/crypto v0.0.7-0.20210401210040-b7f1da24ef13 h1:x6oSLhgzhBcXeItHQ7OlDNoyvebgyNdGCaywAP/IkMc= gitlab.com/elixxir/crypto v0.0.7-0.20210401210040-b7f1da24ef13/go.mod h1:5k+LGynIQa42jZ/UbNVwBiZGHKvLXbXXkqyuTY6uHs0= gitlab.com/elixxir/ekv v0.1.4 h1:NLVMwsFEKArWcsDHu2DbXlm9374iSgn7oIA3rVSsvjc= @@ -284,26 +275,14 @@ gitlab.com/elixxir/primitives v0.0.0-20200804170709-a1896d262cd9/go.mod h1:p0Vel gitlab.com/elixxir/primitives v0.0.0-20200804182913-788f47bded40/go.mod h1:tzdFFvb1ESmuTCOl1z6+yf6oAICDxH2NPUemVgoNLxc= gitlab.com/elixxir/primitives v0.0.1 h1:q61anawANlNAExfkeQEE1NCsNih6vNV1FFLoUQX6txQ= gitlab.com/elixxir/primitives v0.0.1/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2YKnw5c+LJCE= -gitlab.com/elixxir/primitives v0.0.3-0.20210309193003-ef42ebb4800b h1:TswWfqiZqsdPLeWsfe7VJHMlV01W792kRHGYfYwb2Lk= -gitlab.com/elixxir/primitives v0.0.3-0.20210309193003-ef42ebb4800b/go.mod h1:/e3a4KPqmA9V22qKSZ9prfYYNzIzvLI8xh7noVV091w= -gitlab.com/elixxir/primitives v0.0.3-0.20210326022836-1143187bd2fe h1:fOZONg2RIiMtJoXdQHBSAdhv8/fm03VGEnZWcF9DJ8Q= -gitlab.com/elixxir/primitives v0.0.3-0.20210326022836-1143187bd2fe/go.mod h1:/e3a4KPqmA9V22qKSZ9prfYYNzIzvLI8xh7noVV091w= -gitlab.com/elixxir/primitives v0.0.3-0.20210401160752-2fe779c9fb2a h1:EyBlFKVP5905RCA9Rf18EfZwYurUW4b8LmZLv9TOC4I= -gitlab.com/elixxir/primitives v0.0.3-0.20210401160752-2fe779c9fb2a/go.mod h1:9qqDucNbLP9ArL1VKCXQuqYrcAbJIUcI8uzbP7NmKDw= gitlab.com/elixxir/primitives v0.0.3-0.20210401175645-9b7b92f74ec4 h1:PFrOIpax1IMXS7jVGFhOF3bSOWh3IWhNUD18n1DzSZM= gitlab.com/elixxir/primitives v0.0.3-0.20210401175645-9b7b92f74ec4/go.mod h1:9qqDucNbLP9ArL1VKCXQuqYrcAbJIUcI8uzbP7NmKDw= gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw= -gitlab.com/xx_network/comms v0.0.4-0.20210323233204-5acf90f56550 h1:pLEE4KyitAexCMenkTA2BnPP5McXmLp/LVXrful7pZQ= -gitlab.com/xx_network/comms v0.0.4-0.20210323233204-5acf90f56550/go.mod h1:0Hx+zO3Pr4uYw4RZXFnPM3ocjY6bPIKDiHCjWTZLOSI= -gitlab.com/xx_network/comms v0.0.4-0.20210326005744-5e73cbf0f525 h1:wfAzcd9Cv3tUQT23odiEDNcBYjn+Q9w7qQfSbmw6F/c= -gitlab.com/xx_network/comms v0.0.4-0.20210326005744-5e73cbf0f525/go.mod h1:0Hx+zO3Pr4uYw4RZXFnPM3ocjY6bPIKDiHCjWTZLOSI= gitlab.com/xx_network/comms v0.0.4-0.20210401160731-7b8890cdd8ad h1:0E4wnLoOqODo6K2SwVG18y63sns4WLN3x+nSM9SWfiM= gitlab.com/xx_network/comms v0.0.4-0.20210401160731-7b8890cdd8ad/go.mod h1:inre/Ot0UJkxcfF4Oy4jk2A1MXyicRkPZB9FfnCfKQY= gitlab.com/xx_network/crypto v0.0.3/go.mod h1:DF2HYvvCw9wkBybXcXAgQMzX+MiGbFPjwt3t17VRqRE= gitlab.com/xx_network/crypto v0.0.4 h1:lpKOL5mTJ2awWMfgBy30oD/UvJVrWZzUimSHlOdZZxo= gitlab.com/xx_network/crypto v0.0.4/go.mod h1:+lcQEy+Th4eswFgQDwT0EXKp4AXrlubxalwQFH5O0Mk= -gitlab.com/xx_network/crypto v0.0.5-0.20210319231335-249c6b1aa323 h1:SR65X97KUaNdOQIX1SItNjPcQZ2oqznKM4g0UWpu+BI= -gitlab.com/xx_network/crypto v0.0.5-0.20210319231335-249c6b1aa323/go.mod h1:T2IjHhuTSvaX9qHXfX8qsjbRKsqEzZ73NNHvY3QR6CQ= gitlab.com/xx_network/crypto v0.0.5-0.20210401160648-4f06cace9123 h1:i2PajAamYlacUpAFWqE7g5qtM6Vt/xG9iDfoK1nc2l4= gitlab.com/xx_network/crypto v0.0.5-0.20210401160648-4f06cace9123/go.mod h1:CWV349I9Nv1zPCIY/f8Ej6yWs7NG0HLTWnm+Jlz7jKc= gitlab.com/xx_network/primitives v0.0.0-20200803231956-9b192c57ea7c/go.mod h1:wtdCMr7DPePz9qwctNoAUzZtbOSHSedcK++3Df3psjA= @@ -311,10 +290,14 @@ gitlab.com/xx_network/primitives v0.0.0-20200804183002-f99f7a7284da h1:CCVslUwNC gitlab.com/xx_network/primitives v0.0.0-20200804183002-f99f7a7284da/go.mod h1:OK9xevzWCaPO7b1wiluVJGk7R5ZsuC7pHY5hteZFQug= gitlab.com/xx_network/primitives v0.0.2 h1:r45yKenJ9e7PylI1ZXJ1Es09oYNaYXjxVy9+uYlwo7Y= gitlab.com/xx_network/primitives v0.0.2/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVkHy+QogOB6F/qc= -gitlab.com/xx_network/primitives v0.0.4-0.20210309173740-eb8cd411334a h1:Ume9QbJ4GoJh7v5yg/YVDjowJHx/VFeOC/A4PJZUm9g= -gitlab.com/xx_network/primitives v0.0.4-0.20210309173740-eb8cd411334a/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE= gitlab.com/xx_network/primitives v0.0.4-0.20210331161816-ed23858bdb93 h1:ZV5ZfSBX7+7moL8pywpCB3HTNXd03tSwMgDA7SDYaFA= gitlab.com/xx_network/primitives v0.0.4-0.20210331161816-ed23858bdb93/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE= +gitlab.com/xx_network/primitives v0.0.4-0.20210402183235-e04f174cf8c4 h1:uPTABEykN9moPQjb427tqVFPcxWbYbiqLZ26iwI8Cws= +gitlab.com/xx_network/primitives v0.0.4-0.20210402183235-e04f174cf8c4/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE= +gitlab.com/xx_network/primitives v0.0.4-0.20210402205313-e9b80f75e701 h1:svcqDo2heNLjmUncmgymwRH3lkV5Jy3PdhvLuqmI39o= +gitlab.com/xx_network/primitives v0.0.4-0.20210402205313-e9b80f75e701/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE= +gitlab.com/xx_network/primitives v0.0.4-0.20210402222416-37c1c4d3fac4 h1:YPYTKF0zQf08y0eQrjQP01C/EWQTypdqawjZPr5c6rc= +gitlab.com/xx_network/primitives v0.0.4-0.20210402222416-37c1c4d3fac4/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE= gitlab.com/xx_network/ring v0.0.2 h1:TlPjlbFdhtJrwvRgIg4ScdngMTaynx/ByHBRZiXCoL0= gitlab.com/xx_network/ring v0.0.2/go.mod h1:aLzpP2TiZTQut/PVHR40EJAomzugDdHXetbieRClXIM= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -457,7 +440,6 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20201030142918-24207fddd1c3/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210105202744-fe13368bc0e1 h1:Zk6zlGXdtYdcY5TL+VrbTfmifvk3VvsXopCpszsHPBA= google.golang.org/genproto v0.0.0-20210105202744-fe13368bc0e1/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= @@ -472,8 +454,6 @@ google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyz google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1 h1:7QnIQpGRHE5RnLKnESfDoxm2dTapTZua5a0kS0A+VXQ= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= diff --git a/keyExchange/confirm_test.go b/keyExchange/confirm_test.go index b2e619c684c0985ded4887178113ade1d489af1d..8cef6f6f60488568614208f751914332ca5267f9 100644 --- a/keyExchange/confirm_test.go +++ b/keyExchange/confirm_test.go @@ -13,8 +13,8 @@ import ( "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/storage/e2e" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "testing" - "time" ) // Smoke test for handleTrigger @@ -57,7 +57,7 @@ func TestHandleConfirm(t *testing.T) { Payload: rekey, MessageType: message.KeyExchangeConfirm, Sender: bobID, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Encryption: message.E2E, } diff --git a/keyExchange/exchange_test.go b/keyExchange/exchange_test.go index 2c1729995c28d528c19ffe88a92ae425d2b57e0d..4fd98b3e650a191d6facf40d0e1321bfdc84a031 100644 --- a/keyExchange/exchange_test.go +++ b/keyExchange/exchange_test.go @@ -19,6 +19,7 @@ import ( dh "gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "testing" "time" ) @@ -74,7 +75,7 @@ func TestFullExchange(t *testing.T) { Payload: rekeyTrigger, MessageType: message.KeyExchangeTrigger, Sender: exchangeBobId, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Encryption: message.E2E, } diff --git a/keyExchange/trigger_test.go b/keyExchange/trigger_test.go index c69e09562bd10bbe998855c33f3c765b7f0ed085..430bba91a0ba734541b03a61260493caa03237e0 100644 --- a/keyExchange/trigger_test.go +++ b/keyExchange/trigger_test.go @@ -14,6 +14,7 @@ import ( dh "gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "google.golang.org/protobuf/proto" "testing" "time" @@ -54,7 +55,7 @@ func TestHandleTrigger(t *testing.T) { Payload: rekey, MessageType: message.NoType, Sender: bobID, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Encryption: message.E2E, } diff --git a/keyExchange/utils_test.go b/keyExchange/utils_test.go index 162db4728cec9ddfa0b91d0f0ae3acc6e0c7c522..a1447b990744f92b063420888ea1c96e1d9fb5dd 100644 --- a/keyExchange/utils_test.go +++ b/keyExchange/utils_test.go @@ -8,9 +8,6 @@ package keyExchange import ( - "testing" - "time" - "github.com/golang/protobuf/proto" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces" @@ -31,6 +28,8 @@ import ( "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" "gitlab.com/xx_network/primitives/ndf" + "gitlab.com/xx_network/primitives/netTime" + "testing" ) // Generate partner ID for two people, used for smoke tests @@ -170,7 +169,7 @@ func (t *testNetworkManagerFullExchange) SendE2E(m message.Send, p params.E2E) ( Payload: payload, MessageType: message.KeyExchangeConfirm, Sender: exchangeAliceId, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Encryption: message.E2E, } diff --git a/network/ephemeral/tracker.go b/network/ephemeral/tracker.go index f158e337521ffddb5bcd6267e69e0e048e89f9de..2f19604c49faea57cb58b5cf7caf3476af4d9eab 100644 --- a/network/ephemeral/tracker.go +++ b/network/ephemeral/tracker.go @@ -16,6 +16,7 @@ import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + "gitlab.com/xx_network/primitives/netTime" "time" ) @@ -59,7 +60,7 @@ func track(session *storage.Session, ourId *id.ID, stop *stoppable.Single) { receptionStore.WaitForIdSizeUpdate() for true { - now := time.Now() + now := netTime.Now() // Generates the IDs since the last track protoIds, err := ephemeral.GetIdsByRange(ourId, receptionStore.GetIDSize(), now, now.Sub(lastCheck)) @@ -148,7 +149,7 @@ func checkTimestampStore(session *storage.Session) error { if _, err := session.Get(TimestampKey); err != nil { // only generate from the last hour because this is a new id, it // couldn't receive messages yet - now, err := marshalTimestamp(time.Now().Add(-1 * time.Hour)) + now, err := marshalTimestamp(netTime.Now().Add(-1 * time.Hour)) if err != nil { return errors.Errorf("Could not marshal new timestamp for storage: %v", err) } @@ -161,7 +162,7 @@ func checkTimestampStore(session *storage.Session) error { // Takes the stored timestamp and unmarshal into a time object func unmarshalTimestamp(lastTimestampObj *versioned.Object) (time.Time, error) { if lastTimestampObj == nil || lastTimestampObj.Data == nil { - return time.Now(), nil + return netTime.Now(), nil } lastTimestamp := time.Time{} @@ -175,7 +176,7 @@ func marshalTimestamp(timeToStore time.Time) (*versioned.Object, error) { return &versioned.Object{ Version: 0, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: data, }, err } diff --git a/network/ephemeral/tracker_test.go b/network/ephemeral/tracker_test.go index 1d01511f5b03be3b08a2084b92548cae62f84ff7..aa4589ebe7650ab55d4d04ab97fb98cfb9d1c008 100644 --- a/network/ephemeral/tracker_test.go +++ b/network/ephemeral/tracker_test.go @@ -17,6 +17,7 @@ import ( "gitlab.com/xx_network/comms/signature" "gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/utils" "testing" "time" @@ -31,7 +32,7 @@ func TestCheck(t *testing.T) { } /// Store a mock initial timestamp the store - now := time.Now() + now := netTime.Now() twoDaysAgo := now.Add(-2 * 24 * time.Hour) twoDaysTimestamp, err := marshalTimestamp(twoDaysAgo) if err != nil { @@ -65,7 +66,7 @@ func TestCheck_Thread(t *testing.T) { stop := stoppable.NewSingle(ephemeralStoppable) /// Store a mock initial timestamp the store - now := time.Now() + now := netTime.Now() yesterday := now.Add(-24 * time.Hour) yesterdayTimestamp, err := marshalTimestamp(yesterday) if err != nil { diff --git a/network/message/garbled_test.go b/network/message/garbled_test.go index 21098b72bef9a6408c6131c275c021471e79565d..0f5c3a074641af02ef3e156372bd7957eedba5aa 100644 --- a/network/message/garbled_test.go +++ b/network/message/garbled_test.go @@ -12,6 +12,7 @@ import ( "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/crypto/csprng" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "testing" "time" @@ -102,7 +103,7 @@ func TestManager_CheckGarbledMessages(t *testing.T) { fmp.NumParts[0] = uint8(1) binary.BigEndian.PutUint16(fmp.Len, 256) fmp.Part[0] = 0 - ts, err := time.Now().MarshalBinary() + ts, err := netTime.Now().MarshalBinary() if err != nil { t.Errorf("failed to martial ts: %+v", err) } diff --git a/network/message/parse/partition_test.go b/network/message/parse/partition_test.go index 59963cfefc57ab70d8d76e07fd384d8aae293a40..933db1a01d4e95605d44d7cf5f5dce4429f2a9b5 100644 --- a/network/message/parse/partition_test.go +++ b/network/message/parse/partition_test.go @@ -11,8 +11,8 @@ import ( "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/storage" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "testing" - "time" ) var ipsumTestStr = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet euismod est. Donec dolor " + @@ -67,7 +67,7 @@ func TestPartitioner_Partition(t *testing.T) { p := NewPartitioner(len(ipsumTestStr), storeSession) _, _, err := p.Partition(&id.DummyUser, message.Text, - time.Now(), []byte(ipsumTestStr)) + netTime.Now(), []byte(ipsumTestStr)) if err != nil { t.Error(err) } @@ -94,7 +94,7 @@ func TestPartitioner_HandleFirstPartition(t *testing.T) { storeSession := storage.InitTestingSession(t) p := NewPartitioner(len(ipsumTestStr), storeSession) - m := newFirstMessagePart(message.Text, 1107, 1, time.Now(), []byte(ipsumTestStr)) + m := newFirstMessagePart(message.Text, 1107, 1, netTime.Now(), []byte(ipsumTestStr)) _, _ = p.HandlePartition( &id.DummyUser, diff --git a/network/message/sendCmix.go b/network/message/sendCmix.go index b802a25fc9baab5ee288b372371e8cf40ee00166..1aced6efe44eaef52f17a08392d4c52a8d6eae7c 100644 --- a/network/message/sendCmix.go +++ b/network/message/sendCmix.go @@ -22,6 +22,7 @@ import ( "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + "gitlab.com/xx_network/primitives/netTime" "strings" "time" ) @@ -54,14 +55,14 @@ func sendCmixHelper(msg format.Message, recipient *id.ID, param params.CMIX, ins session *storage.Session, nodeRegistration chan network.NodeGateway, rng *fastRNG.StreamGenerator, senderId *id.ID, comms sendCmixCommsInterface) (id.Round, ephemeral.Id, error) { - timeStart := time.Now() + timeStart := netTime.Now() attempted := set.New() jww.INFO.Printf("Looking for round to send cMix message to %s "+ "(msgDigest: %s)", recipient, msg.Digest()) for numRoundTries := uint(0); numRoundTries < param.RoundTries; numRoundTries++ { - elapsed := time.Now().Sub(timeStart) + elapsed := netTime.Now().Sub(timeStart) if elapsed > param.Timeout { jww.INFO.Printf("No rounds to send to %s (msgDigest: %s) "+ diff --git a/network/message/sendCmix_test.go b/network/message/sendCmix_test.go index b58a8005cb0cbe3d43d6d2242e9801e2aab0d279..82b3ebcb2c3cfa87a72f62519f68541ae78bd06d 100644 --- a/network/message/sendCmix_test.go +++ b/network/message/sendCmix_test.go @@ -21,6 +21,7 @@ import ( "gitlab.com/xx_network/crypto/large" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/ndf" + "gitlab.com/xx_network/primitives/netTime" "testing" "time" ) @@ -64,7 +65,7 @@ func Test_attemptSendCmix(t *testing.T) { if err != nil { t.Errorf("Failed to start instance: %+v", err) } - now := time.Now() + now := netTime.Now() nid1 := id.NewIdFromString("zezima", id.Node, t) nid2 := id.NewIdFromString("jakexx360", id.Node, t) nid3 := id.NewIdFromString("westparkhome", id.Node, t) diff --git a/network/message/sendE2E.go b/network/message/sendE2E.go index 3b759b2601cc24250ccf045e3b8c29fdf0508b65..78061232830f167adf91d21f5805fa2e00b58916 100644 --- a/network/message/sendE2E.go +++ b/network/message/sendE2E.go @@ -16,6 +16,7 @@ import ( "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "sync" "time" ) @@ -26,7 +27,7 @@ func (m *Manager) SendE2E(msg message.Send, param params.E2E) ([]id.Round, e2e.M "message type", msg.MessageType) } //timestamp the message - ts := time.Now() + ts := netTime.Now() //partition the message partitions, internalMsgId, err := m.partitioner.Partition(msg.Recipient, msg.MessageType, ts, diff --git a/network/message/sendUnsafe.go b/network/message/sendUnsafe.go index d039b18724af24efbf3c60c711e55092b1fe40b8..ef28cf2d789d1f5f0a097413046b5a0c50b0a230 100644 --- a/network/message/sendUnsafe.go +++ b/network/message/sendUnsafe.go @@ -14,8 +14,8 @@ import ( "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "sync" - "time" ) // WARNING: Unsafe @@ -33,7 +33,7 @@ func (m *Manager) SendUnsafe(msg message.Send, param params.Unsafe) ([]id.Round, msg.MessageType) } //timestamp the message - ts := time.Now() + ts := netTime.Now() //partition the message partitions, _, err := m.partitioner.Partition(msg.Recipient, msg.MessageType, ts, diff --git a/single/manager_test.go b/single/manager_test.go index ff09e8ecd8ed9faa67f3339c283ea365c7899c5c..a9718de7c884b0c7135d676c13672a5d97b78587 100644 --- a/single/manager_test.go +++ b/single/manager_test.go @@ -31,6 +31,7 @@ import ( "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" "gitlab.com/xx_network/primitives/ndf" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "reflect" "sync" @@ -67,7 +68,7 @@ func TestManager_StartProcesses(t *testing.T) { callback, callbackChan := createReceiveComm() transmitMsg, _, rid, _, err := m.makeTransmitCmixMessage(partner, payload, - tag, 8, 32, 30*time.Second, time.Now(), rand.New(rand.NewSource(42))) + tag, 8, 32, 30*time.Second, netTime.Now(), rand.New(rand.NewSource(42))) if err != nil { t.Fatalf("Failed to create tranmission CMIX message: %+v", err) } @@ -107,7 +108,7 @@ func TestManager_StartProcesses(t *testing.T) { m.p.Lock() m.p.singleUse[*rid] = newState(sender.dhKey, sender.maxParts, callbackFunc) m.p.Unlock() - eid, _, _, _ := ephemeral.GetId(partner.ID, id.ArrIDLen, time.Now().UnixNano()) + eid, _, _, _ := ephemeral.GetId(partner.ID, id.ArrIDLen, netTime.Now().UnixNano()) replyMsg := message.Receive{ Payload: replyMsgs[0].Marshal(), MessageType: message.Raw, @@ -153,7 +154,7 @@ func TestManager_StartProcesses_Stop(t *testing.T) { callback, callbackChan := createReceiveComm() transmitMsg, _, rid, _, err := m.makeTransmitCmixMessage(partner, payload, - tag, 8, 32, 30*time.Second, time.Now(), rand.New(rand.NewSource(42))) + tag, 8, 32, 30*time.Second, netTime.Now(), rand.New(rand.NewSource(42))) if err != nil { t.Fatalf("Failed to create tranmission CMIX message: %+v", err) } @@ -199,7 +200,7 @@ func TestManager_StartProcesses_Stop(t *testing.T) { m.p.Lock() m.p.singleUse[*rid] = newState(sender.dhKey, sender.maxParts, callbackFunc) m.p.Unlock() - eid, _, _, _ := ephemeral.GetId(partner.ID, id.ArrIDLen, time.Now().UnixNano()) + eid, _, _, _ := ephemeral.GetId(partner.ID, id.ArrIDLen, netTime.Now().UnixNano()) replyMsg := message.Receive{ Payload: replyMsgs[0].Marshal(), MessageType: message.Raw, diff --git a/single/receiveResponse_test.go b/single/receiveResponse_test.go index 2782bc6fc1ad6d74eab2c0c2d51bf9988066734d..4e7e8c352e8196f0ff24d5a0d60633f78439e8dd 100644 --- a/single/receiveResponse_test.go +++ b/single/receiveResponse_test.go @@ -15,6 +15,7 @@ import ( "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "strings" "testing" @@ -29,7 +30,7 @@ func TestManager_ReceiveResponseHandler(t *testing.T) { partner := NewContact(id.NewIdFromString("recipientID", id.User, t), m.store.E2e().GetGroup().NewInt(43), m.store.E2e().GetGroup().NewInt(42), singleUse.TagFP{}, 8) - ephID, _, _, err := ephemeral.GetId(partner.partner, id.ArrIDLen, time.Now().UnixNano()) + ephID, _, _, err := ephemeral.GetId(partner.partner, id.ArrIDLen, netTime.Now().UnixNano()) payload := make([]byte, 2000) rand.New(rand.NewSource(42)).Read(payload) callback, callbackChan := createReplyComm() @@ -88,7 +89,7 @@ func TestManager_ReceiveResponseHandler_CmixMessageError(t *testing.T) { partner := NewContact(id.NewIdFromString("recipientID", id.User, t), m.store.E2e().GetGroup().NewInt(43), m.store.E2e().GetGroup().NewInt(42), singleUse.TagFP{}, 8) - ephID, _, _, _ := ephemeral.GetId(partner.partner, id.ArrIDLen, time.Now().UnixNano()) + ephID, _, _, _ := ephemeral.GetId(partner.partner, id.ArrIDLen, netTime.Now().UnixNano()) payload := make([]byte, 2000) rand.New(rand.NewSource(42)).Read(payload) callback, callbackChan := createReplyComm() @@ -130,7 +131,7 @@ func TestManager_ReceiveResponseHandler_CmixMessageError(t *testing.T) { func TestManager_processesResponse(t *testing.T) { m := newTestManager(0, false, t) rid := id.NewIdFromString("test RID", id.User, t) - ephID, _, _, err := ephemeral.GetId(rid, id.ArrIDLen, time.Now().UnixNano()) + ephID, _, _, err := ephemeral.GetId(rid, id.ArrIDLen, netTime.Now().UnixNano()) if err != nil { t.Fatalf("Failed to create ephemeral ID: %+v", err) } diff --git a/single/reception_test.go b/single/reception_test.go index 6989406621f2300e2f78c057defaf55d2e5858e1..ffe1991fd9cffaceb78a1308945054b1f8cf3ab6 100644 --- a/single/reception_test.go +++ b/single/reception_test.go @@ -7,6 +7,7 @@ import ( "gitlab.com/elixxir/crypto/e2e/singleUse" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "testing" "time" @@ -27,7 +28,7 @@ func TestManager_receiveTransmissionHandler(t *testing.T) { callback, callbackChan := createReceiveComm() msg, _, _, _, err := m.makeTransmitCmixMessage(partner, payload, tag, 8, 32, - 30*time.Second, time.Now(), rand.New(rand.NewSource(42))) + 30*time.Second, netTime.Now(), rand.New(rand.NewSource(42))) if err != nil { t.Fatalf("Failed to create tranmission CMIX message: %+v", err) } @@ -92,7 +93,7 @@ func TestManager_receiveTransmissionHandler_FingerPrintError(t *testing.T) { callback, callbackChan := createReceiveComm() msg, _, _, _, err := m.makeTransmitCmixMessage(partner, payload, tag, 8, 32, - 30*time.Second, time.Now(), rand.New(rand.NewSource(42))) + 30*time.Second, netTime.Now(), rand.New(rand.NewSource(42))) if err != nil { t.Fatalf("Failed to create tranmission CMIX message: %+v", err) } @@ -129,7 +130,7 @@ func TestManager_receiveTransmissionHandler_ProcessMessageError(t *testing.T) { callback, callbackChan := createReceiveComm() msg, _, _, _, err := m.makeTransmitCmixMessage(partner, payload, tag, 8, 32, - 30*time.Second, time.Now(), rand.New(rand.NewSource(42))) + 30*time.Second, netTime.Now(), rand.New(rand.NewSource(42))) if err != nil { t.Fatalf("Failed to create tranmission CMIX message: %+v", err) } @@ -167,7 +168,7 @@ func TestManager_receiveTransmissionHandler_TagFpError(t *testing.T) { rand.New(rand.NewSource(42)).Read(payload) msg, _, _, _, err := m.makeTransmitCmixMessage(partner, payload, tag, 8, 32, - 30*time.Second, time.Now(), rand.New(rand.NewSource(42))) + 30*time.Second, netTime.Now(), rand.New(rand.NewSource(42))) if err != nil { t.Fatalf("Failed to create tranmission CMIX message: %+v", err) } @@ -189,7 +190,7 @@ func TestManager_processTransmission(t *testing.T) { payload := []byte("This is the payload.") maxMsgs := uint8(6) cmixMsg, dhKey, rid, _, err := m.makeTransmitCmixMessage(partner, payload, - tag, maxMsgs, 32, 30*time.Second, time.Now(), rand.New(rand.NewSource(42))) + tag, maxMsgs, 32, 30*time.Second, netTime.Now(), rand.New(rand.NewSource(42))) if err != nil { t.Fatalf("Failed to generate expected CMIX message: %+v", err) } @@ -240,7 +241,7 @@ func TestManager_processTransmission_MacVerifyError(t *testing.T) { DhPubKey: m.store.E2e().GetDHPublicKey(), } cmixMsg, _, _, _, err := m.makeTransmitCmixMessage(partner, []byte{}, "", 6, - 32, 30*time.Second, time.Now(), rand.New(rand.NewSource(42))) + 32, 30*time.Second, netTime.Now(), rand.New(rand.NewSource(42))) if err != nil { t.Fatalf("Failed to generate expected CMIX message: %+v", err) } diff --git a/single/transmission.go b/single/transmission.go index 13abe66dbd753c5f1b2e6a3036c0c6efa8f0c9b4..4f7a85048cd4becc8ed4dbb62e39565e505744f8 100644 --- a/single/transmission.go +++ b/single/transmission.go @@ -24,6 +24,7 @@ import ( "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + "gitlab.com/xx_network/primitives/netTime" "io" "sync/atomic" "time" @@ -72,7 +73,7 @@ func (m *Manager) transmitSingleUse(partner contact2.Contact, payload []byte, // Create new CMIX message containing the transmission payload cmixMsg, dhKey, rid, ephID, err := m.makeTransmitCmixMessage(partner, - payload, tag, MaxMsgs, addressSize, timeout, time.Now(), rng) + payload, tag, MaxMsgs, addressSize, timeout, netTime.Now(), rng) if err != nil { return errors.Errorf("failed to create new CMIX message: %+v", err) } @@ -80,7 +81,7 @@ func (m *Manager) transmitSingleUse(partner contact2.Contact, payload []byte, jww.DEBUG.Printf("Created single-use transmission CMIX message with new ID "+ "%s and ephemeral ID %d", rid, ephID.Int64()) - timeStart := time.Now() + timeStart := netTime.Now() // Add message state to map quitChan, quit, err := m.p.addState(rid, dhKey, MaxMsgs, callback, timeout) @@ -139,7 +140,7 @@ func (m *Manager) transmitSingleUse(partner contact2.Contact, payload []byte, } // Update the timeout for the elapsed time - roundEventTimeout := timeout - time.Now().Sub(timeStart) - time.Millisecond + roundEventTimeout := timeout - netTime.Now().Sub(timeStart) - time.Millisecond // Check message delivery sendResults := make(chan ds.EventReturn, 1) diff --git a/single/transmission_test.go b/single/transmission_test.go index fe6df60ba188ef5abe88e06ab4434c0d289618b5..b3697d4fd3c659edb4863d0a0a6810b605091e7c 100644 --- a/single/transmission_test.go +++ b/single/transmission_test.go @@ -12,6 +12,7 @@ import ( "gitlab.com/elixxir/primitives/states" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "reflect" "strings" @@ -60,7 +61,7 @@ func TestManager_transmitSingleUse(t *testing.T) { } expectedMsg, _, _, _, err := m.makeTransmitCmixMessage(partner, payload, - tag, maxMsgs, 32, 30*time.Second, time.Now(), rand.New(rand.NewSource(42))) + tag, maxMsgs, 32, 30*time.Second, netTime.Now(), rand.New(rand.NewSource(42))) if err != nil { t.Fatalf("Failed to make expected message: %+v", err) } @@ -204,7 +205,7 @@ func TestManager_transmitSingleUse_AddStateError(t *testing.T) { // Create new CMIX and add a state _, dhKey, rid, _, err := m.makeTransmitCmixMessage(partner, payload, tag, - maxMsgs, 32, 30*time.Second, time.Now(), rand.New(rand.NewSource(42))) + maxMsgs, 32, 30*time.Second, netTime.Now(), rand.New(rand.NewSource(42))) if err != nil { t.Fatalf("Failed to create new CMIX message: %+v", err) } @@ -262,7 +263,7 @@ func TestManager_makeTransmitCmixMessage(t *testing.T) { payload := make([]byte, 132) rand.New(rand.NewSource(42)).Read(payload) maxMsgs := uint8(8) - timeNow := time.Now() + timeNow := netTime.Now() msg, dhKey, rid, _, err := m.makeTransmitCmixMessage(partner, payload, tag, maxMsgs, 32, 30*time.Second, timeNow, prng) @@ -325,7 +326,7 @@ func TestManager_makeTransmitCmixMessage_PayloadTooLargeError(t *testing.T) { rand.New(rand.NewSource(42)).Read(payload) _, _, _, _, err := m.makeTransmitCmixMessage(contact2.Contact{}, payload, "", 8, 32, - 30*time.Second, time.Now(), prng) + 30*time.Second, netTime.Now(), prng) if !check(err, "too long for message payload capacity") { t.Errorf("makeTransmitCmixMessage() failed to error when the payload is too "+ @@ -343,7 +344,7 @@ func TestManager_makeTransmitCmixMessage_KeyGenerationError(t *testing.T) { } _, _, _, _, err := m.makeTransmitCmixMessage(partner, nil, "", 8, 32, - 30*time.Second, time.Now(), prng) + 30*time.Second, netTime.Now(), prng) if !check(err, "failed to generate key in group") { t.Errorf("makeTransmitCmixMessage() failed to error when key "+ @@ -377,7 +378,7 @@ func Test_makeIDs_Consistency(t *testing.T) { t.Fatalf("Failed to set nonce: %+v", err) } - timeNow := time.Now() + timeNow := netTime.Now() rid, ephID, err := makeIDs(&msgPayload, publicKey, addressSize, 30*time.Second, timeNow, rand.New(rand.NewSource(42))) @@ -412,7 +413,7 @@ func Test_makeIDs_NonceError(t *testing.T) { msgPayload := newTransmitMessagePayload(transmitPlMinSize) _, _, err := makeIDs(&msgPayload, &cyclic.Int{}, 32, 30*time.Second, - time.Now(), strings.NewReader("")) + netTime.Now(), strings.NewReader("")) if !check(err, "failed to generate nonce") { t.Errorf("makeIDs() did not return an error when failing to make nonce: %+v", err) } diff --git a/stoppable/cleanup.go b/stoppable/cleanup.go index c721f3605aa6d5ef1323a9e01dc2b80b7cb3684c..b76fbbc8d539fbbb905026e8bb7f3560da3db41e 100644 --- a/stoppable/cleanup.go +++ b/stoppable/cleanup.go @@ -9,6 +9,7 @@ package stoppable import ( "github.com/pkg/errors" + "gitlab.com/xx_network/primitives/netTime" "sync" "sync/atomic" "time" @@ -55,7 +56,7 @@ func (c *Cleanup) Close(timeout time.Duration) error { c.once.Do( func() { defer atomic.StoreUint32(&c.running, 0) - start := time.Now() + start := netTime.Now() // Run the stoppable if err := c.stop.Close(timeout); err != nil { diff --git a/storage/auth/sentRequest.go b/storage/auth/sentRequest.go index 09251401cbe1433d917a6d3912ab68aaf2873002..77901412056ca674b8756d9e661edff7bd4d8076 100644 --- a/storage/auth/sentRequest.go +++ b/storage/auth/sentRequest.go @@ -14,7 +14,7 @@ import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentSentRequestVersion = 0 @@ -112,7 +112,7 @@ func (sr *SentRequest) save() error { obj := versioned.Object{ Version: currentSentRequestVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: data, } diff --git a/storage/auth/store.go b/storage/auth/store.go index 1d8f074436461f7c7a3e198bbbbc772d54804388..ed378f83690787768f8b4faf579b849308e29814 100644 --- a/storage/auth/store.go +++ b/storage/auth/store.go @@ -18,8 +18,8 @@ import ( "gitlab.com/elixxir/crypto/e2e/auth" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "sync" - "time" ) const NoRequest = "Request Not Found" @@ -161,7 +161,7 @@ func (s *Store) save() error { obj := versioned.Object{ Version: requestMapVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: data, } diff --git a/storage/clientVersion/store.go b/storage/clientVersion/store.go index 3f1eca48aca688113ba8c240ad8e747029947a90..5b6e951ef6c0bf5b86049b636606fa015f9d4062 100644 --- a/storage/clientVersion/store.go +++ b/storage/clientVersion/store.go @@ -12,8 +12,8 @@ import ( jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/primitives/version" + "gitlab.com/xx_network/primitives/netTime" "sync" - "time" ) const ( @@ -105,7 +105,7 @@ func (s *Store) update(newVersion version.Version) error { // save stores the clientVersion store. Note that this function does not take // a lock. func (s *Store) save() error { - timeNow := time.Now() + timeNow := netTime.Now() obj := versioned.Object{ Version: storeVersion, diff --git a/storage/clientVersion/store_test.go b/storage/clientVersion/store_test.go index 22da1257c04f0b7780d63b46c0cf28a86bd6143d..72098cffa061ac63ac375f92e533312272e5d3bf 100644 --- a/storage/clientVersion/store_test.go +++ b/storage/clientVersion/store_test.go @@ -11,10 +11,10 @@ import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/ekv" "gitlab.com/elixxir/primitives/version" + "gitlab.com/xx_network/primitives/netTime" "reflect" "strings" "testing" - "time" ) // Happy path. @@ -67,7 +67,7 @@ func TestLoadStore_ParseVersionError(t *testing.T) { kv := versioned.NewKV(make(ekv.Memstore)) obj := versioned.Object{ Version: storeVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: []byte("invalid version"), } diff --git a/storage/cmix/key.go b/storage/cmix/key.go index 3a7f6400e238f84a481a08449aaa05c02374a48a..3ab6fc084cff007e879cd541afc44dbf910ea10d 100644 --- a/storage/cmix/key.go +++ b/storage/cmix/key.go @@ -12,7 +12,7 @@ import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/xx_network/primitives/id" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentKeyVersion = 0 @@ -65,7 +65,7 @@ func loadKey(kv *versioned.KV, id *id.ID) (*key, error) { // saves the key as the key for the given node ID in the passed keystore func (k *key) save() error { - now := time.Now() + now := netTime.Now() data, err := k.marshal() if err != nil { diff --git a/storage/cmix/store.go b/storage/cmix/store.go index 8a2c514ef1bc2087a2bafc0ef420a3f8ce9333a4..95a67d7789c3f8f35642e96ef9d81cc864f4b0cb 100644 --- a/storage/cmix/store.go +++ b/storage/cmix/store.go @@ -17,8 +17,8 @@ import ( "gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "sync" - "time" ) const prefix = "cmix" @@ -111,7 +111,7 @@ func (s *Store) Add(nid *id.ID, k *cyclic.Int) { } // Returns if the store has the node -func (s *Store) Has(nid *id.ID)bool { +func (s *Store) Has(nid *id.ID) bool { s.mux.RLock() _, exists := s.nodes[*nid] s.mux.RUnlock() @@ -202,7 +202,7 @@ func (s *Store) Count() int { // save stores the cMix store. func (s *Store) save() error { - now := time.Now() + now := netTime.Now() data, err := s.marshal() if err != nil { diff --git a/storage/conversation/partner.go b/storage/conversation/partner.go index 0fef58be68864181ccd18a7282f6be627b26c29f..8bad184d3c1791d2751003f692651ae7112b0854 100644 --- a/storage/conversation/partner.go +++ b/storage/conversation/partner.go @@ -13,10 +13,10 @@ import ( jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "math" "strings" "sync" - "time" ) const ( @@ -159,7 +159,7 @@ func (c *Conversation) save() error { obj := versioned.Object{ Version: currentConversationVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: data, } diff --git a/storage/e2e/key_test.go b/storage/e2e/key_test.go index d74f53e174685483666c37150be86aef2d3a69a9..0f93e69a2818967cbfd53caaf26d034a8c224296 100644 --- a/storage/e2e/key_test.go +++ b/storage/e2e/key_test.go @@ -17,10 +17,10 @@ import ( "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/crypto/large" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "reflect" "testing" - "time" ) // Happy path of newKey(). @@ -212,7 +212,7 @@ func getSession(t *testing.T) *Session { } func getFingerprint() *format.Fingerprint { - rand.Seed(time.Now().UnixNano()) + rand.Seed(netTime.Now().UnixNano()) fp := format.Fingerprint{} rand.Read(fp[:]) diff --git a/storage/e2e/manager_test.go b/storage/e2e/manager_test.go index 58b0ca6bb6c5b846abc994b8c5f43e90819be664..907bbff91b561d2267b71371356ae7bf6f332b86 100644 --- a/storage/e2e/manager_test.go +++ b/storage/e2e/manager_test.go @@ -14,10 +14,10 @@ import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "reflect" "testing" - "time" ) // Tests happy path of newManager. @@ -234,7 +234,7 @@ func TestManager_TriggerNegotiations(t *testing.T) { // newTestManager returns a new relationship for testing. func newTestManager(t *testing.T) (*Manager, *versioned.KV) { - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) s, ctx := makeTestSession() kv := versioned.NewKV(make(ekv.Memstore)) partnerID := id.NewIdFromUInts([4]uint64{prng.Uint64(), prng.Uint64(), diff --git a/storage/e2e/relationship.go b/storage/e2e/relationship.go index e2c5bac8ff0c0f60082655c170c7e5bd31f0f6f8..9678b4db89f6c68feed54606ee6dd3daa8041637 100644 --- a/storage/e2e/relationship.go +++ b/storage/e2e/relationship.go @@ -14,8 +14,8 @@ import ( "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/crypto/cyclic" + "gitlab.com/xx_network/primitives/netTime" "sync" - "time" ) const maxUnconfirmed uint = 3 @@ -111,7 +111,7 @@ func LoadRelationship(manager *Manager, t RelationshipType) (*relationship, erro func (r *relationship) save() error { - now := time.Now() + now := netTime.Now() data, err := r.marshal() if err != nil { diff --git a/storage/e2e/relationshipFingerprint.go b/storage/e2e/relationshipFingerprint.go index f071e5ffb0dcf4e90e40e461338eedbf9c78fc51..a3702655319ccf0f14323d31f5b32b3fe59cb825 100644 --- a/storage/e2e/relationshipFingerprint.go +++ b/storage/e2e/relationshipFingerprint.go @@ -13,7 +13,7 @@ import ( "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/e2e" "gitlab.com/xx_network/primitives/id" - "time" + "gitlab.com/xx_network/primitives/netTime" ) func makeRelationshipFingerprint(t RelationshipType, grp *cyclic.Group, @@ -36,7 +36,7 @@ func makeRelationshipFingerprint(t RelationshipType, grp *cyclic.Group, } func storeRelationshipFingerprint(fp []byte, kv *versioned.KV) error { - now := time.Now() + now := netTime.Now() obj := versioned.Object{ Version: currentRelationshipFingerprintVersion, Timestamp: now, diff --git a/storage/e2e/session.go b/storage/e2e/session.go index db5ff551cf7059381b9befb73db6482258f9f519..b51c0584780b60d28ced2004ce48159495b929be 100644 --- a/storage/e2e/session.go +++ b/storage/e2e/session.go @@ -10,11 +10,6 @@ package e2e import ( "encoding/json" "fmt" - "math/big" - "sync" - "testing" - "time" - "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces/params" @@ -24,6 +19,10 @@ import ( "gitlab.com/elixxir/crypto/hash" "gitlab.com/xx_network/crypto/randomness" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" + "math/big" + "sync" + "testing" ) const currentSessionVersion = 0 @@ -174,7 +173,7 @@ func loadSession(ship *relationship, kv *versioned.KV, func (s *Session) save() error { - now := time.Now() + now := netTime.Now() data, err := s.marshal() if err != nil { diff --git a/storage/e2e/session_test.go b/storage/e2e/session_test.go index 495dc39095218506a1bbe427a746b971d0998164..1043dc556d928c61984fc6af3de00759e9b1e174 100644 --- a/storage/e2e/session_test.go +++ b/storage/e2e/session_test.go @@ -16,6 +16,7 @@ import ( "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/crypto/csprng" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "reflect" "testing" "time" @@ -460,7 +461,7 @@ func TestSession_SetNegotiationStatus(t *testing.T) { // Normal paths: SetNegotiationStatus should not fail // Use timestamps to determine whether a save has occurred s.negotiationStatus = Sending - now := time.Now() + now := netTime.Now() time.Sleep(time.Millisecond) s.SetNegotiationStatus(Sent) if s.negotiationStatus != Sent { @@ -474,7 +475,7 @@ func TestSession_SetNegotiationStatus(t *testing.T) { t.Errorf("save didn't occur after switching Sending to Sent") } - now = time.Now() + now = netTime.Now() time.Sleep(time.Millisecond) s.SetNegotiationStatus(Confirmed) if s.negotiationStatus != Confirmed { @@ -488,7 +489,7 @@ func TestSession_SetNegotiationStatus(t *testing.T) { t.Errorf("save didn't occur after switching Sent to Confirmed") } - now = time.Now() + now = netTime.Now() time.Sleep(time.Millisecond) s.negotiationStatus = NewSessionTriggered s.SetNegotiationStatus(NewSessionCreated) @@ -505,7 +506,7 @@ func TestSession_SetNegotiationStatus(t *testing.T) { // Reverting paths: SetNegotiationStatus should not fail, and a save should not take place time.Sleep(time.Millisecond) - now = time.Now() + now = netTime.Now() time.Sleep(time.Millisecond) s.negotiationStatus = Sending s.SetNegotiationStatus(Unconfirmed) diff --git a/storage/e2e/stateVector.go b/storage/e2e/stateVector.go index 4a2e6271c0f42f65060f4416bfd7603f2a3d4d5d..10306ae562bde79a5d6382d167f83b823ccbc8df 100644 --- a/storage/e2e/stateVector.go +++ b/storage/e2e/stateVector.go @@ -13,8 +13,8 @@ import ( "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage/versioned" + "gitlab.com/xx_network/primitives/netTime" "sync" - "time" ) const currentStateVectorVersion = 0 @@ -79,7 +79,7 @@ func loadStateVector(kv *versioned.KV, key string) (*stateVector, error) { } func (sv *stateVector) save() error { - now := time.Now() + now := netTime.Now() data, err := sv.marshal() if err != nil { diff --git a/storage/e2e/store.go b/storage/e2e/store.go index ae06cb56b5112fa39c2812de23d69b00966e8f18..001f077e826d3e1e3f3627cbf500dfae926a3b1a 100644 --- a/storage/e2e/store.go +++ b/storage/e2e/store.go @@ -19,8 +19,8 @@ import ( "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "sync" - "time" ) const ( @@ -144,7 +144,7 @@ func LoadStore(kv *versioned.KV, myID *id.ID, rng *fastRNG.StreamGenerator) (*St } func (s *Store) save() error { - now := time.Now() + now := netTime.Now() data, err := s.marshal() if err != nil { diff --git a/storage/partition/multiPartMessage.go b/storage/partition/multiPartMessage.go index 7dc6cbb886136577caee703337485cab0367369f..754c524702498c2c6586d54a42adedf3351a7cc5 100644 --- a/storage/partition/multiPartMessage.go +++ b/storage/partition/multiPartMessage.go @@ -17,6 +17,7 @@ import ( "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "sync" "time" ) @@ -85,7 +86,7 @@ func (mpm *multiPartMessage) save() error { obj := versioned.Object{ Version: currentMultiPartMessageVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: data, } diff --git a/storage/partition/multiPartMessage_test.go b/storage/partition/multiPartMessage_test.go index ec871783b1e935a0653283102a29b7b8e7b9b939..dff3c0fabb41cffd20f714497b487ea8bcbd4644 100644 --- a/storage/partition/multiPartMessage_test.go +++ b/storage/partition/multiPartMessage_test.go @@ -15,6 +15,7 @@ import ( "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "reflect" "testing" @@ -24,7 +25,7 @@ import ( // Tests the creation part of loadOrCreateMultiPartMessage(). func Test_loadOrCreateMultiPartMessage_Create(t *testing.T) { // Set up expected test value - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) expectedMpm := &multiPartMessage{ Sender: id.NewIdFromUInt(prng.Uint64(), id.User, t), MessageID: prng.Uint64(), @@ -60,7 +61,7 @@ func Test_loadOrCreateMultiPartMessage_Create(t *testing.T) { // Tests the loading part of loadOrCreateMultiPartMessage(). func Test_loadOrCreateMultiPartMessage_Load(t *testing.T) { // Set up expected test value - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) expectedMpm := &multiPartMessage{ Sender: id.NewIdFromUInt(prng.Uint64(), id.User, t), MessageID: prng.Uint64(), @@ -115,7 +116,7 @@ func CheckMultiPartMessages(expectedMpm *multiPartMessage, mpm *multiPartMessage // Tests happy path of multiPartMessage.Add(). func TestMultiPartMessage_Add(t *testing.T) { // Generate test values - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) mpm := loadOrCreateMultiPartMessage(id.NewIdFromUInt(prng.Uint64(), id.User, t), prng.Uint64(), versioned.NewKV(make(ekv.Memstore))) partNums, parts := generateParts(prng, 0) @@ -156,13 +157,13 @@ func TestMultiPartMessage_Add(t *testing.T) { // Tests happy path of multiPartMessage.AddFirst(). func TestMultiPartMessage_AddFirst(t *testing.T) { // Generate test values - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) expectedMpm := &multiPartMessage{ Sender: id.NewIdFromUInt(prng.Uint64(), id.User, t), MessageID: prng.Uint64(), NumParts: uint8(prng.Uint32()), PresentParts: 1, - Timestamp: time.Now(), + Timestamp: netTime.Now(), MessageType: message.NoType, parts: make([][]byte, 3), kv: versioned.NewKV(make(ekv.Memstore)), @@ -190,7 +191,7 @@ func TestMultiPartMessage_AddFirst(t *testing.T) { // Tests happy path of multiPartMessage.IsComplete(). func TestMultiPartMessage_IsComplete(t *testing.T) { // Create multiPartMessage and fill with random parts - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) mid := prng.Uint64() mpm := loadOrCreateMultiPartMessage(id.NewIdFromUInt(prng.Uint64(), id.User, t), mid, versioned.NewKV(make(ekv.Memstore))) @@ -202,7 +203,7 @@ func TestMultiPartMessage_IsComplete(t *testing.T) { t.Error("IsComplete() returned true when NumParts == 0.") } - mpm.AddFirst(message.Text, partNums[0], 75, time.Now(), parts[0]) + mpm.AddFirst(message.Text, partNums[0], 75, netTime.Now(), parts[0]) for i := range partNums { if i > 0 { mpm.Add(partNums[i], parts[i]) @@ -237,7 +238,7 @@ func TestMultiPartMessage_IsComplete(t *testing.T) { // Tests happy path of multiPartMessage.delete(). func TestMultiPartMessage_delete(t *testing.T) { - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) kv := versioned.NewKV(make(ekv.Memstore)) mpm := loadOrCreateMultiPartMessage(id.NewIdFromUInt(prng.Uint64(), id.User, t), prng.Uint64(), kv) diff --git a/storage/partition/part.go b/storage/partition/part.go index 66206fd4345d19ba233cfbd185f4251fb4bd74a6..9c24861ff83e732606341e1130bf041cc344c75a 100644 --- a/storage/partition/part.go +++ b/storage/partition/part.go @@ -10,7 +10,7 @@ package partition import ( "fmt" "gitlab.com/elixxir/client/storage/versioned" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentMultiPartMessagePartVersion = 0 @@ -31,7 +31,7 @@ func savePart(kv *versioned.KV, partNum uint8, part []byte) error { obj := versioned.Object{ Version: currentMultiPartMessagePartVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: part, } diff --git a/storage/partition/part_test.go b/storage/partition/part_test.go index 22dfa11156024976b1d96c50988c464f1ec00612..b1db602f7932a505a877e8c34a54ed61173cf1ab 100644 --- a/storage/partition/part_test.go +++ b/storage/partition/part_test.go @@ -11,15 +11,15 @@ import ( "bytes" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/ekv" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "testing" - "time" ) // Tests happy path of savePart(). func Test_savePart(t *testing.T) { // Set up test values - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) kv := versioned.NewKV(make(ekv.Memstore)) partNum := uint8(prng.Uint32()) part := make([]byte, prng.Int31n(500)) @@ -48,7 +48,7 @@ func Test_savePart(t *testing.T) { // Tests happy path of loadPart(). func Test_loadPart(t *testing.T) { // Set up test values - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) rootKv := versioned.NewKV(make(ekv.Memstore)) partNum := uint8(prng.Uint32()) part := make([]byte, prng.Int31n(500)) @@ -56,7 +56,7 @@ func Test_loadPart(t *testing.T) { key := makeMultiPartMessagePartKey(partNum) // Save part to key value store - err := rootKv.Set(key, 0, &versioned.Object{Timestamp: time.Now(), Data: part}) + err := rootKv.Set(key, 0, &versioned.Object{Timestamp: netTime.Now(), Data: part}) if err != nil { t.Fatalf("Failed to set object: %v", err) } @@ -78,7 +78,7 @@ func Test_loadPart(t *testing.T) { // key. func Test_loadPart_NotFoundError(t *testing.T) { // Set up test values - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) kv := versioned.NewKV(make(ekv.Memstore)) partNum := uint8(prng.Uint32()) part := make([]byte, prng.Int31n(500)) @@ -100,7 +100,7 @@ func Test_loadPart_NotFoundError(t *testing.T) { // Test happy path of deletePart(). func TestDeletePart(t *testing.T) { // Set up test values - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) kv := versioned.NewKV(make(ekv.Memstore)) partNum := uint8(prng.Uint32()) part := make([]byte, prng.Int31n(500)) diff --git a/storage/partition/store_test.go b/storage/partition/store_test.go index c150d026d55389793dd32952b2fe209a29192e8b..9de6327d989d032e6ed987db0aff891d6be0fa3b 100644 --- a/storage/partition/store_test.go +++ b/storage/partition/store_test.go @@ -13,9 +13,9 @@ import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "reflect" "testing" - "time" ) // Tests happy path of New(). @@ -40,7 +40,7 @@ func TestStore_AddFirst(t *testing.T) { s := New(versioned.NewKV(ekv.Memstore{})) msg, complete := s.AddFirst(id.NewIdFromString("User", id.User, t), - message.Text, 5, 0, 1, time.Now(), part, + message.Text, 5, 0, 1, netTime.Now(), part, []byte{0}) if !complete { @@ -60,7 +60,7 @@ func TestStore_Add(t *testing.T) { s := New(versioned.NewKV(ekv.Memstore{})) msg, complete := s.AddFirst(id.NewIdFromString("User", id.User, t), - message.Text, 5, 0, 2, time.Now(), part1, + message.Text, 5, 0, 2, netTime.Now(), part1, []byte{0}) if complete { diff --git a/storage/reception/identity.go b/storage/reception/identity.go index 65da42ac9ac76dcd37b232a8c2a54b47f36494cf..4c65d9696ba4a6d0fd567395a4d86e8bd9145b45 100644 --- a/storage/reception/identity.go +++ b/storage/reception/identity.go @@ -6,6 +6,7 @@ import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + "gitlab.com/xx_network/primitives/netTime" "strconv" "time" ) @@ -58,7 +59,7 @@ func (i Identity) store(kv *versioned.KV) error { // Create versioned object with data obj := &versioned.Object{ Version: identityStorageVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: regStr, } diff --git a/storage/reception/identity_test.go b/storage/reception/identity_test.go index 8499050e9e988b1a48b9e59ad8501ddd211a74c6..d80b9501486c94045209da5c99dc0b77a07306f8 100644 --- a/storage/reception/identity_test.go +++ b/storage/reception/identity_test.go @@ -5,6 +5,7 @@ import ( "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "testing" "time" @@ -15,10 +16,10 @@ func TestIdentity_EncodeDecode(t *testing.T) { r := Identity{ EphId: ephemeral.Id{}, Source: &id.Permissioning, - End: time.Now().Round(0), + End: netTime.Now().Round(0), ExtraChecks: 12, - StartValid: time.Now().Round(0), - EndValid: time.Now().Round(0), + StartValid: netTime.Now().Round(0), + EndValid: netTime.Now().Round(0), RequestMask: 2 * time.Hour, Ephemeral: false, } @@ -44,10 +45,10 @@ func TestIdentity_Delete(t *testing.T) { r := Identity{ EphId: ephemeral.Id{}, Source: &id.Permissioning, - End: time.Now().Round(0), + End: netTime.Now().Round(0), ExtraChecks: 12, - StartValid: time.Now().Round(0), - EndValid: time.Now().Round(0), + StartValid: netTime.Now().Round(0), + EndValid: netTime.Now().Round(0), RequestMask: 2 * time.Hour, Ephemeral: false, } @@ -85,7 +86,7 @@ func TestIdentity_Equal(t *testing.T) { timestamp := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC) a, _ := generateFakeIdentity(rand.New(rand.NewSource(42)), 15, timestamp) b, _ := generateFakeIdentity(rand.New(rand.NewSource(42)), 15, timestamp) - c, _ := generateFakeIdentity(rand.New(rand.NewSource(42)), 15, time.Now()) + c, _ := generateFakeIdentity(rand.New(rand.NewSource(42)), 15, netTime.Now()) if !a.Identity.Equal(b.Identity) { t.Errorf("Equal() found two equal identities as unequal."+ diff --git a/storage/reception/registration.go b/storage/reception/registration.go index d586594f9b932a7cd9c49a803228f0c81ae29cba..70647129c7c621b9a757b9d42ec82ef66f3c1bd3 100644 --- a/storage/reception/registration.go +++ b/storage/reception/registration.go @@ -6,6 +6,7 @@ import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + "gitlab.com/xx_network/primitives/netTime" "strconv" "time" ) @@ -25,7 +26,7 @@ func newRegistration(reg Identity, kv *versioned.KV) (*registration, error) { reg.EndValid = reg.EndValid.Round(0) reg.End = reg.End.Round(0) - now := time.Now() + now := netTime.Now() // Do edge checks to determine if the identity is valid if now.After(reg.End) && reg.ExtraChecks < 1 { @@ -73,7 +74,7 @@ func loadRegistration(EphId ephemeral.Id, Source *id.ID, startValid time.Time, r := ®istration{ Identity: reg, kv: kv, - UR: rounds.LoadUnknownRounds(kv,rounds.DefaultUnknownRoundsParams()), + UR: rounds.LoadUnknownRounds(kv, rounds.DefaultUnknownRoundsParams()), ER: rounds.LoadEarliestRound(kv), } diff --git a/storage/reception/registration_test.go b/storage/reception/registration_test.go index e2eff1547462fe13683c79ff16f5862db0d6af47..8e9024c46d9fdb60726498b9fb103cb2b1beddbb 100644 --- a/storage/reception/registration_test.go +++ b/storage/reception/registration_test.go @@ -3,6 +3,7 @@ package reception import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/ekv" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "strings" "testing" @@ -34,7 +35,7 @@ func TestNewRegistration_Ephemeral(t *testing.T) { id := idu.Identity kv := versioned.NewKV(make(ekv.Memstore)) - id.End = time.Now().Add(1 * time.Hour) + id.End = netTime.Now().Add(1 * time.Hour) id.ExtraChecks = 2 id.Ephemeral = true @@ -57,7 +58,7 @@ func TestNewRegistration_Persistent(t *testing.T) { id := idu.Identity kv := versioned.NewKV(make(ekv.Memstore)) - id.End = time.Now().Add(1 * time.Hour) + id.End = netTime.Now().Add(1 * time.Hour) id.ExtraChecks = 2 id.Ephemeral = false @@ -81,7 +82,7 @@ func TestLoadRegistration(t *testing.T) { id := idu.Identity kv := versioned.NewKV(make(ekv.Memstore)) - id.End = time.Now().Add(1 * time.Hour) + id.End = netTime.Now().Add(1 * time.Hour) id.ExtraChecks = 2 id.Ephemeral = false @@ -107,7 +108,7 @@ func Test_registration_Delete(t *testing.T) { id := idu.Identity kv := versioned.NewKV(make(ekv.Memstore)) - id.End = time.Now().Add(1 * time.Hour) + id.End = netTime.Now().Add(1 * time.Hour) id.ExtraChecks = 2 id.Ephemeral = false diff --git a/storage/reception/store.go b/storage/reception/store.go index 40cc9c0b40c6675ac7d7b1b5f52e38f1cb5bcc73..f87ee416abaecd01e3955549080e462b3ae1e3ad 100644 --- a/storage/reception/store.go +++ b/storage/reception/store.go @@ -10,6 +10,7 @@ import ( "gitlab.com/xx_network/crypto/large" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id/ephemeral" + "gitlab.com/xx_network/primitives/netTime" "io" "strconv" "sync" @@ -133,7 +134,7 @@ func (s *Store) save() error { // Create versioned object with data obj := &versioned.Object{ Version: receptionStoreStorageVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: data, } @@ -169,7 +170,7 @@ func (s *Store) GetIdentity(rng io.Reader) (IdentityUse, error) { s.mux.Lock() defer s.mux.Unlock() - now := time.Now() + now := netTime.Now() // Remove any now expired identities s.prune(now) @@ -307,7 +308,7 @@ func (s *Store) UpdateIdSize(idSize uint) { // Store the ID size obj := &versioned.Object{ Version: receptionIDSizeStorageVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: []byte(strconv.Itoa(s.idSize)), } @@ -379,7 +380,7 @@ func (s *Store) selectIdentity(rng io.Reader, now time.Time) (IdentityUse, error return IdentityUse{ Identity: selected.Identity, Fake: false, - UR: selected.UR, - ER: selected.ER, + UR: selected.UR, + ER: selected.ER, }, nil } diff --git a/storage/reception/store_test.go b/storage/reception/store_test.go index 70e6f41d5597ba6cc2cf58c981e0bf9bfb132667..8779e8f54cedacd24ae9e4c892fb3b19c279b814 100644 --- a/storage/reception/store_test.go +++ b/storage/reception/store_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/ekv" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "reflect" "testing" @@ -49,7 +50,7 @@ func TestLoadStore(t *testing.T) { // Fill active registration with fake identities for i := 0; i < 10; i++ { - testID, err := generateFakeIdentity(prng, 15, time.Now()) + testID, err := generateFakeIdentity(prng, 15, netTime.Now()) if err != nil { t.Fatalf("Failed to generate fake ID: %+v", err) } @@ -80,7 +81,7 @@ func TestStore_save(t *testing.T) { // Fill active registration with fake identities for i := 0; i < 10; i++ { - testID, err := generateFakeIdentity(prng, 15, time.Now()) + testID, err := generateFakeIdentity(prng, 15, netTime.Now()) if err != nil { t.Fatalf("Failed to generate fake ID: %+v", err) } @@ -119,7 +120,7 @@ func TestStore_makeStoredReferences(t *testing.T) { // Fill active registration with fake identities for i := 0; i < 10; i++ { - testID, err := generateFakeIdentity(prng, 15, time.Now()) + testID, err := generateFakeIdentity(prng, 15, netTime.Now()) if err != nil { t.Fatalf("Failed to generate fake ID: %+v", err) } @@ -145,7 +146,7 @@ func TestStore_GetIdentity(t *testing.T) { kv := versioned.NewKV(make(ekv.Memstore)) s := NewStore(kv) prng := rand.New(rand.NewSource(42)) - testID, err := generateFakeIdentity(prng, 15, time.Now()) + testID, err := generateFakeIdentity(prng, 15, netTime.Now()) if err != nil { t.Fatalf("Failed to generate fake ID: %+v", err) } @@ -168,7 +169,7 @@ func TestStore_AddIdentity(t *testing.T) { kv := versioned.NewKV(make(ekv.Memstore)) s := NewStore(kv) prng := rand.New(rand.NewSource(42)) - testID, err := generateFakeIdentity(prng, 15, time.Now()) + testID, err := generateFakeIdentity(prng, 15, netTime.Now()) if err != nil { t.Fatalf("Failed to generate fake ID: %+v", err) } @@ -188,7 +189,7 @@ func TestStore_RemoveIdentity(t *testing.T) { kv := versioned.NewKV(make(ekv.Memstore)) s := NewStore(kv) prng := rand.New(rand.NewSource(42)) - testID, err := generateFakeIdentity(prng, 15, time.Now()) + testID, err := generateFakeIdentity(prng, 15, netTime.Now()) if err != nil { t.Fatalf("Failed to generate fake ID: %+v", err) } @@ -224,7 +225,7 @@ func TestStore_prune(t *testing.T) { expected := make([]*registration, runs/2) for i := 0; i < runs; i++ { - timestamp := time.Now() + timestamp := netTime.Now() if i%2 == 0 { timestamp = timestamp.Add(24 * time.Hour) } @@ -241,7 +242,7 @@ func TestStore_prune(t *testing.T) { } } - s.prune(time.Now().Add(24 * time.Hour)) + s.prune(netTime.Now().Add(24 * time.Hour)) for i, reg := range s.active { if !reg.Equal(expected[i].Identity) { @@ -259,7 +260,7 @@ func TestStore_selectIdentity(t *testing.T) { expectedReg := make([]*registration, runs) for i := 0; i < runs; i++ { - testID, err := generateFakeIdentity(prng, 15, time.Now()) + testID, err := generateFakeIdentity(prng, 15, netTime.Now()) if err != nil { t.Fatalf("Failed to generate fake ID: %+v", err) } @@ -271,7 +272,7 @@ func TestStore_selectIdentity(t *testing.T) { } for i := 0; i < runs; i++ { - idu, err := s.selectIdentity(prng, time.Now()) + idu, err := s.selectIdentity(prng, netTime.Now()) if err != nil { t.Errorf("selectIdentity() produced an error: %+v", err) } diff --git a/storage/regCode.go b/storage/regCode.go index 8e9533395ede948ca495b6660e8d9c4a17cdb212..da0a306d78537f1baee90e193230146f4053753d 100644 --- a/storage/regCode.go +++ b/storage/regCode.go @@ -11,7 +11,7 @@ import ( "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage/versioned" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const regCodeKey = "regCode" @@ -23,7 +23,7 @@ func (s *Session) SetRegCode(regCode string) { &versioned.Object{ Version: regCodeVersion, Data: []byte(regCode), - Timestamp: time.Now(), + Timestamp: netTime.Now(), }); err != nil { jww.FATAL.Panicf("Failed to set the registration code: %s", err) } diff --git a/storage/regStatus.go b/storage/regStatus.go index ec18a0cfcb92aaa9c154f23528a40a96f202273f..dfb2619c810920269be39c91b2aa642bcba002ab 100644 --- a/storage/regStatus.go +++ b/storage/regStatus.go @@ -12,7 +12,7 @@ import ( "fmt" "github.com/pkg/errors" "gitlab.com/elixxir/client/storage/versioned" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentRegistrationStatusVersion = 0 @@ -59,7 +59,7 @@ func (rs RegistrationStatus) marshalBinary() []byte { func (s *Session) newRegStatus() error { s.regStatus = NotStarted - now := time.Now() + now := netTime.Now() obj := versioned.Object{ Version: currentRegistrationStatusVersion, @@ -98,7 +98,7 @@ func (s *Session) ForwardRegistrationStatus(regStatus RegistrationStatus) error s.regStatus, regStatus) } - now := time.Now() + now := netTime.Now() obj := versioned.Object{ Version: currentRegistrationStatusVersion, diff --git a/storage/rounds/earliestRound.go b/storage/rounds/earliestRound.go index b67fc1d6f7ca2d314eb9bfff1e625837e2f00453..fea486dd93d0e718bd292fc4bc5ae35acce133f6 100644 --- a/storage/rounds/earliestRound.go +++ b/storage/rounds/earliestRound.go @@ -5,8 +5,8 @@ import ( jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "sync" - "time" ) const unknownRoundStorageKey = "unknownRoundStorage" @@ -58,7 +58,7 @@ func (ur *EarliestRound) save() { // Create versioned object with data obj := &versioned.Object{ Version: unknownRoundStorageVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: urStr, } diff --git a/storage/rounds/unknownRounds.go b/storage/rounds/unknownRounds.go index 703c5b91b583c0ffe4c55a2c63feb4926a73b99b..3711b8787f530633a360bb91ab7911d9f8cc6830 100644 --- a/storage/rounds/unknownRounds.go +++ b/storage/rounds/unknownRounds.go @@ -12,9 +12,9 @@ import ( jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "sync" "sync/atomic" - "time" ) const ( @@ -52,7 +52,7 @@ type UnknownRoundsParams struct { func DefaultUnknownRoundsParams() UnknownRoundsParams { return UnknownRoundsParams{ MaxChecks: defaultMaxCheck, - Stored: true, + Stored: true, } } @@ -60,9 +60,9 @@ func DefaultUnknownRoundsParams() UnknownRoundsParams { func NewUnknownRounds(kv *versioned.KV, params UnknownRoundsParams) *UnknownRounds { - urs:= newUnknownRounds(kv, params) + urs := newUnknownRounds(kv, params) - if err := urs.save(); err!=nil{ + if err := urs.save(); err != nil { jww.FATAL.Printf("Failed to store New Unknown Rounds: %+v", err) } @@ -75,7 +75,7 @@ func newUnknownRounds(kv *versioned.KV, // Modify the prefix of the KV kv = kv.Prefix(unknownRoundPrefix) - urs:= &UnknownRounds{ + urs := &UnknownRounds{ rounds: make(map[id.Round]*uint64), params: params, kv: kv, @@ -147,8 +147,8 @@ func (urs *UnknownRounds) Iterate(checker func(rid id.Round) bool, } } - if err := urs.save(); err!=nil{ - jww.FATAL.Panicf("Failed to save unknown reounds after " + + if err := urs.save(); err != nil { + jww.FATAL.Panicf("Failed to save unknown reounds after "+ "edit: %+v", err) } @@ -157,10 +157,10 @@ func (urs *UnknownRounds) Iterate(checker func(rid id.Round) bool, // save stores the unknown rounds store. func (urs *UnknownRounds) save() error { - if !urs.params.Stored{ + if !urs.params.Stored { return nil } - now := time.Now() + now := netTime.Now() // Serialize the map data, err := json.Marshal(urs.rounds) @@ -179,14 +179,12 @@ func (urs *UnknownRounds) save() error { return urs.kv.Set(unknownRoundsStorageKey, unknownRoundsStorageVersion, &obj) } - // save stores the unknown rounds store. -func (urs *UnknownRounds) Delete() { +func (urs *UnknownRounds) Delete() { urs.mux.Lock() defer urs.mux.Unlock() - if urs.params.Stored{ - if err := urs.kv.Delete(unknownRoundPrefix,unknownRoundsStorageVersion); - err!=nil{ + if urs.params.Stored { + if err := urs.kv.Delete(unknownRoundPrefix, unknownRoundsStorageVersion); err != nil { jww.FATAL.Panicf("Failed to delete unknown rounds: %+v", err) } } @@ -198,4 +196,4 @@ func (urs *UnknownRounds) Delete() { // unmarshal loads the serialized round data into the UnknownRounds map func (urs *UnknownRounds) unmarshal(b []byte) error { return json.Unmarshal(b, &urs.rounds) -} \ No newline at end of file +} diff --git a/storage/session_test.go b/storage/session_test.go index 7b0d5ebc78c3f888d800d0506169f65a64c289f4..73fe66a252cabc444a9c6c325f9c582dff7d1705 100644 --- a/storage/session_test.go +++ b/storage/session_test.go @@ -27,7 +27,7 @@ func TestSession_Smoke(t *testing.T) { err := s.Set("testkey", &versioned.Object{ Version: 0, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: []byte("test"), }) if err != nil { diff --git a/storage/user/cryptographic.go b/storage/user/cryptographic.go index c01b6ffa1bc1e835f2cae169f678de566b572778..592fc9c2322d3f8552d3e0ebc5f721cd292ed384 100644 --- a/storage/user/cryptographic.go +++ b/storage/user/cryptographic.go @@ -15,7 +15,7 @@ import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/primitives/id" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentCryptographicIdentityVersion = 0 @@ -112,7 +112,7 @@ func (ci *CryptographicIdentity) save(kv *versioned.KV) error { obj := &versioned.Object{ Version: currentCryptographicIdentityVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: userDataBuffer.Bytes(), } diff --git a/storage/user/regValidationSig.go b/storage/user/regValidationSig.go index 4b5e09957e1597c899628fcecc58b0913afb575a..7440500fc680e2aee821ac761f47c8d9b201f40a 100644 --- a/storage/user/regValidationSig.go +++ b/storage/user/regValidationSig.go @@ -10,7 +10,7 @@ package user import ( jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage/versioned" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentRegValidationSigVersion = 0 @@ -68,7 +68,7 @@ func (u *User) SetTransmissionRegistrationValidationSignature(b []byte) { obj := &versioned.Object{ Version: currentRegValidationSigVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: b, } @@ -95,7 +95,7 @@ func (u *User) SetReceptionRegistrationValidationSignature(b []byte) { obj := &versioned.Object{ Version: currentRegValidationSigVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: b, } diff --git a/storage/user/regValidationSig_test.go b/storage/user/regValidationSig_test.go index c824ad8891075f71a7d9bbd5e90ab1ac91bb1263..68a69f60c8a8dca24161a4ec8bc9721d096aa6a9 100644 --- a/storage/user/regValidationSig_test.go +++ b/storage/user/regValidationSig_test.go @@ -13,8 +13,8 @@ import ( "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "testing" - "time" ) // Test User GetRegistrationValidationSignature function @@ -109,7 +109,7 @@ func TestUser_loadRegistrationValidationSignature(t *testing.T) { err = kv.Set(transmissionRegValidationSigKey, currentRegValidationSigVersion, &versioned.Object{ Version: currentRegValidationSigVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: sig, }) if err != nil { @@ -125,7 +125,7 @@ func TestUser_loadRegistrationValidationSignature(t *testing.T) { err = kv.Set(receptionRegValidationSigKey, currentRegValidationSigVersion, &versioned.Object{ Version: currentRegValidationSigVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: sig, }) if err != nil { diff --git a/storage/user/username.go b/storage/user/username.go index 268025e2ea728645a3124165c0cd30f368a93942..c36e0eba99883f5d735d4aeb2e557848f8ff4180 100644 --- a/storage/user/username.go +++ b/storage/user/username.go @@ -11,7 +11,7 @@ import ( "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage/versioned" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentUsernameVersion = 0 @@ -35,7 +35,7 @@ func (u *User) SetUsername(username string) error { obj := &versioned.Object{ Version: currentUsernameVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: []byte(username), } diff --git a/storage/user/username_test.go b/storage/user/username_test.go index 1da1ce0eb9dc96a8d85b965bbdb867bdc36846fe..7571d3804136b560f5730b76d69b5672cd6d5c48 100644 --- a/storage/user/username_test.go +++ b/storage/user/username_test.go @@ -12,8 +12,8 @@ import ( "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "testing" - "time" ) // Test normal function and errors for User's SetUsername function @@ -94,7 +94,7 @@ func TestUser_loadUsername(t *testing.T) { err = u.kv.Set(usernameKey, currentUsernameVersion, &versioned.Object{ Version: currentUsernameVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: []byte(u1), }) u.loadUsername() diff --git a/storage/utility/NDF.go b/storage/utility/NDF.go index 728ec90c9fcf12db993e25b5566203c98783dbf4..e4e6281b26ed92c6466a8afaa9cbec7375ed5107 100644 --- a/storage/utility/NDF.go +++ b/storage/utility/NDF.go @@ -10,7 +10,7 @@ package utility import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/primitives/ndf" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentNDFVersion = 0 @@ -35,7 +35,7 @@ func SaveNDF(kv *versioned.KV, key string, ndf *ndf.NetworkDefinition) error { return err } - now := time.Now() + now := netTime.Now() obj := versioned.Object{ Version: currentNDFVersion, diff --git a/storage/utility/cmixMessageBuffer.go b/storage/utility/cmixMessageBuffer.go index 367d4fd534bad871472590ecf5ecf4fd7c017f95..6091c65bc59ee0836384d4a475a15f8c8f7a940e 100644 --- a/storage/utility/cmixMessageBuffer.go +++ b/storage/utility/cmixMessageBuffer.go @@ -15,7 +15,7 @@ import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentCmixMessageVersion = 0 @@ -45,7 +45,7 @@ func (cmh *cmixMessageHandler) SaveMessage(kv *versioned.KV, m interface{}, key // Create versioned object obj := versioned.Object{ Version: currentCmixMessageVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: sm.Marshal(), } diff --git a/storage/utility/cmixMessageBuffer_test.go b/storage/utility/cmixMessageBuffer_test.go index f884d73d78629dbc51e88ce5443dfee8f3bde66e..b015cb2c66f028be8472b3281603f0b9e026b335 100644 --- a/storage/utility/cmixMessageBuffer_test.go +++ b/storage/utility/cmixMessageBuffer_test.go @@ -13,10 +13,10 @@ import ( "gitlab.com/elixxir/ekv" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "reflect" "testing" - "time" ) // Test happy path of cmixMessageHandler.SaveMessage(). @@ -159,7 +159,7 @@ func TestCmixMessageBuffer_Smoke(t *testing.T) { // expected map after they are added to the buffer. func makeTestCmixMessages(n int) ([]format.Message, []*id.ID, map[MessageHash]struct{}) { cmh := &cmixMessageHandler{} - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) mh := map[MessageHash]struct{}{} msgs := make([]format.Message, n) ids := make([]*id.ID, n) diff --git a/storage/utility/contact.go b/storage/utility/contact.go index cef79e2ffc8748798908cfcedd87a3e96c0c0e7e..89b9b31548ce467231e556fb607af106a25dedce 100644 --- a/storage/utility/contact.go +++ b/storage/utility/contact.go @@ -12,13 +12,13 @@ import ( "gitlab.com/elixxir/client/interfaces/contact" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/primitives/id" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentContactVersion = 0 func StoreContact(kv *versioned.KV, c contact.Contact) error { - now := time.Now() + now := netTime.Now() obj := versioned.Object{ Version: currentContactVersion, diff --git a/storage/utility/dh.go b/storage/utility/dh.go index ea2f6296d1289378189c4e4d85e6c344b9715aa1..9b0280ed1ef4bd96e71d15fcc788b5633c51fe03 100644 --- a/storage/utility/dh.go +++ b/storage/utility/dh.go @@ -10,13 +10,13 @@ package utility import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/crypto/cyclic" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentCyclicVersion = 0 func StoreCyclicKey(kv *versioned.KV, cy *cyclic.Int, key string) error { - now := time.Now() + now := netTime.Now() data, err := cy.GobEncode() if err != nil { diff --git a/storage/utility/e2eMessageBuffer.go b/storage/utility/e2eMessageBuffer.go index 9f0d3f417e6fd9c84e66c71dc324d13df31cf0ac..b8de8f65d3219f662df87680d174aec47743b97f 100644 --- a/storage/utility/e2eMessageBuffer.go +++ b/storage/utility/e2eMessageBuffer.go @@ -16,8 +16,7 @@ import ( "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/primitives/id" - - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentE2EMessageVersion = 0 @@ -44,7 +43,7 @@ func (emh *e2eMessageHandler) SaveMessage(kv *versioned.KV, m interface{}, key s // Create versioned object obj := versioned.Object{ Version: currentE2EMessageVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: b, } diff --git a/storage/utility/e2eMessageBuffer_test.go b/storage/utility/e2eMessageBuffer_test.go index aa7366ced5e5964fc666b67b3015f34a46433d4c..0aca79126fe53903957780f298e26ae1434597db 100644 --- a/storage/utility/e2eMessageBuffer_test.go +++ b/storage/utility/e2eMessageBuffer_test.go @@ -14,10 +14,10 @@ import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "reflect" "testing" - "time" ) // Test happy path of e2eMessageHandler.SaveMessage(). @@ -155,7 +155,7 @@ func TestE2EMessageHandler_Smoke(t *testing.T) { // makeTestE2EMessages creates a list of messages with random data and the // expected map after they are added to the buffer. func makeTestE2EMessages(n int, t *testing.T) ([]e2eMessage, []message.Send) { - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) msgs := make([]e2eMessage, n) send := make([]message.Send, n) for i := range msgs { diff --git a/storage/utility/group.go b/storage/utility/group.go index 20a05e8378fde158a0ec6b1b6009a6f9f68ebc55..2b2e40678cbdd7f7f004ce86a15965c346d7e042 100644 --- a/storage/utility/group.go +++ b/storage/utility/group.go @@ -10,13 +10,13 @@ package utility import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/crypto/cyclic" - "time" + "gitlab.com/xx_network/primitives/netTime" ) const currentGroupVersion = 0 func StoreGroup(kv *versioned.KV, grp *cyclic.Group, key string) error { - now := time.Now() + now := netTime.Now() data, err := grp.GobEncode() if err != nil { diff --git a/storage/utility/knownRounds.go b/storage/utility/knownRounds.go index 5b57c29484b91570abd93d7149ed0e91ccd9e651..85203145b7fead0131b3c861539c2c89cabd475b 100644 --- a/storage/utility/knownRounds.go +++ b/storage/utility/knownRounds.go @@ -61,7 +61,7 @@ func LoadKnownRounds(kv *versioned.KV, key string, size int) (*KnownRounds, erro // save saves the round buffer as a versioned object to the key value store. func (kr *KnownRounds) save() error { - now := time.Now() + now := netTime.Now() // Marshal list of rounds data, err := kr.rounds.Marshal() diff --git a/storage/utility/messageBuffer.go b/storage/utility/messageBuffer.go index c37255d88894d8076e0e2029080ae77ace107aa8..31af9f7f2a9b472873d476a686321a33145b2b42 100644 --- a/storage/utility/messageBuffer.go +++ b/storage/utility/messageBuffer.go @@ -13,8 +13,8 @@ import ( jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/primitives/format" + "gitlab.com/xx_network/primitives/netTime" "sync" - "time" ) // MessageHash stores the hash of a message, which is used as the key for each @@ -106,7 +106,7 @@ func LoadMessageBuffer(kv *versioned.KV, handler MessageHandler, // are in the "not processed" or "processing" state are stored together and // considered "not processed". func (mb *MessageBuffer) save() error { - now := time.Now() + now := netTime.Now() // Build a combined list of message hashes in messages + processingMessages allMessages := mb.getMessageList() diff --git a/storage/utility/messageBuffer_test.go b/storage/utility/messageBuffer_test.go index f331078fd5429a81c317620caf28802932617ba6..fc4de8be8dd5573520d02c9a35fae07593bb6a90 100644 --- a/storage/utility/messageBuffer_test.go +++ b/storage/utility/messageBuffer_test.go @@ -13,11 +13,11 @@ import ( "encoding/json" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/ekv" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "os" "reflect" "testing" - "time" ) type testHandler struct { @@ -294,7 +294,7 @@ func TestMessageBuffer_Failed(t *testing.T) { // addTestMessages adds random messages to the buffer. func addTestMessages(mb *MessageBuffer, n int) []MessageHash { - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) msgs := make([]MessageHash, n) for i := 0; i < n; i++ { keyData := make([]byte, 16) @@ -337,7 +337,7 @@ func cmpMessageHash(arrA, arrB []MessageHash) bool { // makeTestMessages creates a list of messages with random data and the expected // map after they are added to the buffer. func makeTestMessages(n int) ([][]byte, map[MessageHash]struct{}) { - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) mh := map[MessageHash]struct{}{} msgs := make([][]byte, n) for i := range msgs { diff --git a/storage/utility/meteredCmixMessageBuffer.go b/storage/utility/meteredCmixMessageBuffer.go index e4b7ab4fbce6e5e97cf00c8fcadb0d130f13167e..719faa3883ebf6d47e5abf86931c3e9e1b8e0143 100644 --- a/storage/utility/meteredCmixMessageBuffer.go +++ b/storage/utility/meteredCmixMessageBuffer.go @@ -14,6 +14,7 @@ import ( jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/primitives/format" + "gitlab.com/xx_network/primitives/netTime" "time" ) @@ -40,7 +41,7 @@ func (*meteredCmixMessageHandler) SaveMessage(kv *versioned.KV, m interface{}, k // Create versioned object obj := versioned.Object{ Version: currentMeteredCmixMessageVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: marshaled, } @@ -111,7 +112,7 @@ func (mcmb *MeteredCmixMessageBuffer) Add(m format.Message) { msg := meteredCmixMessage{ M: m.Marshal(), Count: 0, - Timestamp: time.Now(), + Timestamp: netTime.Now(), } mcmb.mb.Add(msg) } @@ -120,7 +121,7 @@ func (mcmb *MeteredCmixMessageBuffer) AddProcessing(m format.Message) { msg := meteredCmixMessage{ M: m.Marshal(), Count: 0, - Timestamp: time.Now(), + Timestamp: netTime.Now(), } mcmb.mb.AddProcessing(msg) } diff --git a/storage/utility/meteredCmixMessageBuffer_test.go b/storage/utility/meteredCmixMessageBuffer_test.go index bd2edcd259cb1bff0b04068d6c5fa8600fb16d82..a8116a7235dd7f64c701d04d3e655bef2237bc5a 100644 --- a/storage/utility/meteredCmixMessageBuffer_test.go +++ b/storage/utility/meteredCmixMessageBuffer_test.go @@ -13,6 +13,7 @@ import ( "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/ekv" "gitlab.com/elixxir/primitives/format" + "gitlab.com/xx_network/primitives/netTime" "math/rand" "testing" "time" @@ -188,7 +189,7 @@ func Test_meteredCmixMessageHandler_Smoke(t *testing.T) { // expected map after they are added to the buffer. func makeTestMeteredCmixMessage(n int) ([]meteredCmixMessage, map[MessageHash]struct{}) { mcmh := &meteredCmixMessageHandler{} - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) mh := map[MessageHash]struct{}{} msgs := make([]meteredCmixMessage, n) for i := range msgs { @@ -207,7 +208,7 @@ func makeTestMeteredCmixMessage(n int) ([]meteredCmixMessage, map[MessageHash]st // makeTestFormatMessages creates a list of messages with random data. func makeTestFormatMessages(n int) []format.Message { - prng := rand.New(rand.NewSource(time.Now().UnixNano())) + prng := rand.New(rand.NewSource(netTime.Now().UnixNano())) msgs := make([]format.Message, n) for i := range msgs { msgs[i] = format.NewMessage(128) diff --git a/storage/versioned/kv_test.go b/storage/versioned/kv_test.go index 58ec70ad4f77972a326d089df74263e7aeae80fb..393078152ab91f82045108c0eee3fa5f4706ed66 100644 --- a/storage/versioned/kv_test.go +++ b/storage/versioned/kv_test.go @@ -10,10 +10,9 @@ package versioned import ( "bytes" "errors" - "testing" - "time" - "gitlab.com/elixxir/ekv" + "gitlab.com/xx_network/primitives/netTime" + "testing" ) // KV Get should call the Upgrade function when it's available @@ -40,7 +39,7 @@ func TestVersionedKV_GetUpgrade(t *testing.T) { key := vkv.GetFullKey("test", 0) original := Object{ Version: 0, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: []byte("not upgraded"), } originalSerialized := original.Marshal() @@ -49,7 +48,7 @@ func TestVersionedKV_GetUpgrade(t *testing.T) { upgrade := []Upgrade{func(oldObject *Object) (*Object, error) { return &Object{ Version: 1, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: []byte("this object was upgraded from v0 to v1"), }, nil }} @@ -77,7 +76,7 @@ func TestVersionedKV_GetUpgrade_KeyNotFound(t *testing.T) { upgrade := []Upgrade{func(oldObject *Object) (*Object, error) { return &Object{ Version: 1, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: []byte("this object was upgraded from v0 to v1"), }, nil }} @@ -97,7 +96,7 @@ func TestVersionedKV_GetUpgrade_UpgradeReturnsError(t *testing.T) { key := vkv.GetFullKey("test", 0) original := Object{ Version: 0, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: []byte("not upgraded"), } originalSerialized := original.Marshal() @@ -125,7 +124,7 @@ func TestVersionedKV_Delete(t *testing.T) { key := vkv.GetFullKey("test", 0) original := Object{ Version: 0, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: []byte("not upgraded"), } originalSerialized := original.Marshal() @@ -151,7 +150,7 @@ func TestVersionedKV_Get(t *testing.T) { key := vkv.GetFullKey("test", originalVersion) original := Object{ Version: originalVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: []byte("not upgraded"), } originalSerialized := original.Marshal() @@ -176,7 +175,7 @@ func TestVersionedKV_Set(t *testing.T) { key := vkv.GetFullKey("test", originalVersion) original := Object{ Version: originalVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: []byte("not upgraded"), } err := vkv.Set("test", originalVersion, &original) diff --git a/ud/registered.go b/ud/registered.go index 8191f2667246b8936a098eac688c49d2c2ae2be5..d81e615894e6928f5e7a529cf10c2ca288f21e04 100644 --- a/ud/registered.go +++ b/ud/registered.go @@ -5,8 +5,8 @@ import ( "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage/versioned" + "gitlab.com/xx_network/primitives/netTime" "sync/atomic" - "time" ) const isRegisteredKey = "isRegisteredKey" @@ -44,7 +44,7 @@ func (m *Manager) setRegistered() error { obj := &versioned.Object{ Version: isRegisteredVersion, - Timestamp: time.Now(), + Timestamp: netTime.Now(), Data: data, }