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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
73f685d7
Commit
73f685d7
authored
3 years ago
by
RUANO RINCON Santiago
Browse files
Options
Downloads
Patches
Plain Diff
Add count occurrencies function
parent
184554a3
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/masterpow/payload.go
+5
-3
5 additions, 3 deletions
plugins/masterpow/payload.go
plugins/masterpow/plugin.go
+108
-79
108 additions, 79 deletions
plugins/masterpow/plugin.go
with
113 additions
and
82 deletions
plugins/masterpow/payload.go
+
5
−
3
View file @
73f685d7
...
...
@@ -7,6 +7,7 @@ import (
"github.com/cockroachdb/errors"
"github.com/iotaledger/goshimmer/packages/tangle/payload"
gossipPkg
"github.com/iotaledger/goshimmer/packages/gossip"
"github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/stringify"
)
...
...
@@ -51,12 +52,13 @@ type Payload struct {
}
// NewMasterPoWPayload creates a new test echo request payload
func
NewMasterPoWPayload
(
cpuUsage
float64
,
nodeDst
string
,
powdCast
uint8
)
*
Payload
{
//func NewMasterPoWPayload(cpuUsage float64, nodeDst string, powdCast uint8) *Payload {
func
NewMasterPoWPayload
(
cpuUsage
float64
,
nodeDst
*
gossipPkg
.
Neighbor
,
powdCast
uint8
)
*
Payload
{
return
&
Payload
{
subType
:
uint32
(
1234
),
cpuUsage
:
cpuUsage
,
nodeDst
:
nodeDst
,
nodeDstLen
:
uint32
(
len
([]
byte
(
nodeDst
))),
nodeDst
:
nodeDst
.
Peer
.
ID
()
.
String
()
,
nodeDstLen
:
uint32
(
len
([]
byte
(
nodeDst
.
Peer
.
ID
()
.
String
()
))),
powdCast
:
powdCast
,
}
...
...
This diff is collapsed.
Click to expand it.
plugins/masterpow/plugin.go
+
108
−
79
View file @
73f685d7
...
...
@@ -31,13 +31,16 @@ const (
// TODO: use it or remove it
func
neighborAdd
(
neighbor
*
gossipPkg
.
Neighbor
)
{
log
.
Debugf
(
"neighbor to be added: %s"
,
neighbor
.
Peer
.
ID
()
.
String
())
currentDifficulty
[
neighbor
.
Peer
.
ID
()
.
String
()]
=
1
log
.
Infof
(
"neighbor to be added: %s"
,
neighbor
.
Peer
.
PublicKey
()
.
String
())
//currentDifficulty[neighbor.Peer.PublicKey().String()] = 1
//neighbor or neighbor.Peer?
currentDifficulty
[
neighbor
]
=
1
}
func
neighborRemove
(
neighbor
*
gossipPkg
.
Neighbor
)
{
log
.
Debugf
(
"neighbor to be removed: %s"
,
neighbor
.
Peer
.
ID
()
.
String
())
delete
(
currentDifficulty
,
neighbor
.
Peer
.
ID
()
.
String
())
log
.
Infof
(
"neighbor to be removed: %s"
,
neighbor
.
Peer
.
PublicKey
()
.
String
())
//delete(currentDifficulty, neighbor.Peer.PublicKey().String())
delete
(
currentDifficulty
,
neighbor
)
}
var
(
...
...
@@ -48,7 +51,7 @@ var (
//TODO: this should be actually something like
//map[pubKey]int
currentDifficulty
=
make
(
map
[
string
]
int
)
currentDifficulty
=
make
(
map
[
*
gossipPkg
.
Neighbor
]
int
)
// Map that keeps count of the amount of messages sent by each neighbor
senderOccurrences
=
make
(
map
[
string
]
int
)
...
...
@@ -88,23 +91,46 @@ func configure(_ *node.Plugin) {
localhost
=
local
.
GetInstance
()
}
func
increaseOccurrencyCounts
(
msg
*
tangle
.
Message
)
{
messagePayload
:=
msg
.
Payload
()
/* TODO: Filter specific types of messages
*/
if
messagePayload
.
Type
()
!=
Type
{
func
increaseOccurrencyCounts
(
msg
*
tangle
.
Message
)
{
/*
// TODO: Filter specific types of messages
if msg.Payload().Type() != Type {
return
}
*/
log
.
Infof
(
"issuer: %s"
,
msg
.
issuerPublicKey
)
log
.
Debugf
(
"issuer: %s"
,
msg
.
IssuerPublicKey
())
msgIssuerPublicKey
:=
msg
.
IssuerPublicKey
()
.
String
()
for
n
,
_
:=
range
currentDifficulty
{
// check if the sender is in our neighbor map
if
n
.
Peer
.
PublicKey
()
.
String
()
==
msgIssuerPublicKey
{
senderOccurrences
[
msgIssuerPublicKey
]
++
//log.Infof("%s: %d", msgIssuerPublicKey, senderOccurrences[msgIssuerPublicKey])
}
}
}
func
countOccurrencies
()
{
for
issuer
,
occurrencies
:=
range
senderOccurrences
{
log
.
Infof
(
"%s: %d"
,
issuer
,
occurrencies
)
}
}
/*
messagelayer.Tangle().Events.MessageSolid.Attach(events.NewClosure(func(cachedMsgEvent *tangle.CachedMessageEvent) { // When receiving a message solid event do
defer cachedMsgEvent.MessageMetadata.Release()
cachedMsgEvent.Message.Consume(func(message *tangle.Message)
*/
func
configureEvents
()
{
messagelayer
.
Tangle
()
.
Solidifier
.
Events
.
MessageSolid
.
Attach
(
events
.
NewClosure
(
func
(
messageID
tangle
.
MessageID
)
{
messagelayer
.
Tangle
()
.
Storage
.
Message
(
messageID
)
.
Consume
(
func
(
msg
*
tangle
.
Message
)
{
increaseOccurrencyCounts
(
msg
)
//log.Infof("issuer: %s", msg.IssuerPublicKey())
// Move the rest to a separate function
messagePayload
:=
msg
.
Payload
()
if
messagePayload
.
Type
()
!=
Type
{
...
...
@@ -119,7 +145,7 @@ func configureEvents() {
log
.
Infof
(
"Master pow message received for nodeDst: %s"
,
msgPayload
.
nodeDst
)
if
msgPayload
.
nodeDst
==
localhost
.
ID
()
.
String
()
{
if
msgPayload
.
nodeDst
==
localhost
.
PublicKey
()
.
String
()
{
pow
.
Tune
(
int
(
msgPayload
.
PoWdCast
()))
log
.
Info
(
"PoWCast received"
)
}
...
...
@@ -155,13 +181,14 @@ func broadcastMasterPoWPayload() (doneSignal chan struct{}) {
func
run
(
_
*
node
.
Plugin
)
{
if
err
:=
daemon
.
BackgroundWorker
(
"MasterPoW"
,
func
(
shutdownSignal
<-
chan
struct
{})
{
ticker
:=
time
.
NewTicker
(
42
*
time
.
Second
)
defer
ticker
.
Stop
()
tickerBroadcast
:=
time
.
NewTicker
(
42
*
time
.
Second
)
defer
tickerBroadcast
.
Stop
()
tickerCount
:=
time
.
NewTicker
(
60
*
time
.
Second
)
for
{
select
{
case
<-
shutdownSignal
:
return
case
<-
ticker
.
C
:
case
<-
ticker
Broadcast
.
C
:
doneSignal
:=
broadcastMasterPoWPayload
()
select
{
...
...
@@ -170,6 +197,8 @@ func run(_ *node.Plugin) {
case
<-
doneSignal
:
// continue with the next beacon
}
case
<-
tickerCount
.
C
:
countOccurrencies
()
}
}
},
shutdown
.
PrioritySynchronization
);
err
!=
nil
{
...
...
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