revert: utils.GetUnixEpoch()

This commit is contained in:
Richard Ramos 2021-10-12 09:12:54 -04:00
parent 051634c12a
commit c1bdead94d
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F
7 changed files with 19 additions and 9 deletions

View File

@ -15,6 +15,7 @@ import (
logging "github.com/ipfs/go-log"
"github.com/status-im/go-waku/waku/v2/node"
"github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/status-im/go-waku/waku/v2/utils"
)
var log = logging.Logger("basic2")
@ -77,7 +78,7 @@ func randomHex(n int) (string, error) {
func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) {
var contentTopic string = "test"
var version uint32 = 0
var timestamp float64 = float64(time.Now().Unix())
var timestamp float64 = utils.GetUnixEpoch()
p := new(node.Payload)
p.Data = []byte(wakuNode.ID() + ": " + msgContent)

View File

@ -13,6 +13,7 @@ import (
"github.com/status-im/go-waku/waku/v2/protocol/filter"
wpb "github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/status-im/go-waku/waku/v2/protocol/relay"
"github.com/status-im/go-waku/waku/v2/utils"
"golang.org/x/crypto/pbkdf2"
)
@ -84,7 +85,7 @@ func (cr *Chat) Publish(ctx context.Context, message string) error {
}
var version uint32
var timestamp float64 = float64(time.Now().Unix())
var timestamp float64 = utils.GetUnixEpoch()
var keyInfo *node.KeyInfo = &node.KeyInfo{}
if cr.useV1Payload { // Use WakuV1 encryption

View File

@ -17,6 +17,7 @@ import (
"github.com/status-im/go-waku/waku/v2/protocol/filter"
"github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/status-im/go-waku/waku/v2/protocol/relay"
"github.com/status-im/go-waku/waku/v2/utils"
)
var log = logging.Logger("filter2")
@ -125,7 +126,7 @@ func randomHex(n int) (string, error) {
func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) {
var version uint32 = 0
var timestamp float64 = float64(time.Now().UnixNano())
var timestamp float64 = utils.GetUnixEpoch()
p := new(node.Payload)
p.Data = []byte(wakuNode.ID() + ": " + msgContent)

View File

@ -17,6 +17,7 @@ import (
"github.com/status-im/go-waku/waku/v2/node"
"github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/status-im/go-waku/waku/v2/protocol/relay"
"github.com/status-im/go-waku/waku/v2/utils"
//"github.com/status-im/go-waku/waku/v2/protocol/store"
)
@ -182,7 +183,7 @@ func randomHex(n int) (string, error) {
func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) {
var version uint32 = 0
var timestamp float64 = float64(time.Now().Unix())
var timestamp float64 = utils.GetUnixEpoch()
p := new(node.Payload)
p.Data = []byte(wakuNode.ID() + ": " + msgContent)

View File

@ -6,13 +6,13 @@ import (
"encoding/hex"
"net"
"testing"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
"github.com/status-im/go-waku/waku/v2/node"
"github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/status-im/go-waku/waku/v2/utils"
)
func TestBasicSendingReceiving(t *testing.T) {
@ -61,7 +61,7 @@ func randomHex(n int) (string, error) {
func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) error {
var contentTopic string = "test"
var version uint32 = 0
var timestamp float64 = float64(time.Now().Unix())
var timestamp float64 = utils.GetUnixEpoch()
p := new(node.Payload)
p.Data = []byte(wakuNode.ID() + ": " + msgContent)

View File

@ -10,7 +10,6 @@ import (
"math"
"sort"
"sync"
"time"
logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p-core/host"
@ -360,7 +359,7 @@ func computeIndex(msg *pb.WakuMessage) (*pb.Index, error) {
digest := sha256.Sum256(data)
return &pb.Index{
Digest: digest[:],
ReceiverTime: float64(time.Now().Unix()),
ReceiverTime: utils.GetUnixEpoch(),
SenderTime: msg.Timestamp,
}, nil
}
@ -575,7 +574,7 @@ func (store *WakuStore) findLastSeen() float64 {
// the resume proc returns the number of retrieved messages if no error occurs, otherwise returns the error string
func (store *WakuStore) Resume(ctx context.Context, pubsubTopic string, peerList []peer.ID) (int, error) {
currentTime := float64(time.Now().UnixNano())
currentTime := utils.GetUnixEpoch()
lastSeenTime := store.findLastSeen()
var offset float64 = 200000

7
waku/v2/utils/time.go Normal file
View File

@ -0,0 +1,7 @@
package utils
import "time"
func GetUnixEpoch() float64 {
return float64(time.Now().UnixNano()) / float64(time.Second)
}