Newer
Older
package client
import (
"sync"
Angelo Capossele
committed
"github.com/iotaledger/goshimmer/dapps/valuetransfers"
"github.com/iotaledger/goshimmer/packages/shutdown"
Angelo Capossele
committed
"github.com/iotaledger/goshimmer/packages/vote"
"github.com/iotaledger/goshimmer/plugins/config"
Angelo Capossele
committed
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/node"
const (
// PluginName is the name of the analysis client plugin.
PluginName = "Analysis-Client"
// CfgServerAddress defines the config flag of the analysis server address.
CfgServerAddress = "analysis.client.serverAddress"
// defines the report interval of the reporting in seconds.
reportIntervalSec = 5
Angelo Capossele
committed
// voteContextChunkThreshold defines the maximum number of vote context to fit into an FPC update.
voteContextChunkThreshold = 50
flag.String(CfgServerAddress, "ressims.iota.cafe:21888", "tcp server for collecting analysis information")
// plugin is the plugin instance of the analysis client plugin.
plugin *node.Plugin
once sync.Once
log *logger.Logger
conn *Connector
// Plugin gets the plugin instance
func Plugin() *node.Plugin {
once.Do(func() {
plugin = node.NewPlugin(PluginName, node.Enabled, run)
})
return plugin
}
Angelo Capossele
committed
finalized = make(map[string]vote.Opinion)
conn = NewConnector("tcp", config.Node().String(CfgServerAddress))
Angelo Capossele
committed
if err := daemon.BackgroundWorker(PluginName, func(shutdownSignal <-chan struct{}) {
Angelo Capossele
committed
conn.Start()
defer conn.Stop()
onFinalizedClosure := events.NewClosure(onFinalized)
valuetransfers.Voter().Events().Finalized.Attach(onFinalizedClosure)
defer valuetransfers.Voter().Events().Finalized.Detach(onFinalizedClosure)
onRoundExecutedClosure := events.NewClosure(onRoundExecuted)
valuetransfers.Voter().Events().RoundExecuted.Attach(onRoundExecutedClosure)
defer valuetransfers.Voter().Events().RoundExecuted.Detach(onRoundExecutedClosure)
ticker := time.NewTicker(reportIntervalSec * time.Second)
Angelo Capossele
committed
sendHeartbeat(conn, createHeartbeat())
sendMetricHeartbeat(conn, createMetricHeartbeat())
}, shutdown.PriorityAnalysis); err != nil {
log.Panicf("Failed to start as daemon: %s", err)