diff --git a/packages/node/node.go b/packages/node/node.go index 9f86209f5e259cbe9e79f50efc6b057e56246eab..443da232a8ca87ea15d151c3e51350e992b1888f 100644 --- a/packages/node/node.go +++ b/packages/node/node.go @@ -14,6 +14,7 @@ type Node struct { } var DisabledPlugins = make(map[string]bool) +var EnabledPlugins = make(map[string]bool) func Load(plugins ...*Plugin) *Node { node := &Node{ @@ -100,18 +101,38 @@ func (node *Node) LogFailure(pluginName string, message string) { } } +func getPluginKey(plugin *Plugin) string { + return strings.ToLower(strings.Replace(plugin.Name, " ", "", -1)) +} + +func isDisabled(plugin *Plugin) bool { + _, exists := DisabledPlugins[getPluginKey(plugin)] + + return exists +} + +func isEnabled(plugin *Plugin) bool { + _, exists := EnabledPlugins[getPluginKey(plugin)] + + return exists +} + func (node *Node) Load(plugins ...*Plugin) { if len(plugins) >= 1 { for _, plugin := range plugins { - if _, exists := DisabledPlugins[strings.ToLower(strings.Replace(plugin.Name, " ", "", -1))]; !exists { + status := plugin.Status + if (status == Enabled && !isDisabled(plugin)) || + (status == Disabled && isEnabled(plugin)) { + plugin.wg = node.wg plugin.Node = node plugin.Events.Configure.Trigger(plugin) + node.loadedPlugins = append(node.loadedPlugins, plugin) node.LogInfo("Node", "Loading Plugin: "+plugin.Name+" ... done") - - node.loadedPlugins = append(node.loadedPlugins, plugin) + } else { + node.LogInfo("Node", "Skipping Plugin: "+plugin.Name) } } } diff --git a/packages/node/parameters.go b/packages/node/parameters.go index d94f31e901131a2f4bb3ddd7a6202ee691467244..ee244e3d1a91eff75854e8f3cd7abdaeab336e9d 100644 --- a/packages/node/parameters.go +++ b/packages/node/parameters.go @@ -3,6 +3,8 @@ package node import "github.com/iotaledger/goshimmer/packages/parameter" var ( - LOG_LEVEL = parameter.AddInt("NODE/LOG_LEVEL", LOG_LEVEL_INFO, "controls the log types that are shown") + LOG_LEVEL = parameter.AddInt("NODE/LOG_LEVEL", LOG_LEVEL_INFO, "controls the log types that are shown") + DISABLE_PLUGINS = parameter.AddString("NODE/DISABLE_PLUGINS", "", "a list of plugins that shall be disabled") + ENABLE_PLUGINS = parameter.AddString("NODE/ENABLE_PLUGINS", "", "a list of plugins that shall be enabled") ) diff --git a/packages/node/plugin.go b/packages/node/plugin.go index a98a22beff880d7b73b210c14e38f0f6730a1ce1..4e915d3a48c211ab63fd6884d8cdd185cc69b522 100644 --- a/packages/node/plugin.go +++ b/packages/node/plugin.go @@ -6,16 +6,25 @@ import ( "github.com/iotaledger/goshimmer/packages/events" ) +const ( + Disabled = iota + Enabled +) + type Plugin struct { Node *Node Name string + Status int Events pluginEvents wg *sync.WaitGroup } -func NewPlugin(name string, callback Callback, callbacks ...Callback) *Plugin { +// Creates a new plugin with the given name, default status and callbacks. +// The last specified callback is the run callback, while all other callbacks are configure callbacks. +func NewPlugin(name string, status int, callback Callback, callbacks ...Callback) *Plugin { plugin := &Plugin{ - Name: name, + Name: name, + Status: status, Events: pluginEvents{ Configure: events.NewEvent(pluginCaller), Run: events.NewEvent(pluginCaller), diff --git a/plugins/analysis/plugin.go b/plugins/analysis/plugin.go index ee40ed44c39499b3336a428f390b1d21b58d9cea..44268dd0c077025e796cea7df2c859ef74f78061 100644 --- a/plugins/analysis/plugin.go +++ b/plugins/analysis/plugin.go @@ -9,7 +9,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/analysis/webinterface" ) -var PLUGIN = node.NewPlugin("Analysis", configure, run) +var PLUGIN = node.NewPlugin("Analysis", node.Enabled, configure, run) func configure(plugin *node.Plugin) { if *server.SERVER_PORT.Value != 0 { diff --git a/plugins/autopeering/plugin.go b/plugins/autopeering/plugin.go index c8633bffc4f2d02e21afd16fdc113e90be347bcc..9cac751d8815b488f2523e7141d4c0e35b0aecea 100644 --- a/plugins/autopeering/plugin.go +++ b/plugins/autopeering/plugin.go @@ -16,7 +16,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/gossip" ) -var PLUGIN = node.NewPlugin("Auto Peering", configure, run) +var PLUGIN = node.NewPlugin("Auto Peering", node.Enabled, configure, run) func configure(plugin *node.Plugin) { saltmanager.Configure(plugin) diff --git a/plugins/bundleprocessor/plugin.go b/plugins/bundleprocessor/plugin.go index 02303b751f4007b8bfd24f7b8e4f3237cfa8e23a..db1e1c28cfac3fd8d13041466e6081c6b9e8ed8f 100644 --- a/plugins/bundleprocessor/plugin.go +++ b/plugins/bundleprocessor/plugin.go @@ -9,7 +9,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/tangle" ) -var PLUGIN = node.NewPlugin("Bundle Processor", configure, run) +var PLUGIN = node.NewPlugin("Bundle Processor", node.Enabled, configure, run) func configure(plugin *node.Plugin) { tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) { diff --git a/plugins/cli/plugin.go b/plugins/cli/plugin.go index 4e98e5154bcdb9258fb3b1d236797dd5c5f14159..0c0158f0860d85e109d4d8eeb17918650917f47a 100644 --- a/plugins/cli/plugin.go +++ b/plugins/cli/plugin.go @@ -48,12 +48,19 @@ func init() { flag.Usage = printUsage } +func parseParameters() { + for _, pluginName := range strings.Fields(*node.DISABLE_PLUGINS.Value) { + node.DisabledPlugins[strings.ToLower(pluginName)] = true + } + for _, pluginName := range strings.Fields(*node.ENABLE_PLUGINS.Value) { + node.EnabledPlugins[strings.ToLower(pluginName)] = true + } +} + func configure(ctx *node.Plugin) { flag.Parse() - for _, disabledPlugin := range strings.Fields(*node.DISABLE_PLUGINS.Value) { - node.DisabledPlugins[strings.ToLower(disabledPlugin)] = true - } + parseParameters() fmt.Println(" _____ _ _ ________ ______ ___ ___________ ") fmt.Println(" / ___| | | |_ _| \\/ || \\/ || ___| ___ \\") @@ -66,6 +73,6 @@ func configure(ctx *node.Plugin) { ctx.Node.LogInfo("Node", "Loading plugins ...") } -var PLUGIN = node.NewPlugin("CLI", configure, func(plugin *node.Plugin) { +var PLUGIN = node.NewPlugin("CLI", node.Enabled, configure, func(plugin *node.Plugin) { }) diff --git a/plugins/dashboard/plugin.go b/plugins/dashboard/plugin.go index 2d4f992dc9e31489b3b0e013929f54bb3b3bd2a9..09fb191d4ed8208856af549544c9fc933dd227d4 100644 --- a/plugins/dashboard/plugin.go +++ b/plugins/dashboard/plugin.go @@ -10,7 +10,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/metrics" ) -var PLUGIN = node.NewPlugin("Dashboard", configure, run) +var PLUGIN = node.NewPlugin("Dashboard", node.Enabled, configure, run) func configure(plugin *node.Plugin) { http.HandleFunc("/dashboard", ServeHome) diff --git a/plugins/gossip-on-solidification/plugin.go b/plugins/gossip-on-solidification/plugin.go index 1c2268007bd1336b3643f294d3572953c38fa60a..bd040b9cae5b56a314cef22ab7c144b0c28d291a 100644 --- a/plugins/gossip-on-solidification/plugin.go +++ b/plugins/gossip-on-solidification/plugin.go @@ -8,7 +8,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/tangle" ) -var PLUGIN = node.NewPlugin("Gossip On Solidification", func(plugin *node.Plugin) { +var PLUGIN = node.NewPlugin("Gossip On Solidification", node.Enabled, func(plugin *node.Plugin) { tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) { gossip.SendTransaction(tx.MetaTransaction) })) diff --git a/plugins/gossip/plugin.go b/plugins/gossip/plugin.go index 0f02bd1404f577c1d265e239493aeec712e97ead..872e3caca32014e06be5a740e65461936973c06d 100644 --- a/plugins/gossip/plugin.go +++ b/plugins/gossip/plugin.go @@ -4,7 +4,7 @@ import ( "github.com/iotaledger/goshimmer/packages/node" ) -var PLUGIN = node.NewPlugin("Gossip", configure, run) +var PLUGIN = node.NewPlugin("Gossip", node.Enabled, configure, run) func configure(plugin *node.Plugin) { configureNeighbors(plugin) diff --git a/plugins/gracefulshutdown/plugin.go b/plugins/gracefulshutdown/plugin.go index ee3a074c18f7b7d078be19689b70c8192994977f..41da78c2495d915078c2029854fe527c8957c45e 100644 --- a/plugins/gracefulshutdown/plugin.go +++ b/plugins/gracefulshutdown/plugin.go @@ -15,7 +15,7 @@ import ( // 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 -var PLUGIN = node.NewPlugin("Graceful Shutdown", func(plugin *node.Plugin) { +var PLUGIN = node.NewPlugin("Graceful Shutdown", node.Enabled, func(plugin *node.Plugin) { gracefulStop := make(chan os.Signal) signal.Notify(gracefulStop, syscall.SIGTERM) diff --git a/plugins/metrics/plugin.go b/plugins/metrics/plugin.go index bcc9310e0715c9b1ef02bdd1e64972bac1533208..290b548fee32bb014b3bcd80e8b03a7f03f8ef7c 100644 --- a/plugins/metrics/plugin.go +++ b/plugins/metrics/plugin.go @@ -11,7 +11,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/gossip" ) -var PLUGIN = node.NewPlugin("Metrics", configure, run) +var PLUGIN = node.NewPlugin("Metrics", node.Enabled, configure, run) func configure(plugin *node.Plugin) { // increase received TPS counter whenever we receive a new transaction diff --git a/plugins/statusscreen-tps/plugin.go b/plugins/statusscreen-tps/plugin.go index 9b73392c93acbe5d71a52a9ab6b3b3339cd83a3a..e91121a15859989755e4e35667e166d3acc498ef 100644 --- a/plugins/statusscreen-tps/plugin.go +++ b/plugins/statusscreen-tps/plugin.go @@ -23,7 +23,7 @@ var receivedTps uint64 var solidTps uint64 -var PLUGIN = node.NewPlugin("Statusscreen TPS", func(plugin *node.Plugin) { +var PLUGIN = node.NewPlugin("Statusscreen TPS", node.Enabled, func(plugin *node.Plugin) { gossip.Events.ReceiveTransaction.Attach(events.NewClosure(func(_ *meta_transaction.MetaTransaction) { atomic.AddUint64(&receivedTpsCounter, 1) })) diff --git a/plugins/statusscreen/statusscreen.go b/plugins/statusscreen/statusscreen.go index 5c6d13e27a7162126eef3a69798110f6758ff059..91a83d4b809ecee103db1f0a9f16fa8a33777364 100644 --- a/plugins/statusscreen/statusscreen.go +++ b/plugins/statusscreen/statusscreen.go @@ -118,4 +118,4 @@ func run(plugin *node.Plugin) { }) } -var PLUGIN = node.NewPlugin("Status Screen", configure, run) +var PLUGIN = node.NewPlugin("Status Screen", node.Enabled, configure, run) diff --git a/plugins/tangle/plugin.go b/plugins/tangle/plugin.go index db5d513513b885a1e6c1a6d939c00e3bd751607d..f1efc83ac545aceb16670a933757104d83d3278a 100644 --- a/plugins/tangle/plugin.go +++ b/plugins/tangle/plugin.go @@ -6,7 +6,7 @@ import ( // region plugin module setup ////////////////////////////////////////////////////////////////////////////////////////// -var PLUGIN = node.NewPlugin("Tangle", configure, run) +var PLUGIN = node.NewPlugin("Tangle", node.Enabled, configure, run) func configure(plugin *node.Plugin) { configureTransactionDatabase(plugin) diff --git a/plugins/tipselection/plugin.go b/plugins/tipselection/plugin.go index 7980a59557a1db7c66006c1ebd8a1e582a6d9016..745c1dad4c8e2ecb8178fd2fc84c405a22357989 100644 --- a/plugins/tipselection/plugin.go +++ b/plugins/tipselection/plugin.go @@ -7,7 +7,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/tangle" ) -var PLUGIN = node.NewPlugin("Tipselection", configure, run) +var PLUGIN = node.NewPlugin("Tipselection", node.Enabled, configure, run) func configure(node *node.Plugin) { tangle.Events.TransactionSolid.Attach(events.NewClosure(func(transaction *value_transaction.ValueTransaction) { diff --git a/plugins/validator/plugin.go b/plugins/validator/plugin.go index dce2129b6d57b502f65a8f1621149ce8fa7e7119..10e80653233b88f608c2dce6ac59ad163ba50420 100644 --- a/plugins/validator/plugin.go +++ b/plugins/validator/plugin.go @@ -13,7 +13,7 @@ import ( . "github.com/iotaledger/iota.go/trinary" ) -var PLUGIN = node.NewPlugin("Validator", configure, run) +var PLUGIN = node.NewPlugin("Validator", node.Enabled, configure, run) // Creates bundle signature fragments and the corresponding address to validate against. // Each signature fragment after the first must go into its own meta transaction with value = 0. diff --git a/plugins/webapi-gtta/plugin.go b/plugins/webapi-gtta/plugin.go index 0ebad67343e0fcc402ce8e82f50fc71fdbf0ec39..73ee6f22f248d84a2caba7dcc69ee33e530bb5e9 100644 --- a/plugins/webapi-gtta/plugin.go +++ b/plugins/webapi-gtta/plugin.go @@ -11,7 +11,7 @@ import ( "github.com/labstack/echo" ) -var PLUGIN = node.NewPlugin("WebAPI GTTA Endpoint", func(plugin *node.Plugin) { +var PLUGIN = node.NewPlugin("WebAPI GTTA Endpoint", node.Enabled, func(plugin *node.Plugin) { webapi.AddEndpoint("getTransactionsToApprove", Handler) }) diff --git a/plugins/webapi-spammer/plugin.go b/plugins/webapi-spammer/plugin.go index 4823ac75ce19225b142c4029003848be1bf0a307..71ec701de756164a4930adfcfea63d13646b23e8 100644 --- a/plugins/webapi-spammer/plugin.go +++ b/plugins/webapi-spammer/plugin.go @@ -10,7 +10,7 @@ import ( "github.com/labstack/echo" ) -var PLUGIN = node.NewPlugin("Spammer", configure) +var PLUGIN = node.NewPlugin("Spammer", node.Enabled, configure) func configure(plugin *node.Plugin) { webapi.AddEndpoint("spammer", WebApiHandler) diff --git a/plugins/webapi/plugin.go b/plugins/webapi/plugin.go index f19c9e47b2a991a354a4cb05422b06a62b0996ba..f9de1de526423c6871d8ad02a3be310f485ecee6 100644 --- a/plugins/webapi/plugin.go +++ b/plugins/webapi/plugin.go @@ -10,7 +10,7 @@ import ( "github.com/labstack/echo" ) -var PLUGIN = node.NewPlugin("WebAPI", configure, run) +var PLUGIN = node.NewPlugin("WebAPI", node.Enabled, configure, run) var Server = echo.New() diff --git a/plugins/zeromq/plugin.go b/plugins/zeromq/plugin.go index 1b7e38af503c813ef397549098f9024964e2262e..50dfd046131ec2d1be094ac8440c8b54f5cff639 100644 --- a/plugins/zeromq/plugin.go +++ b/plugins/zeromq/plugin.go @@ -12,7 +12,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/tangle" ) -var PLUGIN = node.NewPlugin("ZeroMQ", configure, run) +var PLUGIN = node.NewPlugin("ZeroMQ", node.Enabled, configure, run) var publisher *Publisher var emptyTag = strings.Repeat("9", 27)