diff --git a/main.go b/main.go index 32513b07b2b64b42d5a1fb4572e4953337884a87..928652848245ce63a37a29830c9540d467cb53fc 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,9 @@ import ( "net/http" _ "net/http/pprof" + "github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/goshimmer/plugins/gracefulshutdown" + "github.com/iotaledger/goshimmer/plugins/logger" "github.com/iotaledger/goshimmer/plugins/tangle" @@ -16,12 +18,12 @@ import ( ) func main() { - cli.LoadConfig() - go http.ListenAndServe("localhost:6060", nil) // pprof Server for Debbuging Mutexes node.Run( node.Plugins( + config.PLUGIN, + logger.PLUGIN, cli.PLUGIN, remotelog.PLUGIN, diff --git a/packages/database/database.go b/packages/database/database.go index 1a1465ca4a87055e1414a954443d2a3d07ec21ef..094abae6294fcc988bdc49f5bb585b546c32f5dc 100644 --- a/packages/database/database.go +++ b/packages/database/database.go @@ -8,7 +8,7 @@ import ( "github.com/dgraph-io/badger/v2" "github.com/dgraph-io/badger/v2/options" - "github.com/iotaledger/goshimmer/packages/parameter" + "github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/hive.go/database" "github.com/iotaledger/hive.go/logger" ) @@ -34,7 +34,7 @@ func Get(dbPrefix byte, optionalBadger ...*badger.DB) (Database, error) { func GetBadgerInstance() *badger.DB { once.Do(func() { - dbDir := parameter.NodeConfig.GetString(CFG_DIRECTORY) + dbDir := config.NodeConfig.GetString(CFG_DIRECTORY) var dbDirClear bool // check whether the database is new, by checking whether any file exists within diff --git a/plugins/analysis/client/plugin.go b/plugins/analysis/client/plugin.go index fa9623609aa4b56d7bc9c776908010df081dda69..b7285656d1a0f5dfc57234c83abe3a46649f380a 100644 --- a/plugins/analysis/client/plugin.go +++ b/plugins/analysis/client/plugin.go @@ -6,15 +6,6 @@ import ( "sync" "time" - "github.com/iotaledger/goshimmer/packages/parameter" - "github.com/iotaledger/goshimmer/packages/shutdown" - "github.com/iotaledger/goshimmer/plugins/analysis/types/addnode" - "github.com/iotaledger/goshimmer/plugins/analysis/types/connectnodes" - "github.com/iotaledger/goshimmer/plugins/analysis/types/disconnectnodes" - "github.com/iotaledger/goshimmer/plugins/analysis/types/ping" - "github.com/iotaledger/goshimmer/plugins/analysis/types/removenode" - "github.com/iotaledger/goshimmer/plugins/autopeering" - "github.com/iotaledger/goshimmer/plugins/autopeering/local" "github.com/iotaledger/hive.go/autopeering/discover" "github.com/iotaledger/hive.go/autopeering/selection" "github.com/iotaledger/hive.go/daemon" @@ -23,6 +14,16 @@ import ( "github.com/iotaledger/hive.go/network" "github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/timeutil" + + "github.com/iotaledger/goshimmer/packages/shutdown" + "github.com/iotaledger/goshimmer/plugins/analysis/types/addnode" + "github.com/iotaledger/goshimmer/plugins/analysis/types/connectnodes" + "github.com/iotaledger/goshimmer/plugins/analysis/types/disconnectnodes" + "github.com/iotaledger/goshimmer/plugins/analysis/types/ping" + "github.com/iotaledger/goshimmer/plugins/analysis/types/removenode" + "github.com/iotaledger/goshimmer/plugins/autopeering" + "github.com/iotaledger/goshimmer/plugins/autopeering/local" + "github.com/iotaledger/goshimmer/plugins/config" ) var log *logger.Logger @@ -39,7 +40,7 @@ func Run(plugin *node.Plugin) { return default: - if conn, err := net.Dial("tcp", parameter.NodeConfig.GetString(CFG_SERVER_ADDRESS)); err != nil { + if conn, err := net.Dial("tcp", config.NodeConfig.GetString(CFG_SERVER_ADDRESS)); err != nil { log.Debugf("Could not connect to reporting server: %s", err.Error()) timeutil.Sleep(1*time.Second, shutdownSignal) diff --git a/plugins/analysis/plugin.go b/plugins/analysis/plugin.go index 1dc75fff1e3613bdd05dbced7c3bc4e832109a9a..405f801478ab505b65af912a00869e111f8ca321 100644 --- a/plugins/analysis/plugin.go +++ b/plugins/analysis/plugin.go @@ -1,12 +1,13 @@ package analysis import ( - "github.com/iotaledger/goshimmer/packages/parameter" + "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/hive.go/node" + "github.com/iotaledger/goshimmer/plugins/analysis/client" "github.com/iotaledger/goshimmer/plugins/analysis/server" "github.com/iotaledger/goshimmer/plugins/analysis/webinterface" - "github.com/iotaledger/hive.go/logger" - "github.com/iotaledger/hive.go/node" + "github.com/iotaledger/goshimmer/plugins/config" ) var PLUGIN = node.NewPlugin("Analysis", node.Enabled, configure, run) @@ -14,21 +15,21 @@ var log *logger.Logger func configure(plugin *node.Plugin) { log = logger.NewLogger("Analysis") - if parameter.NodeConfig.GetInt(server.CFG_SERVER_PORT) != 0 { + if config.NodeConfig.GetInt(server.CFG_SERVER_PORT) != 0 { webinterface.Configure(plugin) server.Configure(plugin) } } func run(plugin *node.Plugin) { - if parameter.NodeConfig.GetInt(server.CFG_SERVER_PORT) != 0 { + if config.NodeConfig.GetInt(server.CFG_SERVER_PORT) != 0 { webinterface.Run(plugin) server.Run(plugin) } else { log.Info("Server is disabled (server-port is 0)") } - if parameter.NodeConfig.GetString(client.CFG_SERVER_ADDRESS) != "" { + if config.NodeConfig.GetString(client.CFG_SERVER_ADDRESS) != "" { client.Run(plugin) } else { log.Info("Client is disabled (server-address is empty)") diff --git a/plugins/analysis/server/plugin.go b/plugins/analysis/server/plugin.go index 215eefa19743648dbc073eacd69b164f686f81f4..39ad60875c809886742186a948c1211d9d64b90a 100644 --- a/plugins/analysis/server/plugin.go +++ b/plugins/analysis/server/plugin.go @@ -5,19 +5,20 @@ import ( "errors" "math" - "github.com/iotaledger/goshimmer/packages/parameter" - "github.com/iotaledger/goshimmer/packages/shutdown" - "github.com/iotaledger/goshimmer/plugins/analysis/types/addnode" - "github.com/iotaledger/goshimmer/plugins/analysis/types/connectnodes" - "github.com/iotaledger/goshimmer/plugins/analysis/types/disconnectnodes" - "github.com/iotaledger/goshimmer/plugins/analysis/types/ping" - "github.com/iotaledger/goshimmer/plugins/analysis/types/removenode" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/network" "github.com/iotaledger/hive.go/network/tcp" "github.com/iotaledger/hive.go/node" + + "github.com/iotaledger/goshimmer/packages/shutdown" + "github.com/iotaledger/goshimmer/plugins/analysis/types/addnode" + "github.com/iotaledger/goshimmer/plugins/analysis/types/connectnodes" + "github.com/iotaledger/goshimmer/plugins/analysis/types/disconnectnodes" + "github.com/iotaledger/goshimmer/plugins/analysis/types/ping" + "github.com/iotaledger/goshimmer/plugins/analysis/types/removenode" + "github.com/iotaledger/goshimmer/plugins/config" ) var ( @@ -36,7 +37,7 @@ func Configure(plugin *node.Plugin) { log.Errorf("error in server: %s", err.Error()) })) server.Events.Start.Attach(events.NewClosure(func() { - log.Infof("Starting Server (port %d) ... done", parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) + log.Infof("Starting Server (port %d) ... done", config.NodeConfig.GetInt(CFG_SERVER_PORT)) })) server.Events.Shutdown.Attach(events.NewClosure(func() { log.Info("Stopping Server ... done") @@ -45,8 +46,8 @@ func Configure(plugin *node.Plugin) { func Run(plugin *node.Plugin) { daemon.BackgroundWorker("Analysis Server", func(shutdownSignal <-chan struct{}) { - log.Infof("Starting Server (port %d) ... done", parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) - go server.Listen("0.0.0.0", parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) + log.Infof("Starting Server (port %d) ... done", config.NodeConfig.GetInt(CFG_SERVER_PORT)) + go server.Listen("0.0.0.0", config.NodeConfig.GetInt(CFG_SERVER_PORT)) <-shutdownSignal Shutdown() }, shutdown.ShutdownPriorityAnalysis) diff --git a/plugins/analysis/webinterface/httpserver/plugin.go b/plugins/analysis/webinterface/httpserver/plugin.go index dfc752a3ec08edaf39f619e49972fa294c6a8f1e..d063c3550ca24283287526902e2ae0a591328663 100644 --- a/plugins/analysis/webinterface/httpserver/plugin.go +++ b/plugins/analysis/webinterface/httpserver/plugin.go @@ -6,13 +6,14 @@ import ( "time" "github.com/gobuffalo/packr/v2" - "github.com/iotaledger/goshimmer/packages/parameter" - "github.com/iotaledger/goshimmer/packages/shutdown" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/logger" "github.com/labstack/echo" "golang.org/x/net/context" "golang.org/x/net/websocket" + + "github.com/iotaledger/goshimmer/packages/shutdown" + "github.com/iotaledger/goshimmer/plugins/config" ) var ( @@ -31,7 +32,7 @@ func Configure() { engine.HideBanner = true // we only need this special flag, because we always keep a packed box in the same directory - if parameter.NodeConfig.GetBool(CFG_DEV) { + if config.NodeConfig.GetBool(CFG_DEV) { engine.Static("/static", "./plugins/analysis/webinterface/httpserver/static") engine.File("/", "./plugins/analysis/webinterface/httpserver/static/index.html") } else { @@ -51,7 +52,7 @@ func Run() { func start(shutdownSignal <-chan struct{}) { stopped := make(chan struct{}) - bindAddr := parameter.NodeConfig.GetString(CFG_BIND_ADDRESS) + bindAddr := config.NodeConfig.GetString(CFG_BIND_ADDRESS) go func() { log.Infof("Started %s: http://%s", name, bindAddr) if err := engine.Start(bindAddr); err != nil { diff --git a/plugins/autopeering/autopeering.go b/plugins/autopeering/autopeering.go index 191d847156a40c63aebe74b487fc9b9df6c28901..c02b8bf87d18bd47a48d0555e073a99b0b340eed 100644 --- a/plugins/autopeering/autopeering.go +++ b/plugins/autopeering/autopeering.go @@ -7,11 +7,6 @@ import ( "net" "strings" - "github.com/iotaledger/goshimmer/packages/netutil" - "github.com/iotaledger/goshimmer/packages/parameter" - "github.com/iotaledger/goshimmer/plugins/autopeering/local" - "github.com/iotaledger/goshimmer/plugins/cli" - "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/hive.go/autopeering/discover" "github.com/iotaledger/hive.go/autopeering/peer" "github.com/iotaledger/hive.go/autopeering/peer/service" @@ -20,6 +15,12 @@ import ( "github.com/iotaledger/hive.go/autopeering/transport" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" + + "github.com/iotaledger/goshimmer/packages/netutil" + "github.com/iotaledger/goshimmer/plugins/autopeering/local" + "github.com/iotaledger/goshimmer/plugins/cli" + "github.com/iotaledger/goshimmer/plugins/config" + "github.com/iotaledger/goshimmer/plugins/gossip" ) var ( @@ -85,7 +86,7 @@ func start(shutdownSignal <-chan struct{}) { panic(err) } // resolve the bind address - address := net.JoinHostPort(parameter.NodeConfig.GetString(local.CFG_BIND), peeringPort) + address := net.JoinHostPort(config.NodeConfig.GetString(local.CFG_BIND), peeringPort) localAddr, err := net.ResolveUDPAddr(peeringAddr.Network(), address) if err != nil { log.Fatalf("Error resolving %s: %v", local.CFG_BIND, err) @@ -136,7 +137,7 @@ func start(shutdownSignal <-chan struct{}) { } func parseEntryNodes() (result []*peer.Peer, err error) { - for _, entryNodeDefinition := range parameter.NodeConfig.GetStringSlice(CFG_ENTRY_NODES) { + for _, entryNodeDefinition := range config.NodeConfig.GetStringSlice(CFG_ENTRY_NODES) { if entryNodeDefinition == "" { continue } diff --git a/plugins/autopeering/local/local.go b/plugins/autopeering/local/local.go index b6a89a75c6e7ae20bca23f747929af3c38343651..da050eac21e04edd9acd362936ee0a295909ded8 100644 --- a/plugins/autopeering/local/local.go +++ b/plugins/autopeering/local/local.go @@ -8,12 +8,13 @@ import ( "strings" "sync" - "github.com/iotaledger/goshimmer/packages/database" - "github.com/iotaledger/goshimmer/packages/netutil" - "github.com/iotaledger/goshimmer/packages/parameter" "github.com/iotaledger/hive.go/autopeering/peer" "github.com/iotaledger/hive.go/autopeering/peer/service" "github.com/iotaledger/hive.go/logger" + + "github.com/iotaledger/goshimmer/packages/database" + "github.com/iotaledger/goshimmer/packages/netutil" + "github.com/iotaledger/goshimmer/plugins/config" ) var ( @@ -25,7 +26,7 @@ func configureLocal() *peer.Local { log := logger.NewLogger("Local") var externalIP net.IP - if str := parameter.NodeConfig.GetString(CFG_EXTERNAL); strings.ToLower(str) == "auto" { + if str := config.NodeConfig.GetString(CFG_EXTERNAL); strings.ToLower(str) == "auto" { log.Info("Querying external IP ...") ip, err := netutil.GetPublicIP(false) if err != nil { @@ -43,7 +44,7 @@ func configureLocal() *peer.Local { log.Fatalf("IP is not a global unicast address: %s", externalIP.String()) } - peeringPort := strconv.Itoa(parameter.NodeConfig.GetInt(CFG_PORT)) + peeringPort := strconv.Itoa(config.NodeConfig.GetInt(CFG_PORT)) // announce the peering service services := service.New() @@ -55,7 +56,7 @@ func configureLocal() *peer.Local { // set the private key from the seed provided in the config var seed [][]byte - if str := parameter.NodeConfig.GetString(CFG_SEED); str != "" { + if str := config.NodeConfig.GetString(CFG_SEED); str != "" { bytes, err := base64.StdEncoding.DecodeString(str) if err != nil { log.Fatalf("Invalid %s: %s", CFG_SEED, err) diff --git a/plugins/cli/plugin.go b/plugins/cli/plugin.go index 8fbaeab0e65f804969aa69fc89ef4321ff7d47ac..47b250aeac45d31e0098d6fda4d3993d6552f091 100644 --- a/plugins/cli/plugin.go +++ b/plugins/cli/plugin.go @@ -3,9 +3,7 @@ package cli import ( "fmt" - "github.com/iotaledger/goshimmer/packages/parameter" "github.com/iotaledger/hive.go/events" - "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" flag "github.com/spf13/pflag" ) @@ -24,7 +22,6 @@ func onAddPlugin(name string, status int) { } func init() { - for name, status := range node.GetPlugins() { onAddPlugin(name, status) } @@ -34,26 +31,6 @@ func init() { flag.Usage = printUsage } -func parseParameters() { - for _, pluginName := range parameter.NodeConfig.GetStringSlice(node.CFG_DISABLE_PLUGINS) { - node.DisabledPlugins[node.GetPluginIdentifier(pluginName)] = true - } - for _, pluginName := range parameter.NodeConfig.GetStringSlice(node.CFG_ENABLE_PLUGINS) { - node.EnabledPlugins[node.GetPluginIdentifier(pluginName)] = true - } -} - -func LoadConfig() { - if err := parameter.FetchConfig(false); err != nil { - panic(err) - } - parseParameters() - - if err := logger.InitGlobalLogger(parameter.NodeConfig); err != nil { - panic(err) - } -} - func configure(ctx *node.Plugin) { fmt.Printf(` _____ ____ _____ _ _ _____ __ __ __ __ ______ _____ diff --git a/packages/parameter/parameter.go b/plugins/config/config.go similarity index 65% rename from packages/parameter/parameter.go rename to plugins/config/config.go index 7d390f1fb76675fdb95a58512c1b04544af5a4c5..5f507429000463fed592df15ceed04a858fc9866 100644 --- a/packages/parameter/parameter.go +++ b/plugins/config/config.go @@ -1,7 +1,8 @@ -package parameter +package config import ( "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/parameter" flag "github.com/spf13/pflag" "github.com/spf13/viper" @@ -30,13 +31,27 @@ func init() { // set the default logger config NodeConfig = viper.New() NodeConfig.SetDefault(logger.ViperKey, defaultLoggerConfig) + + if err := Fetch(false); err != nil { + panic(err) + } + parseParameters() +} + +func parseParameters() { + for _, pluginName := range NodeConfig.GetStringSlice(node.CFG_DISABLE_PLUGINS) { + node.DisabledPlugins[node.GetPluginIdentifier(pluginName)] = true + } + for _, pluginName := range NodeConfig.GetStringSlice(node.CFG_ENABLE_PLUGINS) { + node.EnabledPlugins[node.GetPluginIdentifier(pluginName)] = true + } } -// FetchConfig fetches config values from a dir defined via CLI flag --config-dir (or the current working dir if not set). +// Fetch fetches config values from a dir defined via CLI flag --config-dir (or the current working dir if not set). // // It automatically reads in a single config file starting with "config" (can be changed via the --config CLI flag) // and ending with: .json, .toml, .yaml or .yml (in this sequence). -func FetchConfig(printConfig bool, ignoreSettingsAtPrint ...[]string) error { +func Fetch(printConfig bool, ignoreSettingsAtPrint ...[]string) error { err := parameter.LoadConfigFile(NodeConfig, *configDirPath, *configName, true, false) if err != nil { return err @@ -47,18 +62,3 @@ func FetchConfig(printConfig bool, ignoreSettingsAtPrint ...[]string) error { } return nil } - -// LoadDefaultConfig only binds the flags, but does not load any config file. -func LoadDefaultConfig(printConfig bool) error { - // only bind the flags - flag.Parse() - err := NodeConfig.BindPFlags(flag.CommandLine) - if err != nil { - return err - } - - if printConfig { - parameter.PrintConfig(NodeConfig) - } - return nil -} diff --git a/plugins/config/plugin.go b/plugins/config/plugin.go new file mode 100644 index 0000000000000000000000000000000000000000..1dcccb490d38bd6a1a7e9d5a40ea2e76d1901d48 --- /dev/null +++ b/plugins/config/plugin.go @@ -0,0 +1,11 @@ +package config + +import ( + "github.com/iotaledger/hive.go/node" +) + +var PLUGIN = node.NewPlugin("Config", node.Enabled, run) + +func run(ctx *node.Plugin) { + // do nothing; everything is handled in the init method +} diff --git a/plugins/gossip/gossip.go b/plugins/gossip/gossip.go index 57f348d1ae6643ece99c63b4c6a219892ceddecb..3697608d0a732f7cd097834c08879ed9423a10e0 100644 --- a/plugins/gossip/gossip.go +++ b/plugins/gossip/gossip.go @@ -6,17 +6,17 @@ import ( "strconv" "sync" - "github.com/iotaledger/goshimmer/packages/binary/tangle/model/transaction" - "github.com/iotaledger/goshimmer/plugins/tangle" + "github.com/iotaledger/hive.go/autopeering/peer" + "github.com/iotaledger/hive.go/autopeering/peer/service" + "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/goshimmer/packages/binary/tangle/model/transaction" gp "github.com/iotaledger/goshimmer/packages/gossip" "github.com/iotaledger/goshimmer/packages/gossip/server" - "github.com/iotaledger/goshimmer/packages/parameter" "github.com/iotaledger/goshimmer/plugins/autopeering/local" "github.com/iotaledger/goshimmer/plugins/cli" - "github.com/iotaledger/hive.go/autopeering/peer" - "github.com/iotaledger/hive.go/autopeering/peer/service" - "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/goshimmer/plugins/config" + "github.com/iotaledger/goshimmer/plugins/tangle" ) var ( @@ -34,7 +34,7 @@ func configureGossip() { } // announce the gossip service - gossipPort := strconv.Itoa(parameter.NodeConfig.GetInt(GOSSIP_PORT)) + gossipPort := strconv.Itoa(config.NodeConfig.GetInt(GOSSIP_PORT)) err = lPeer.UpdateService(service.GossipKey, "tcp", net.JoinHostPort(external, gossipPort)) if err != nil { log.Fatalf("could not update services: %s", err) @@ -54,7 +54,7 @@ func start(shutdownSignal <-chan struct{}) { panic(err) } // resolve the bind address - address := net.JoinHostPort(parameter.NodeConfig.GetString(local.CFG_BIND), gossipPort) + address := net.JoinHostPort(config.NodeConfig.GetString(local.CFG_BIND), gossipPort) localAddr, err := net.ResolveTCPAddr(gossipAddr.Network(), address) if err != nil { log.Fatalf("Error resolving %s: %v", local.CFG_BIND, err) diff --git a/plugins/gossip/plugin.go b/plugins/gossip/plugin.go index 66a27e2214ade99614d19a9200c7aa438ba62b03..4b8bee220239a19ed7facdff06e2f4f311e430d5 100644 --- a/plugins/gossip/plugin.go +++ b/plugins/gossip/plugin.go @@ -1,17 +1,18 @@ package gossip import ( - "github.com/iotaledger/goshimmer/packages/binary/tangle/model/transaction" - "github.com/iotaledger/goshimmer/packages/binary/tangle/model/transactionmetadata" - "github.com/iotaledger/goshimmer/packages/gossip" - "github.com/iotaledger/goshimmer/packages/shutdown" - "github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/hive.go/autopeering/peer" "github.com/iotaledger/hive.go/autopeering/selection" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" + + "github.com/iotaledger/goshimmer/packages/binary/tangle/model/transaction" + "github.com/iotaledger/goshimmer/packages/binary/tangle/model/transactionmetadata" + "github.com/iotaledger/goshimmer/packages/gossip" + "github.com/iotaledger/goshimmer/packages/shutdown" + "github.com/iotaledger/goshimmer/plugins/tangle" ) const name = "Gossip" // name of the plugin diff --git a/plugins/graph/graph.go b/plugins/graph/graph.go index e0946cc3a2e8a5c38644cf6fb0e0cfe750bed436..d6b5bb79a304f0aa6602302038cfb4e14d8b96d6 100644 --- a/plugins/graph/graph.go +++ b/plugins/graph/graph.go @@ -7,10 +7,11 @@ import ( "strings" socketio "github.com/googollee/go-socket.io" - "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/parameter" "github.com/iotaledger/iota.go/consts" + "github.com/iotaledger/goshimmer/packages/model/value_transaction" + "github.com/iotaledger/goshimmer/plugins/config" + "github.com/iotaledger/hive.go/syncutils" ) @@ -66,7 +67,7 @@ func onConnectHandler(s socketio.Conn) error { log.Info(infoMsg) socketioServer.JoinRoom("broadcast", s) - config := &wsConfig{NetworkName: parameter.NodeConfig.GetString(CFG_NETWORK)} + config := &wsConfig{NetworkName: config.NodeConfig.GetString(CFG_NETWORK)} var initTxs []*wsTransaction txRingBuffer.Do(func(tx interface{}) { diff --git a/plugins/graph/plugin.go b/plugins/graph/plugin.go index 566ba82af9795f0105946848844898bf53dfe8f0..7c6cf5f0186fbd4b06a2d75a6e7b7818992093fd 100644 --- a/plugins/graph/plugin.go +++ b/plugins/graph/plugin.go @@ -5,12 +5,13 @@ import ( "net/http" "time" - "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/parameter" - "github.com/iotaledger/goshimmer/packages/shutdown" + "github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/goshimmer/plugins/tangle_old" "golang.org/x/net/context" + "github.com/iotaledger/goshimmer/packages/model/value_transaction" + "github.com/iotaledger/goshimmer/packages/shutdown" + engineio "github.com/googollee/go-engine.io" "github.com/googollee/go-engine.io/transport" "github.com/googollee/go-engine.io/transport/polling" @@ -39,7 +40,7 @@ var ( ) func downloadSocketIOHandler(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, parameter.NodeConfig.GetString(CFG_SOCKET_IO)) + http.ServeFile(w, r, config.NodeConfig.GetString(CFG_SOCKET_IO)) } func configureSocketIOServer() error { @@ -72,11 +73,11 @@ func configure(plugin *node.Plugin) { // socket.io and web server server = &http.Server{ - Addr: parameter.NodeConfig.GetString(CFG_BIND_ADDRESS), + Addr: config.NodeConfig.GetString(CFG_BIND_ADDRESS), Handler: router, } - fs := http.FileServer(http.Dir(parameter.NodeConfig.GetString(CFG_WEBROOT))) + fs := http.FileServer(http.Dir(config.NodeConfig.GetString(CFG_WEBROOT))) if err := configureSocketIOServer(); err != nil { log.Panicf("Graph: %v", err.Error()) @@ -113,7 +114,7 @@ func run(*node.Plugin) { stopped := make(chan struct{}) go func() { - log.Infof("You can now access IOTA Tangle Visualiser using: http://%s", parameter.NodeConfig.GetString(CFG_BIND_ADDRESS)) + log.Infof("You can now access IOTA Tangle Visualiser using: http://%s", config.NodeConfig.GetString(CFG_BIND_ADDRESS)) if err := server.ListenAndServe(); err != nil { if !errors.Is(err, http.ErrServerClosed) { log.Errorf("Error serving: %s", err) diff --git a/plugins/logger/logger.go b/plugins/logger/logger.go new file mode 100644 index 0000000000000000000000000000000000000000..100f2de7b7a734b0659dd32dbe6930dbf51a76dd --- /dev/null +++ b/plugins/logger/logger.go @@ -0,0 +1,13 @@ +package logger + +import ( + "github.com/iotaledger/hive.go/logger" + + "github.com/iotaledger/goshimmer/plugins/config" +) + +func init() { + if err := logger.InitGlobalLogger(config.NodeConfig); err != nil { + panic(err) + } +} diff --git a/plugins/logger/plugin.go b/plugins/logger/plugin.go new file mode 100644 index 0000000000000000000000000000000000000000..8dde32211cf93d76be36538bff0776bd09bc59c0 --- /dev/null +++ b/plugins/logger/plugin.go @@ -0,0 +1,11 @@ +package logger + +import ( + "github.com/iotaledger/hive.go/node" +) + +var PLUGIN = node.NewPlugin("Logger", node.Enabled, run) + +func run(ctx *node.Plugin) { + // do nothing; everything is handled in the init method +} diff --git a/plugins/remotelog/plugin.go b/plugins/remotelog/plugin.go index 0ca02c50ccab9b757253fa5613be8c390bef8f62..f8556f094c4b622becd98858c1de4b4669b8e5cc 100644 --- a/plugins/remotelog/plugin.go +++ b/plugins/remotelog/plugin.go @@ -12,14 +12,15 @@ import ( "runtime" "time" - "github.com/iotaledger/goshimmer/packages/parameter" - "github.com/iotaledger/goshimmer/packages/shutdown" - "github.com/iotaledger/goshimmer/plugins/autopeering/local" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/workerpool" + + "github.com/iotaledger/goshimmer/packages/shutdown" + "github.com/iotaledger/goshimmer/plugins/autopeering/local" + "github.com/iotaledger/goshimmer/plugins/config" ) type logMessage struct { @@ -47,14 +48,14 @@ var ( func configure(plugin *node.Plugin) { log = logger.NewLogger(PLUGIN_NAME) - if parameter.NodeConfig.GetBool(CFG_DISABLE_EVENTS) { + if config.NodeConfig.GetBool(CFG_DISABLE_EVENTS) { log.Fatalf("%s in config.json needs to be false so that events can be captured!", CFG_DISABLE_EVENTS) return } - c, err := net.Dial("udp", parameter.NodeConfig.GetString(CFG_SERVER_ADDRESS)) + c, err := net.Dial("udp", config.NodeConfig.GetString(CFG_SERVER_ADDRESS)) if err != nil { - log.Fatalf("Could not create UDP socket to '%s'. %v", parameter.NodeConfig.GetString(CFG_SERVER_ADDRESS), err) + log.Fatalf("Could not create UDP socket to '%s'. %v", config.NodeConfig.GetString(CFG_SERVER_ADDRESS), err) return } conn = c diff --git a/plugins/spa/plugin.go b/plugins/spa/plugin.go index 7141a88fa65e2b309918853721940ede45174d35..aacc71b4adc44fca3fdd654dd988a0cf53c7ae70 100644 --- a/plugins/spa/plugin.go +++ b/plugins/spa/plugin.go @@ -7,16 +7,17 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/iotaledger/goshimmer/packages/parameter" + "github.com/iotaledger/hive.go/autopeering/peer/service" + "github.com/labstack/echo" + "github.com/labstack/echo/middleware" + "github.com/iotaledger/goshimmer/packages/shutdown" "github.com/iotaledger/goshimmer/plugins/autopeering" "github.com/iotaledger/goshimmer/plugins/autopeering/local" "github.com/iotaledger/goshimmer/plugins/cli" + "github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/goshimmer/plugins/metrics" - "github.com/iotaledger/hive.go/autopeering/peer/service" - "github.com/labstack/echo" - "github.com/labstack/echo/middleware" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" @@ -80,10 +81,10 @@ func run(plugin *node.Plugin) { e.HideBanner = true e.Use(middleware.Recover()) - if parameter.NodeConfig.GetBool(CFG_BASIC_AUTH_ENABLED) { + if config.NodeConfig.GetBool(CFG_BASIC_AUTH_ENABLED) { e.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) { - if username == parameter.NodeConfig.GetString(CFG_BASIC_AUTH_USERNAME) && - password == parameter.NodeConfig.GetString(CFG_BASIC_AUTH_PASSWORD) { + if username == config.NodeConfig.GetString(CFG_BASIC_AUTH_USERNAME) && + password == config.NodeConfig.GetString(CFG_BASIC_AUTH_PASSWORD) { return true, nil } return false, nil @@ -91,7 +92,7 @@ func run(plugin *node.Plugin) { } setupRoutes(e) - addr := parameter.NodeConfig.GetString(CFG_BIND_ADDRESS) + addr := config.NodeConfig.GetString(CFG_BIND_ADDRESS) log.Infof("You can now access the dashboard using: http://%s", addr) go e.Start(addr) diff --git a/plugins/spa/routes.go b/plugins/spa/routes.go index f7e2f24fb7ecafadf2434ec47f55f61ace60bb22..26d433570389d79335ff9276c3ebfe1469649257 100644 --- a/plugins/spa/routes.go +++ b/plugins/spa/routes.go @@ -7,10 +7,9 @@ import ( "time" "github.com/gobuffalo/packr/v2" - "github.com/iotaledger/goshimmer/packages/parameter" + "github.com/iotaledger/goshimmer/plugins/config" "github.com/labstack/echo" "github.com/pkg/errors" - ) var ErrInvalidParameter = errors.New("invalid parameter") @@ -23,7 +22,7 @@ var appBox = packr.New("SPA_App", "./frontend/build") var assetsBox = packr.New("SPA_Assets", "./frontend/src/assets") func indexRoute(e echo.Context) error { - if parameter.NodeConfig.GetBool(CFG_DEV) { + if config.NodeConfig.GetBool(CFG_DEV) { res, err := http.Get("http://127.0.0.1:9090/") if err != nil { return err @@ -43,7 +42,7 @@ func indexRoute(e echo.Context) error { func setupRoutes(e *echo.Echo) { - if parameter.NodeConfig.GetBool("dashboard.dev") { + if config.NodeConfig.GetBool("dashboard.dev") { e.Static("/assets", "./plugins/spa/frontend/src/assets") } else { diff --git a/plugins/webapi/plugin.go b/plugins/webapi/plugin.go index 79365c8727fa71c9c031c3228c5af22e505567c9..4aa38f994cfae34dd59b277d3cf7ceff64bc2600 100644 --- a/plugins/webapi/plugin.go +++ b/plugins/webapi/plugin.go @@ -4,12 +4,13 @@ import ( "context" "time" - "github.com/iotaledger/goshimmer/packages/parameter" - "github.com/iotaledger/goshimmer/packages/shutdown" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" "github.com/labstack/echo" + + "github.com/iotaledger/goshimmer/packages/shutdown" + "github.com/iotaledger/goshimmer/plugins/config" ) var PLUGIN = node.NewPlugin("WebAPI", node.Enabled, configure, run) @@ -31,7 +32,7 @@ func run(plugin *node.Plugin) { log.Info("Starting Web Server ... done") go func() { - if err := Server.Start(parameter.NodeConfig.GetString(BIND_ADDRESS)); err != nil { + if err := Server.Start(config.NodeConfig.GetString(BIND_ADDRESS)); err != nil { log.Info("Stopping Web Server ... done") } }() diff --git a/plugins/webauth/webauth.go b/plugins/webauth/webauth.go index 21e943fa9f10518118227f65c3e584c622df1af8..2b1ac806649eabbd74bd330d3be8fd3df4319dfc 100644 --- a/plugins/webauth/webauth.go +++ b/plugins/webauth/webauth.go @@ -5,13 +5,14 @@ import ( "strings" "time" - "github.com/iotaledger/goshimmer/packages/parameter" - "github.com/iotaledger/goshimmer/plugins/webapi" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" "github.com/labstack/echo" "github.com/labstack/echo/middleware" + "github.com/iotaledger/goshimmer/plugins/config" + "github.com/iotaledger/goshimmer/plugins/webapi" + "github.com/dgrijalva/jwt-go" ) @@ -21,7 +22,7 @@ var privateKey string func configure(plugin *node.Plugin) { log = logger.NewLogger("WebAPI Auth") - privateKey = parameter.NodeConfig.GetString(WEBAPI_AUTH_PRIVATE_KEY) + privateKey = config.NodeConfig.GetString(WEBAPI_AUTH_PRIVATE_KEY) if len(privateKey) == 0 { panic("") } @@ -55,8 +56,8 @@ func Handler(c echo.Context) error { return echo.ErrBadRequest } - if login.Username != parameter.NodeConfig.GetString(WEBAPI_AUTH_USERNAME) || - login.Password != parameter.NodeConfig.GetString(WEBAPI_AUTH_PASSWORD) { + if login.Username != config.NodeConfig.GetString(WEBAPI_AUTH_USERNAME) || + login.Password != config.NodeConfig.GetString(WEBAPI_AUTH_PASSWORD) { return echo.ErrUnauthorized } diff --git a/tools/relay-checker/config.go b/tools/relay-checker/config.go index 6833f365dd0c59933def5969c74492dcf1c49f74..3f62164bb1cc742fe2c53ed8a6e47f4cc4e7ae90 100644 --- a/tools/relay-checker/config.go +++ b/tools/relay-checker/config.go @@ -1,8 +1,6 @@ package main -import ( - "github.com/iotaledger/goshimmer/packages/parameter" -) +import "github.com/iotaledger/goshimmer/plugins/config" var ( nodes []string @@ -14,33 +12,33 @@ var ( ) func LoadConfig() { - if err := parameter.FetchConfig(false); err != nil { + if err := config.Fetch(false); err != nil { panic(err) } } func SetConfig() { - if parameter.NodeConfig.GetString(CFG_TARGET_NODE) == "" { + if config.NodeConfig.GetString(CFG_TARGET_NODE) == "" { panic("Set the target node address\n") } - target = parameter.NodeConfig.GetString(CFG_TARGET_NODE) + target = config.NodeConfig.GetString(CFG_TARGET_NODE) - if len(parameter.NodeConfig.GetStringSlice(CFG_TEST_NODES)) == 0 { + if len(config.NodeConfig.GetStringSlice(CFG_TEST_NODES)) == 0 { panic("Set node addresses\n") } - nodes = append(nodes, parameter.NodeConfig.GetStringSlice(CFG_TEST_NODES)...) + nodes = append(nodes, config.NodeConfig.GetStringSlice(CFG_TEST_NODES)...) // optional settings - if parameter.NodeConfig.GetString(CFG_TX_ADDRESS) != "" { - txnAddr = parameter.NodeConfig.GetString(CFG_TX_ADDRESS) + if config.NodeConfig.GetString(CFG_TX_ADDRESS) != "" { + txnAddr = config.NodeConfig.GetString(CFG_TX_ADDRESS) } - if parameter.NodeConfig.GetString(CFG_DATA) != "" { - txnData = parameter.NodeConfig.GetString(CFG_DATA) + if config.NodeConfig.GetString(CFG_DATA) != "" { + txnData = config.NodeConfig.GetString(CFG_DATA) } - if parameter.NodeConfig.GetInt(CFG_COOLDOWN_TIME) > 0 { - cooldownTime = parameter.NodeConfig.GetInt(CFG_COOLDOWN_TIME) + if config.NodeConfig.GetInt(CFG_COOLDOWN_TIME) > 0 { + cooldownTime = config.NodeConfig.GetInt(CFG_COOLDOWN_TIME) } - if parameter.NodeConfig.GetInt(CFG_REPEAT) > 0 { - repeat = parameter.NodeConfig.GetInt(CFG_REPEAT) + if config.NodeConfig.GetInt(CFG_REPEAT) > 0 { + repeat = config.NodeConfig.GetInt(CFG_REPEAT) } }