Skip to content
Snippets Groups Projects
Commit d4aaa4a4 authored by Samuelle MOLLARD's avatar Samuelle MOLLARD
Browse files

Added comments

parent c0efa45d
No related branches found
No related tags found
1 merge request!1V data collection
......@@ -33,40 +33,40 @@ var (
// Plugin gets the plugin instance.
func Plugin() *node.Plugin {
pluginOnce.Do(func() {
write_to_file("solidification_time;message_id;payload\n")
write_to_file("solidification_time;message_id;payload\n") // Writes on the log file the first line
plugin = node.NewPlugin(PluginName, node.Enabled, configure, run)
})
return plugin
}
func configure(*node.Plugin) {
func configure(*node.Plugin) { // Runs once
log = logger.NewLogger(PluginName)
messagelayer.Tangle().Events.MessageSolid.Attach(events.NewClosure(func(cachedMsgEvent *tangle.CachedMessageEvent) {
messagelayer.Tangle().Events.MessageSolid.Attach(events.NewClosure(func(cachedMsgEvent *tangle.CachedMessageEvent) { // When receiving a message solid event do
defer cachedMsgEvent.MessageMetadata.Release()
//cachedMsgEvent.MessageMetadata.Consume(func(object objectstorage.StorableObject) {
//cachedMsgEvent.MessageMetadata.Consume(func(object objectstorage.StorableObject) { This was a more accurate way to mesure the solidification time but crashed the nodes sometimes for some reason
// msgMetaData := object.(*tangle.MessageMetadata)
// solidificationTime = msgMetaData.SolidificationTime().UnixNano()
//})
cachedMsgEvent.Message.Consume(func(message *tangle.Message) {
solidificationTime := time.Now().UnixNano()
to_write := fmt.Sprintf("%d;%s;%s\n", solidificationTime - message.IssuingTime().UnixNano(), message.ID(), message.String())
cachedMsgEvent.Message.Consume(func(message *tangle.Message) { // Consume the message and call the function
solidificationTime := time.Now().UnixNano() // Since we just received the message, that means the message just got solidificated, so this is a close approximation, which is good enough for now
to_write := fmt.Sprintf("%d;%s;%s\n", solidificationTime - message.IssuingTime().UnixNano(), message.ID(), message.String()) // Write the data to the file
write_to_file(to_write)
log.Info(message.IssuingTime().UnixNano(), message.ID(), message.StrongParents(), message.WeakParents())
})
}))
pow.Events().PowDone.Attach(events.NewClosure(func(ev *pow.PowDoneEvent) {
pow.Events().PowDone.Attach(events.NewClosure(func(ev *pow.PowDoneEvent) { // Allows catching pow done events, which we don't log right now
log.Info(ev.Difficulty, ev.Duration)
}))
}
func write_to_file(text_to_append string) {
func write_to_file(text_to_append string) { // Writes or append a string to the file /tmp/data.csv
f, _ := os.OpenFile("/tmp/data.csv",
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
defer f.Close()
f.WriteString(text_to_append)
}
func run(*node.Plugin) {
func run(*node.Plugin) { // Logs information with goshimmer logs, which we don't really use, but can be nice if others use it later
log.Infof("Starting %s ...", PluginName)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment