Skip to content
Snippets Groups Projects
Unverified Commit 2528f6b4 authored by Angelo Capossele's avatar Angelo Capossele Committed by GitHub
Browse files

Use clock in network delay (#815)

* :sparkles: Use clock

* :recycle: Refactor network delay with clock
parent 3d88854d
No related branches found
No related tags found
No related merge requests found
...@@ -4,11 +4,13 @@ import ( ...@@ -4,11 +4,13 @@ import (
"sync" "sync"
"time" "time"
"github.com/iotaledger/goshimmer/packages/clock"
"github.com/iotaledger/goshimmer/packages/tangle" "github.com/iotaledger/goshimmer/packages/tangle"
"github.com/iotaledger/goshimmer/plugins/autopeering/local" "github.com/iotaledger/goshimmer/plugins/autopeering/local"
"github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/goshimmer/plugins/messagelayer" "github.com/iotaledger/goshimmer/plugins/messagelayer"
"github.com/iotaledger/goshimmer/plugins/remotelog" "github.com/iotaledger/goshimmer/plugins/remotelog"
"github.com/iotaledger/goshimmer/plugins/syncbeaconfollower"
"github.com/iotaledger/hive.go/crypto/ed25519" "github.com/iotaledger/hive.go/crypto/ed25519"
"github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/logger"
...@@ -39,6 +41,9 @@ var ( ...@@ -39,6 +41,9 @@ var (
myID string myID string
myPublicKey ed25519.PublicKey myPublicKey ed25519.PublicKey
originPublicKey ed25519.PublicKey originPublicKey ed25519.PublicKey
// clockEnabled defines if the clock plugin is enabled.
clockEnabled bool
) )
// App gets the plugin instance. // App gets the plugin instance.
...@@ -74,6 +79,8 @@ func configure(_ *node.Plugin) { ...@@ -74,6 +79,8 @@ func configure(_ *node.Plugin) {
// subscribe to message-layer // subscribe to message-layer
messagelayer.Tangle().Events.MessageSolid.Attach(events.NewClosure(onReceiveMessageFromMessageLayer)) messagelayer.Tangle().Events.MessageSolid.Attach(events.NewClosure(onReceiveMessageFromMessageLayer))
clockEnabled = node.EnabledPlugins[node.GetPluginIdentifier("Clock")]
} }
func onReceiveMessageFromMessageLayer(cachedMessageEvent *tangle.CachedMessageEvent) { func onReceiveMessageFromMessageLayer(cachedMessageEvent *tangle.CachedMessageEvent) {
...@@ -105,7 +112,7 @@ func onReceiveMessageFromMessageLayer(cachedMessageEvent *tangle.CachedMessageEv ...@@ -105,7 +112,7 @@ func onReceiveMessageFromMessageLayer(cachedMessageEvent *tangle.CachedMessageEv
return return
} }
now := time.Now().UnixNano() now := clock.SyncedTime().UnixNano()
// abort if message was sent more than 1min ago // abort if message was sent more than 1min ago
// this should only happen due to a node resyncing // this should only happen due to a node resyncing
...@@ -124,6 +131,8 @@ func sendToRemoteLog(networkDelayObject *Object, receiveTime int64) { ...@@ -124,6 +131,8 @@ func sendToRemoteLog(networkDelayObject *Object, receiveTime int64) {
SentTime: networkDelayObject.sentTime, SentTime: networkDelayObject.sentTime,
ReceiveTime: receiveTime, ReceiveTime: receiveTime,
Delta: receiveTime - networkDelayObject.sentTime, Delta: receiveTime - networkDelayObject.sentTime,
Clock: clockEnabled,
Sync: syncbeaconfollower.Synced(),
Type: remoteLogType, Type: remoteLogType,
} }
_ = remoteLogger.Send(m) _ = remoteLogger.Send(m)
...@@ -135,5 +144,7 @@ type networkDelay struct { ...@@ -135,5 +144,7 @@ type networkDelay struct {
SentTime int64 `json:"sentTime"` SentTime int64 `json:"sentTime"`
ReceiveTime int64 `json:"receiveTime"` ReceiveTime int64 `json:"receiveTime"`
Delta int64 `json:"delta"` Delta int64 `json:"delta"`
Clock bool `json:"clock"`
Sync bool `json:"sync"`
Type string `json:"type"` Type string `json:"type"`
} }
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/iotaledger/goshimmer/packages/clock"
"github.com/iotaledger/goshimmer/plugins/issuer" "github.com/iotaledger/goshimmer/plugins/issuer"
"github.com/iotaledger/goshimmer/plugins/webapi" "github.com/iotaledger/goshimmer/plugins/webapi"
"github.com/labstack/echo" "github.com/labstack/echo"
...@@ -24,7 +25,9 @@ func broadcastNetworkDelayObject(c echo.Context) error { ...@@ -24,7 +25,9 @@ func broadcastNetworkDelayObject(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, Response{Error: err.Error()}) return c.JSON(http.StatusInternalServerError, Response{Error: err.Error()})
} }
msg, err := issuer.IssuePayload(NewObject(id, time.Now().UnixNano())) now := clock.SyncedTime().UnixNano()
msg, err := issuer.IssuePayload(NewObject(id, now))
if err != nil { if err != nil {
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()}) return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment