From 02d4ef34b1b634e1ba77b33c5c32748eb4de22db Mon Sep 17 00:00:00 2001 From: joshemb <josh@elixxir.io> Date: Mon, 10 Oct 2022 12:37:58 -0700 Subject: [PATCH] Add netTime functionality to bindings --- bindings/timeNow.go | 34 ++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 2 ++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 bindings/timeNow.go diff --git a/bindings/timeNow.go b/bindings/timeNow.go new file mode 100644 index 000000000..d4ef6929d --- /dev/null +++ b/bindings/timeNow.go @@ -0,0 +1,34 @@ +/////////////////////////////////////////////////////////////////////////////// +// 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" +) + +// SetTimeSource will set the time source that will be used when retrieving the +// current time using [netTime.Now]. +// +// Parameters: +// - timeNow is an object which adheres to [netTime.TimeSource]. Specifically, +// this object should a NowMs() method which return a 64-bit integer value. +func SetTimeSource(timeNow netTime.TimeSource) { + netTime.SetTimeSource(timeNow) +} + +// SetOffset will set an internal offset variable. All calls to [netTime.Now] +// will have this offset applied to this value. +// +// Parameters: +// - offset is a time by which netTime.Now will be offset. This value may be +// negative or positive. This expects a 64-bit integer value which will +// represent the number in microseconds this offset will be. +func SetOffset(offset int64) { + netTime.SetOffset(time.Duration(offset) * time.Microsecond) +} diff --git a/go.mod b/go.mod index 5bb8e8389..372fb69b5 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( gitlab.com/elixxir/primitives v0.0.3-0.20220606195757-40f7a589347f gitlab.com/xx_network/comms v0.0.4-0.20220630163702-f3d372ef6acd gitlab.com/xx_network/crypto v0.0.5-0.20220729193517-1e5e96f39f6e - gitlab.com/xx_network/primitives v0.0.4-0.20220712193914-aebd8544396e + gitlab.com/xx_network/primitives v0.0.4-0.20221010192422-3479f09b7769 go.uber.org/ratelimit v0.2.0 golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa golang.org/x/net v0.0.0-20220802222814-0bcc04d9c69b diff --git a/go.sum b/go.sum index cccd675d6..2e2ecf7e9 100644 --- a/go.sum +++ b/go.sum @@ -461,6 +461,8 @@ gitlab.com/xx_network/primitives v0.0.4-0.20220324193139-b292d1ae6e7e/go.mod h1: gitlab.com/xx_network/primitives v0.0.4-0.20220630163313-7890038258c6/go.mod h1:AXVVFt7dDAeIUpOGPiStCcUIKsBXLWbmV/BgZ4T+tOo= gitlab.com/xx_network/primitives v0.0.4-0.20220712193914-aebd8544396e h1:zRRo/v3KUo3MtpjNJaB03LR+Zi2g1afYF8yKWl1t19o= gitlab.com/xx_network/primitives v0.0.4-0.20220712193914-aebd8544396e/go.mod h1:AXVVFt7dDAeIUpOGPiStCcUIKsBXLWbmV/BgZ4T+tOo= +gitlab.com/xx_network/primitives v0.0.4-0.20221010192422-3479f09b7769 h1:BBYSog3VSKudey4rhWnCw54PcGcD4YRjTrnwzOhJ/GE= +gitlab.com/xx_network/primitives v0.0.4-0.20221010192422-3479f09b7769/go.mod h1:AXVVFt7dDAeIUpOGPiStCcUIKsBXLWbmV/BgZ4T+tOo= gitlab.com/xx_network/ring v0.0.3-0.20220222211904-da613960ad93 h1:eJZrXqHsMmmejEPWw8gNAt0I8CGAMNO/7C339Zco3TM= gitlab.com/xx_network/ring v0.0.3-0.20220222211904-da613960ad93/go.mod h1:aLzpP2TiZTQut/PVHR40EJAomzugDdHXetbieRClXIM= go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A= -- GitLab