Skip to content
Snippets Groups Projects
Commit dc5aab86 authored by Wolfgang Welz's avatar Wolfgang Welz
Browse files

Feat: plugins can be disabled and enabled

parent e00b07cb
Branches
Tags
No related merge requests found
Showing
with 65 additions and 26 deletions
......@@ -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)
}
}
}
......
......@@ -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")
)
......@@ -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),
......
......@@ -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 {
......
......@@ -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)
......
......@@ -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) {
......
......@@ -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) {
})
......@@ -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)
......
......@@ -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)
}))
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
......@@ -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)
}))
......
......@@ -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)
......@@ -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)
......
......@@ -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) {
......
......@@ -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.
......
......@@ -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)
})
......
......@@ -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)
......
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment