Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
2528f6b4
Unverified
Commit
2528f6b4
authored
4 years ago
by
Angelo Capossele
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Use clock in network delay (#815)
*
Use clock *
Refactor network delay with clock
parent
3d88854d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/networkdelay/plugin.go
+12
-1
12 additions, 1 deletion
plugins/networkdelay/plugin.go
plugins/networkdelay/webapi.go
+4
-1
4 additions, 1 deletion
plugins/networkdelay/webapi.go
with
16 additions
and
2 deletions
plugins/networkdelay/plugin.go
+
12
−
1
View file @
2528f6b4
...
@@ -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"`
}
}
This diff is collapsed.
Click to expand it.
plugins/networkdelay/webapi.go
+
4
−
1
View file @
2528f6b4
...
@@ -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
()})
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment