diff --git a/pluginmgr/core/plugins.go b/pluginmgr/core/plugins.go index 401d430a1c4ed697bd54905d0a484924425742bc..2ad52fcc444ef1d886fc21d5cbe944d03ce4a400 100644 --- a/pluginmgr/core/plugins.go +++ b/pluginmgr/core/plugins.go @@ -19,17 +19,17 @@ import ( ) var PLUGINS = node.Plugins( - banner.PLUGIN, - config.PLUGIN, - logger.PLUGIN, - cli.PLUGIN, - portcheck.PLUGIN, + banner.Plugin, + config.Plugin, + logger.Plugin, + cli.Plugin, + portcheck.Plugin, profiling.Plugin, - database.PLUGIN, + database.Plugin, autopeering.Plugin, - messagelayer.PLUGIN, - gossip.PLUGIN, - gracefulshutdown.PLUGIN, - metrics.PLUGIN, - drng.PLUGIN, + messagelayer.Plugin, + gossip.Plugin, + gracefulshutdown.Plugin, + metrics.Plugin, + drng.Plugin, ) diff --git a/pluginmgr/research/plugins.go b/pluginmgr/research/plugins.go index fa338c8a123e8b52fc75add18528be4db93c5a85..92fda562401834d917a3ac5f3eb79197dc8b4c8f 100644 --- a/pluginmgr/research/plugins.go +++ b/pluginmgr/research/plugins.go @@ -7,6 +7,6 @@ import ( ) var PLUGINS = node.Plugins( - remotelog.PLUGIN, + remotelog.Plugin, analysis.Plugin, ) diff --git a/pluginmgr/ui/plugins.go b/pluginmgr/ui/plugins.go index 1da8794f29f5f4d8efa88e9290598c2f27c41f43..3a6f013278af7a580d5e0071e9cb9f61b6f4ab3d 100644 --- a/pluginmgr/ui/plugins.go +++ b/pluginmgr/ui/plugins.go @@ -1,12 +1,12 @@ package ui import ( - "github.com/iotaledger/goshimmer/plugins/graph" "github.com/iotaledger/goshimmer/plugins/dashboard" + "github.com/iotaledger/goshimmer/plugins/graph" "github.com/iotaledger/hive.go/node" ) var PLUGINS = node.Plugins( - dashboard.PLUGIN, - graph.PLUGIN, + dashboard.Plugin, + graph.Plugin, ) diff --git a/pluginmgr/webapi/plugins.go b/pluginmgr/webapi/plugins.go index 464d058c33ddb59fe421511e5cae440a0f93698b..dd7a2e0ba9001cd6b5d1fbed6e92e535713f0769 100644 --- a/pluginmgr/webapi/plugins.go +++ b/pluginmgr/webapi/plugins.go @@ -13,12 +13,12 @@ import ( ) var PLUGINS = node.Plugins( - webapi.PLUGIN, - webauth.PLUGIN, - spammer.PLUGIN, - data.PLUGIN, - drng.PLUGIN, - message.PLUGIN, - autopeering.PLUGIN, + webapi.Plugin, + webauth.Plugin, + spammer.Plugin, + data.Plugin, + drng.Plugin, + message.Plugin, + autopeering.Plugin, info.Plugin, ) diff --git a/plugins/analysis/plugin.go b/plugins/analysis/plugin.go index f7b58bdec3be1b9d61790763e80fec5e7b200e6d..d98514a0b18a36801dab33c356210391156a26c6 100644 --- a/plugins/analysis/plugin.go +++ b/plugins/analysis/plugin.go @@ -10,15 +10,17 @@ import ( "github.com/iotaledger/goshimmer/plugins/config" ) -var pluginName = "Analysis" +// PluginName is the name of the analysis plugin. +const PluginName = "Analysis" -// Plugin defines the analysis plugin. -var Plugin = node.NewPlugin(pluginName, node.Enabled, configure, run) - -var log *logger.Logger +var ( + // Plugin is the plugin instance of the analysis plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run) + log *logger.Logger +) func configure(plugin *node.Plugin) { - log = logger.NewLogger(pluginName) + log = logger.NewLogger(PluginName) if config.Node.GetInt(server.CfgServerPort) != 0 { webinterface.Configure(plugin) server.Configure(plugin) diff --git a/plugins/autopeering/autopeering.go b/plugins/autopeering/autopeering.go index 64754dd30687f3d907d9fbb414a5a7de05c2da06..37614373d6318c25f968e747b97a9f054742f9e6 100644 --- a/plugins/autopeering/autopeering.go +++ b/plugins/autopeering/autopeering.go @@ -20,7 +20,6 @@ import ( "github.com/iotaledger/hive.go/autopeering/server" "github.com/iotaledger/hive.go/crypto/ed25519" "github.com/iotaledger/hive.go/identity" - "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" ) @@ -41,8 +40,6 @@ var ( // NetworkID specifies the autopeering network identifier NetworkID = hash32([]byte(banner.AppVersion + NetworkVersion)) - - log *logger.Logger ) func hash32(b []byte) uint32 { @@ -75,7 +72,7 @@ func configureAP() { ) // enable peer selection only when gossip is enabled - if !node.IsSkipped(gossip.PLUGIN) { + if !node.IsSkipped(gossip.Plugin) { Selection = selection.New(local.GetInstance(), Discovery, selection.Logger(log.Named("sel")), selection.NeighborValidator(selection.ValidatorFunc(isValidNeighbor)), @@ -98,7 +95,7 @@ func isValidNeighbor(p *peer.Peer) bool { } func start(shutdownSignal <-chan struct{}) { - defer log.Info("Stopping " + name + " ... done") + defer log.Info("Stopping " + PluginName + " ... done") lPeer := local.GetInstance() peering := lPeer.Services().Get(service.PeeringKey) @@ -134,11 +131,11 @@ func start(shutdownSignal <-chan struct{}) { defer Selection.Close() } - log.Infof("%s started: ID=%s Address=%s/%s", name, lPeer.ID(), localAddr.String(), localAddr.Network()) + log.Infof("%s started: ID=%s Address=%s/%s", PluginName, lPeer.ID(), localAddr.String(), localAddr.Network()) <-shutdownSignal - log.Infof("Stopping %s ...", name) + log.Infof("Stopping %s ...", PluginName) count := lPeer.Database().PersistSeeds() log.Infof("%d peers persisted as seeds", count) diff --git a/plugins/autopeering/plugin.go b/plugins/autopeering/plugin.go index 04e8d65a1b7e8a1e99ee56719db5738f8cef4702..102a7c44e6b44df95a649ac03d39abb6a64a8038 100644 --- a/plugins/autopeering/plugin.go +++ b/plugins/autopeering/plugin.go @@ -14,20 +14,23 @@ import ( "github.com/iotaledger/hive.go/node" ) -const name = "Autopeering" // name of the plugin +// PluginName is the name of the autopeering plugin. +const PluginName = "Autopeering" -// Plugin defines the autopeering plugin. -var Plugin = node.NewPlugin(name, node.Enabled, configure, run) +var ( + // Plugin is the plugin instance of the autopeering plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run) + log *logger.Logger +) func configure(*node.Plugin) { - log = logger.NewLogger(name) - + log = logger.NewLogger(PluginName) configureEvents() configureAP() } func run(*node.Plugin) { - if err := daemon.BackgroundWorker(name, start, shutdown.PriorityAutopeering); err != nil { + if err := daemon.BackgroundWorker(PluginName, start, shutdown.PriorityAutopeering); err != nil { log.Errorf("Failed to start as daemon: %s", err) } } diff --git a/plugins/banner/plugin.go b/plugins/banner/plugin.go index b4e4b28487f9cfb48d08c2af61900beb539b2dc1..1f0936a6cd9cfa90a38a840f1cf200ef46883e33 100644 --- a/plugins/banner/plugin.go +++ b/plugins/banner/plugin.go @@ -6,7 +6,11 @@ import ( "github.com/iotaledger/hive.go/node" ) -var PLUGIN = node.NewPlugin("Banner", node.Enabled, configure, run) +// PluginName is the name of the banner plugin. +const PluginName = "Banner" + +// Plugin is the plugin instance of the banner plugin. +var Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run) const ( // AppVersion version number diff --git a/plugins/cli/plugin.go b/plugins/cli/plugin.go index da1b61411ee8b1b483fd4063f4da38e304daf98f..2875dcdeaeeac5acd2510b747e83be66c1b05221 100644 --- a/plugins/cli/plugin.go +++ b/plugins/cli/plugin.go @@ -11,9 +11,14 @@ import ( "github.com/iotaledger/goshimmer/plugins/banner" ) -var PLUGIN = node.NewPlugin("CLI", node.Enabled) +// PluginName is the name of the CLI plugin. +const PluginName = "CLI" -var version = flag.BoolP("version", "v", false, "Prints the GoShimmer version") +var ( + // Plugin is the plugin instance of the CLI plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled) + version = flag.BoolP("version", "v", false, "Prints the GoShimmer version") +) func init() { for name, status := range node.GetPlugins() { @@ -24,7 +29,7 @@ func init() { flag.Usage = printUsage - PLUGIN.Events.Init.Attach(events.NewClosure(onInit)) + Plugin.Events.Init.Attach(events.NewClosure(onInit)) } func onAddPlugin(name string, status int) { diff --git a/plugins/config/plugin.go b/plugins/config/plugin.go index 1cd941232ced9cecbafd719f86209c47b46d747d..f9353574a50a34f23459a189cfa4f4d8e3fc3842 100644 --- a/plugins/config/plugin.go +++ b/plugins/config/plugin.go @@ -10,11 +10,14 @@ import ( flag "github.com/spf13/pflag" ) +// PluginName is the name of the config plugin. +const PluginName = "Config" + var ( - // define the plugin as a placeholder, so the init methods get executed accordingly - PLUGIN = node.NewPlugin("Config", node.Enabled) + // Plugin is the plugin instance of the config plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled) - // flags< + // flags configName = flag.StringP("config", "c", "config", "Filename of the config file without the file extension") configDirPath = flag.StringP("config-dir", "d", ".", "Path to the directory containing the config file") @@ -33,7 +36,7 @@ var ( ) func Init() { - PLUGIN.Events.Init.Trigger(PLUGIN) + Plugin.Events.Init.Trigger(Plugin) } func init() { @@ -41,7 +44,7 @@ func init() { Node = viper.New() Node.SetDefault(logger.ViperKey, defaultLoggerConfig) - PLUGIN.Events.Init.Attach(events.NewClosure(func(*node.Plugin) { + Plugin.Events.Init.Attach(events.NewClosure(func(*node.Plugin) { if err := fetch(false); err != nil { panic(err) } diff --git a/plugins/dashboard/plugin.go b/plugins/dashboard/plugin.go index add51aa795dc5daebeea5d833dfe6164a0e84963..2f91ea3d84fc95dbd2b1c62fb554d2c514dc9f12 100644 --- a/plugins/dashboard/plugin.go +++ b/plugins/dashboard/plugin.go @@ -29,8 +29,12 @@ import ( "github.com/iotaledger/hive.go/workerpool" ) +// PluginName is the name of the dashboard plugin. +const PluginName = "Dashboard" + var ( - PLUGIN = node.NewPlugin("Dashboard", node.Enabled, configure, run) + // Plugin is the plugin instance of the dashboard plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run) log *logger.Logger nodeStartAt = time.Now() diff --git a/plugins/database/plugin.go b/plugins/database/plugin.go index c9c279c9a29a0a2223994adbdf75f5e23bb72d91..2227b4ffc8cfc015dabbf9749c3246fa81900b1c 100644 --- a/plugins/database/plugin.go +++ b/plugins/database/plugin.go @@ -14,29 +14,29 @@ import ( "github.com/iotaledger/hive.go/node" ) -const ( - PLUGIN_NAME = "Database" -) +// PluginName is the name of the database plugin. +const PluginName = "Database" var ( - PLUGIN = node.NewPlugin(PLUGIN_NAME, node.Enabled, configure, run) + // Plugin is the plugin instance of the database plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run) log *logger.Logger ) -func configure(plugin *node.Plugin) { - log = logger.NewLogger(PLUGIN_NAME) +func configure(_ *node.Plugin) { + log = logger.NewLogger(PluginName) _ = database.GetBadgerInstance() } -func run(plugin *node.Plugin) { - daemon.BackgroundWorker(PLUGIN_NAME+"_GC", func(shutdownSignal <-chan struct{}) { +func run(_ *node.Plugin) { + daemon.BackgroundWorker(PluginName+"_GC", func(shutdownSignal <-chan struct{}) { timeutil.Ticker(func() { database.CleanupBadgerInstance(log) }, 5*time.Minute, shutdownSignal) }, shutdown.PriorityBadgerGarbageCollection) - daemon.BackgroundWorker(PLUGIN_NAME, func(shutdownSignal <-chan struct{}) { + daemon.BackgroundWorker(PluginName, func(shutdownSignal <-chan struct{}) { <-shutdownSignal log.Infof("Syncing database to disk...") database.GetBadgerInstance().Close() diff --git a/plugins/drng/plugin.go b/plugins/drng/plugin.go index 8b14bda09bbef01451f09da72d67be57afeb8a05..42949d5468d5fa7854cb4309b970aca07f1765ac 100644 --- a/plugins/drng/plugin.go +++ b/plugins/drng/plugin.go @@ -18,17 +18,18 @@ import ( "github.com/iotaledger/hive.go/node" ) -const name = "DRNG" // name of the plugin - -var PLUGIN = node.NewPlugin(name, node.Enabled, configure, run) +// PluginName is the name of the DRNG plugin. +const PluginName = "DRNG" var ( + // Plugin is the plugin instance of the DRNG plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run) Instance *drng.DRNG log *logger.Logger ) func configure(*node.Plugin) { - log = logger.NewLogger(name) + log = logger.NewLogger(PluginName) // parse identities of the committee members committeeMembers, err := parseCommitteeMembers() diff --git a/plugins/fpc/plugin.go b/plugins/fpc/plugin.go index cf57b6f446391e56c76cce0f4d4bf2af9a40e96d..9bc19085251a254603df9d4bb9d03c55e3a504fd 100644 --- a/plugins/fpc/plugin.go +++ b/plugins/fpc/plugin.go @@ -26,10 +26,12 @@ import ( "github.com/iotaledger/hive.go/node" ) -const name = "FPC" +// PluginName is the name of the FPC plugin. +const PluginName = "FPC" var ( - PLUGIN = node.NewPlugin(name, node.Enabled, configure, run) + // Plugin is the plugin instance of the FPC plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run) log *logger.Logger voter *fpc.FPC voterOnce sync.Once @@ -59,7 +61,7 @@ func Voter() vote.DRNGRoundBasedVoter { } func configure(_ *node.Plugin) { - log = logger.NewLogger(name) + log = logger.NewLogger(PluginName) lPeer := local.GetInstance() bindAddr := config.Node.GetString(CfgFPCBindAddress) diff --git a/plugins/gossip/gossip.go b/plugins/gossip/gossip.go index be42070803563bd6d164cd4bf443ec41bf45c856..3a95698d62be831bde4cc60108adac5d37ee4346 100644 --- a/plugins/gossip/gossip.go +++ b/plugins/gossip/gossip.go @@ -39,7 +39,7 @@ func configureGossip() { } func start(shutdownSignal <-chan struct{}) { - defer log.Info("Stopping " + name + " ... done") + defer log.Info("Stopping " + PluginName + " ... done") lPeer := local.GetInstance() @@ -65,10 +65,10 @@ func start(shutdownSignal <-chan struct{}) { mgr.Start(srv) defer mgr.Close() - log.Infof("%s started: Address=%s/%s", name, localAddr.String(), localAddr.Network()) + log.Infof("%s started: Address=%s/%s", PluginName, localAddr.String(), localAddr.Network()) <-shutdownSignal - log.Info("Stopping " + name + " ...") + log.Info("Stopping " + PluginName + " ...") } // loads the given message from the message layer or an error if not found. diff --git a/plugins/gossip/plugin.go b/plugins/gossip/plugin.go index ef7ebeceeddc3133b7eac78e4bfe0ff9c330daff..2b671dc4ffb30610daaaf87eb3e4b965a3882c8b 100644 --- a/plugins/gossip/plugin.go +++ b/plugins/gossip/plugin.go @@ -15,19 +15,21 @@ import ( "github.com/iotaledger/goshimmer/plugins/messagelayer" ) -const name = "Gossip" // name of the plugin +// PluginName is the name of the gossip plugin. +const PluginName = "Gossip" -var PLUGIN = node.NewPlugin(name, node.Enabled, configure, run) +// Plugin is the plugin instance of the gossip plugin. +var Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run) func configure(*node.Plugin) { - log = logger.NewLogger(name) + log = logger.NewLogger(PluginName) configureGossip() configureEvents() } func run(*node.Plugin) { - if err := daemon.BackgroundWorker(name, start, shutdown.PriorityGossip); err != nil { + if err := daemon.BackgroundWorker(PluginName, start, shutdown.PriorityGossip); err != nil { log.Errorf("Failed to start as daemon: %s", err) } } diff --git a/plugins/gracefulshutdown/plugin.go b/plugins/gracefulshutdown/plugin.go index 2cc523798146b0c67d1686595e7a51e5484c3a66..ac57b2b5b324ad0025601b24a2aae42b39c3470d 100644 --- a/plugins/gracefulshutdown/plugin.go +++ b/plugins/gracefulshutdown/plugin.go @@ -12,13 +12,18 @@ import ( "github.com/iotaledger/hive.go/node" ) -// maximum amount of time to wait for background processes to terminate. After that the process is killed. -const WAIT_TO_KILL_TIME_IN_SECONDS = 10 +// PluginName is the name of the graceful shutdown plugin. +const PluginName = "Graceful Shutdown" + +// WaitToKillTimeInSeconds is the maximum amount of time to wait for background processes to terminate. +// After that the process is killed. +const WaitToKillTimeInSeconds = 10 var log *logger.Logger -var PLUGIN = node.NewPlugin("Graceful Shutdown", node.Enabled, func(plugin *node.Plugin) { - log = logger.NewLogger("Graceful Shutdown") +// Plugin is the plugin instance of the graceful shutdown plugin. +var Plugin = node.NewPlugin(PluginName, node.Enabled, func(plugin *node.Plugin) { + log = logger.NewLogger(PluginName) gracefulStop := make(chan os.Signal) signal.Notify(gracefulStop, syscall.SIGTERM) @@ -27,20 +32,20 @@ var PLUGIN = node.NewPlugin("Graceful Shutdown", node.Enabled, func(plugin *node go func() { <-gracefulStop - log.Warnf("Received shutdown request - waiting (max %d) to finish processing ...", WAIT_TO_KILL_TIME_IN_SECONDS) + log.Warnf("Received shutdown request - waiting (max %d) to finish processing ...", WaitToKillTimeInSeconds) go func() { start := time.Now() for x := range time.Tick(1 * time.Second) { secondsSinceStart := x.Sub(start).Seconds() - if secondsSinceStart <= WAIT_TO_KILL_TIME_IN_SECONDS { + if secondsSinceStart <= WaitToKillTimeInSeconds { processList := "" runningBackgroundWorkers := daemon.GetRunningBackgroundWorkers() if len(runningBackgroundWorkers) >= 1 { processList = "(" + strings.Join(runningBackgroundWorkers, ", ") + ") " } - log.Warnf("Received shutdown request - waiting (max %d seconds) to finish processing %s...", WAIT_TO_KILL_TIME_IN_SECONDS-int(secondsSinceStart), processList) + log.Warnf("Received shutdown request - waiting (max %d seconds) to finish processing %s...", WaitToKillTimeInSeconds-int(secondsSinceStart), processList) } else { log.Error("Background processes did not terminate in time! Forcing shutdown ...") os.Exit(1) diff --git a/plugins/graph/plugin.go b/plugins/graph/plugin.go index 934def8c0d747bb7e93cd9e13badafe1d5d7f818..46006acb44b219ab8d79f9a4f66faa4f1cf7160f 100644 --- a/plugins/graph/plugin.go +++ b/plugins/graph/plugin.go @@ -26,8 +26,12 @@ import ( "github.com/iotaledger/hive.go/workerpool" ) +// PluginName is the name of the graph plugin. +const PluginName = "Graph" + var ( - PLUGIN = node.NewPlugin("Graph", node.Disabled, configure, run) + // Plugin is the plugin instance of the graph plugin. + Plugin = node.NewPlugin(PluginName, node.Disabled, configure, run) log *logger.Logger @@ -67,7 +71,7 @@ func configureSocketIOServer() error { } func configure(plugin *node.Plugin) { - log = logger.NewLogger("Graph") + log = logger.NewLogger(PluginName) initRingBuffers() router = http.NewServeMux() @@ -81,7 +85,7 @@ func configure(plugin *node.Plugin) { fs := http.FileServer(http.Dir(config.Node.GetString(CFG_WEBROOT))) if err := configureSocketIOServer(); err != nil { - log.Panicf("Graph: %v", err.Error()) + log.Panicf("%v", err.Error()) } router.Handle("/", fs) diff --git a/plugins/logger/plugin.go b/plugins/logger/plugin.go index d3f85693a0031a613811fe056ac13d560dbcbe2c..9381eef4cabab9647439b05a2500f259832b5b90 100644 --- a/plugins/logger/plugin.go +++ b/plugins/logger/plugin.go @@ -7,15 +7,18 @@ import ( "github.com/iotaledger/hive.go/node" ) -// define the plugin as a placeholder, so the init methods get executed accordingly -var PLUGIN = node.NewPlugin("Logger", node.Enabled) +// PluginName is the name of the logger plugin. +const PluginName = "Logger" + +// Plugin is the plugin instance of the logger plugin. +var Plugin = node.NewPlugin(PluginName, node.Enabled) func Init() { - PLUGIN.Events.Init.Trigger(PLUGIN) + Plugin.Events.Init.Trigger(Plugin) } func init() { - PLUGIN.Events.Init.Attach(events.NewClosure(func(*node.Plugin) { + Plugin.Events.Init.Attach(events.NewClosure(func(*node.Plugin) { if err := logger.InitGlobalLogger(config.Node); err != nil { panic(err) } diff --git a/plugins/messagelayer/plugin.go b/plugins/messagelayer/plugin.go index a942cc838d5d153f9f87d263b49e54ce48b8a63a..e2729184438f0485be6af63818e0059e397d6931 100644 --- a/plugins/messagelayer/plugin.go +++ b/plugins/messagelayer/plugin.go @@ -25,7 +25,8 @@ const ( ) var ( - PLUGIN = node.NewPlugin(PluginName, node.Enabled, configure, run) + // Plugin is the plugin instance of the message layer plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run) MessageParser *messageparser.MessageParser MessageRequester *messagerequester.MessageRequester TipSelector *tipselector.TipSelector diff --git a/plugins/metrics/plugin.go b/plugins/metrics/plugin.go index e9607a16a773b826f9b0c02742dd8f8aac20dd8b..10d52add3d897c82d8a3673811710cb2d31cce1e 100644 --- a/plugins/metrics/plugin.go +++ b/plugins/metrics/plugin.go @@ -14,7 +14,11 @@ import ( "github.com/iotaledger/goshimmer/plugins/messagelayer" ) -var PLUGIN = node.NewPlugin("Metrics", node.Enabled, configure, run) +// PluginName is the name of the metrics plugin. +const PluginName = "Metrics" + +// Plugin is the plugin instance of the metrics plugin. +var Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run) func configure(_ *node.Plugin) { // increase received MPS counter whenever we attached a message diff --git a/plugins/portcheck/plugin.go b/plugins/portcheck/plugin.go index 260439a964d4907c78344c81911651151bc49632..43a5ae3813c44dd74b73db8a8b57dbdec351da83 100644 --- a/plugins/portcheck/plugin.go +++ b/plugins/portcheck/plugin.go @@ -13,17 +13,17 @@ import ( "github.com/iotaledger/hive.go/node" ) -const ( - PLUGIN_NAME = "PortCheck" -) +// PluginName is the name of the port check plugin. +const PluginName = "PortCheck" var ( - PLUGIN = node.NewPlugin(PLUGIN_NAME, node.Enabled, configure, run) + // Plugin is the plugin instance of the port check plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run) log *logger.Logger ) func configure(*node.Plugin) { - log = logger.NewLogger(PLUGIN_NAME) + log = logger.NewLogger(PluginName) } func run(*node.Plugin) { diff --git a/plugins/remotelog/plugin.go b/plugins/remotelog/plugin.go index 9622b0af565b852a0476f9c61b16608dbe3df0a2..f69fe1b93afe85dc335b7585778d542fd2b1f488 100644 --- a/plugins/remotelog/plugin.go +++ b/plugins/remotelog/plugin.go @@ -40,13 +40,15 @@ type logMessage struct { } const ( - CFG_SERVER_ADDRESS = "logger.remotelog.serverAddress" - CFG_DISABLE_EVENTS = "logger.disableEvents" - PLUGIN_NAME = "RemoteLog" + CfgServerAddress = "logger.remotelog.serverAddress" + CfgDisableEvents = "logger.disableEvents" + // PluginName is the name of the remote log plugin. + PluginName = "RemoteLog" ) var ( - PLUGIN = node.NewPlugin(PLUGIN_NAME, node.Disabled, configure, run) + // Plugin is the plugin instance of the remote plugin instance. + Plugin = node.NewPlugin(PluginName, node.Disabled, configure, run) log *logger.Logger conn net.Conn myID string @@ -56,16 +58,16 @@ var ( ) func configure(plugin *node.Plugin) { - log = logger.NewLogger(PLUGIN_NAME) + log = logger.NewLogger(PluginName) - if config.Node.GetBool(CFG_DISABLE_EVENTS) { - log.Fatalf("%s in config.json needs to be false so that events can be captured!", CFG_DISABLE_EVENTS) + if config.Node.GetBool(CfgDisableEvents) { + log.Fatalf("%s in config.json needs to be false so that events can be captured!", CfgDisableEvents) return } - c, err := net.Dial("udp", config.Node.GetString(CFG_SERVER_ADDRESS)) + c, err := net.Dial("udp", config.Node.GetString(CfgServerAddress)) if err != nil { - log.Fatalf("Could not create UDP socket to '%s'. %v", config.Node.GetString(CFG_SERVER_ADDRESS), err) + log.Fatalf("Could not create UDP socket to '%s'. %v", config.Node.GetString(CfgServerAddress), err) return } conn = c @@ -88,14 +90,14 @@ func run(plugin *node.Plugin) { workerPool.TrySubmit(level, name, msg) }) - daemon.BackgroundWorker(PLUGIN_NAME, func(shutdownSignal <-chan struct{}) { + daemon.BackgroundWorker(PluginName, func(shutdownSignal <-chan struct{}) { logger.Events.AnyMsg.Attach(logEvent) workerPool.Start() <-shutdownSignal - log.Infof("Stopping %s ...", PLUGIN_NAME) + log.Infof("Stopping %s ...", PluginName) logger.Events.AnyMsg.Detach(logEvent) workerPool.Stop() - log.Infof("Stopping %s ... done", PLUGIN_NAME) + log.Infof("Stopping %s ... done", PluginName) }, shutdown.PriorityRemoteLog) } diff --git a/plugins/webapi/autopeering/plugin.go b/plugins/webapi/autopeering/plugin.go index 5ee22878c7d43236ec71626fb6358111e63a85da..0a5ceeb180628f4ea3607873d9b1796146cca2d9 100644 --- a/plugins/webapi/autopeering/plugin.go +++ b/plugins/webapi/autopeering/plugin.go @@ -14,7 +14,11 @@ import ( "github.com/labstack/echo" ) -var PLUGIN = node.NewPlugin("WebAPI autopeering Endpoint", node.Enabled, configure) +// PluginName is the name of the web API autopeering endpoint plugin. +const PluginName = "WebAPI autopeering Endpoint" + +// Plugin is the plugin instance of the web API autopeering endpoint plugin. +var Plugin = node.NewPlugin(PluginName, node.Enabled, configure) func configure(plugin *node.Plugin) { webapi.Server.GET("autopeering/neighbors", getNeighbors) diff --git a/plugins/webapi/data/plugin.go b/plugins/webapi/data/plugin.go index 8264dad4e5119c07a084655f0bb88d7eba129adf..cfc3278b0d28490f90f0d72ff8ae9a2e4d81247a 100644 --- a/plugins/webapi/data/plugin.go +++ b/plugins/webapi/data/plugin.go @@ -11,11 +11,17 @@ import ( "github.com/labstack/echo" ) -var PLUGIN = node.NewPlugin("WebAPI data Endpoint", node.Enabled, configure) -var log *logger.Logger +// PluginName is the name of the web API data endpoint plugin. +const PluginName = "WebAPI data Endpoint" + +var ( + // Plugin is the plugin instance of the web API data endpoint plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure) + log *logger.Logger +) func configure(plugin *node.Plugin) { - log = logger.NewLogger("API-data") + log = logger.NewLogger(PluginName) webapi.Server.POST("data", broadcastData) } diff --git a/plugins/webapi/drng/plugin.go b/plugins/webapi/drng/plugin.go index 1963f5c7cc4f7c965d8889e6b8aeaaace08917aa..d835cd6e2c8a96226050a2abc0a77f593701d46f 100644 --- a/plugins/webapi/drng/plugin.go +++ b/plugins/webapi/drng/plugin.go @@ -5,17 +5,19 @@ import ( "github.com/iotaledger/goshimmer/plugins/webapi/drng/collectiveBeacon" "github.com/iotaledger/goshimmer/plugins/webapi/drng/info/committee" "github.com/iotaledger/goshimmer/plugins/webapi/drng/info/randomness" - "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" ) -var PLUGIN = node.NewPlugin("WebAPI dRNG Endpoint", node.Enabled, configure) -var log *logger.Logger +// PluginName is the name of the web API DRNG endpoint plugin. +const PluginName = "WebAPI DRNG Endpoint" -func configure(plugin *node.Plugin) { - log = logger.NewLogger("API-dRNG") - webapi.Server.POST("drng/collectiveBeacon", collectiveBeacon.Handler) +var ( + // Plugin is the plugin instance of the web API DRNG endpoint plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure) +) +func configure(_ *node.Plugin) { + webapi.Server.POST("drng/collectiveBeacon", collectiveBeacon.Handler) webapi.Server.GET("drng/info/committee", committee.Handler) webapi.Server.GET("drng/info/randomness", randomness.Handler) } diff --git a/plugins/webapi/getMessageByHash/plugin.go b/plugins/webapi/getMessageByHash/plugin.go index 7333cbe5c3c69096c501070a89bec1325730b19d..0ec23b7583b2fb01a406ac8556e1673b00ad091c 100644 --- a/plugins/webapi/getMessageByHash/plugin.go +++ b/plugins/webapi/getMessageByHash/plugin.go @@ -13,8 +13,14 @@ import ( "github.com/iotaledger/hive.go/node" ) -var PLUGIN = node.NewPlugin("WebAPI getMessageByHash Endpoint", node.Enabled, configure) -var log *logger.Logger +// PluginName is the name of the web API getMessageByHash endpoint plugin. +const PluginName = "WebAPI getMessageByHash Endpoint" + +var ( + // Plugin is the plugin instance of the web API getMessageByHash endpoint plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure) + log *logger.Logger +) func configure(plugin *node.Plugin) { log = logger.NewLogger("API-getMessageByHash") diff --git a/plugins/webapi/info/plugin.go b/plugins/webapi/info/plugin.go index e2ae0357c4e29bc264fc60072c841ff9caa30aee..cd3c397dd0aecbbfb265eb481aa4c52ac78e4b0a 100644 --- a/plugins/webapi/info/plugin.go +++ b/plugins/webapi/info/plugin.go @@ -10,10 +10,13 @@ import ( "github.com/labstack/echo" ) -// Plugin exports the plugin -var Plugin = node.NewPlugin("WebAPI info Endpoint", node.Enabled, configure) +// PluginName is the name of the web API info endpoint plugin. +const PluginName = "WebAPI info Endpoint" -func configure(plugin *node.Plugin) { +// Plugin is the plugin instance of the web API info endpoint plugin. +var Plugin = node.NewPlugin(PluginName, node.Enabled, configure) + +func configure(_ *node.Plugin) { webapi.Server.GET("info", getInfo) } diff --git a/plugins/webapi/message/plugin.go b/plugins/webapi/message/plugin.go index 80994cf8fe009fa90553e966ad6545bceecb886b..7e4ebdd3af42bb6088a54d765b7d5d189f255d1c 100644 --- a/plugins/webapi/message/plugin.go +++ b/plugins/webapi/message/plugin.go @@ -12,11 +12,17 @@ import ( "github.com/iotaledger/hive.go/node" ) -var PLUGIN = node.NewPlugin("WebAPI message Endpoint", node.Enabled, configure) -var log *logger.Logger +// PluginName is the name of the web API message endpoint plugin. +const PluginName = "WebAPI message Endpoint" + +var ( + // Plugin is the plugin instance of the web API message endpoint plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure) + log *logger.Logger +) func configure(plugin *node.Plugin) { - log = logger.NewLogger("API-message") + log = logger.NewLogger(PluginName) webapi.Server.POST("message/findById", findMessageById) } diff --git a/plugins/webapi/plugin.go b/plugins/webapi/plugin.go index 1c69ea5d95c68d867902355d7910e5f536cc4708..304cb589939be592f7d943f563ca49dd15ba8b8a 100644 --- a/plugins/webapi/plugin.go +++ b/plugins/webapi/plugin.go @@ -13,13 +13,18 @@ import ( "github.com/iotaledger/goshimmer/plugins/config" ) -var PLUGIN = node.NewPlugin("WebAPI", node.Enabled, configure, run) -var log *logger.Logger - -var Server = echo.New() +// PluginName is the name of the web API plugin. +const PluginName = "WebAPI" + +var ( + // Plugin is the plugin instance of the web API plugin. + Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run) + log *logger.Logger + Server = echo.New() +) func configure(plugin *node.Plugin) { - log = logger.NewLogger("WebAPI") + log = logger.NewLogger(PluginName) Server.HideBanner = true Server.HidePort = true Server.GET("/", IndexRequest) diff --git a/plugins/webapi/spammer/plugin.go b/plugins/webapi/spammer/plugin.go index 641f0eb3c1dbc8db310a7a781eb8a623cad0f45a..f747235fd483d494b8384a78dbcd25267793f512 100644 --- a/plugins/webapi/spammer/plugin.go +++ b/plugins/webapi/spammer/plugin.go @@ -13,7 +13,11 @@ import ( var messageSpammer *spammer.Spammer -var PLUGIN = node.NewPlugin("Spammer", node.Disabled, configure, run) +// PluginName is the name of the spammer plugin. +const PluginName = "Spammer" + +// Plugin is the plugin instance of the spammer plugin. +var Plugin = node.NewPlugin(PluginName, node.Disabled, configure, run) func configure(plugin *node.Plugin) { messageSpammer = spammer.New(messagelayer.MessageFactory) diff --git a/plugins/webauth/webauth.go b/plugins/webauth/webauth.go index 4c18c57aec0062920915ed399dc7289ae25a6dfb..f4f45b55e7493a45d566e6b7d323d55961ddc651 100644 --- a/plugins/webauth/webauth.go +++ b/plugins/webauth/webauth.go @@ -16,12 +16,18 @@ import ( "github.com/dgrijalva/jwt-go" ) -var PLUGIN = node.NewPlugin("WebAPI Auth", node.Disabled, configure) -var log *logger.Logger -var privateKey string +// PluginName is the name of the web API auth plugin. +const PluginName = "WebAPI Auth" + +var ( + // Plugin is the plugin instance of the web API auth plugin. + Plugin = node.NewPlugin(PluginName, node.Disabled, configure) + log *logger.Logger + privateKey string +) func configure(plugin *node.Plugin) { - log = logger.NewLogger("WebAPI Auth") + log = logger.NewLogger(PluginName) privateKey = config.Node.GetString(WEBAPI_AUTH_PRIVATE_KEY) if len(privateKey) == 0 { panic("")