From aa210a5439c2aa56912948bca9526533cab6628c Mon Sep 17 00:00:00 2001 From: Luca Moser <moser.luca@gmail.com> Date: Sat, 16 Nov 2019 19:58:30 +0100 Subject: [PATCH] replaces logger, node and daemon package with the ones from hive.go --- go.mod | 2 +- go.sum | 10 ++ main.go | 2 +- packages/daemon/daemon.go | 123 ------------- packages/daemon/events.go | 13 -- packages/daemon/types.go | 3 - packages/node/constants.go | 9 - packages/node/events.go | 14 -- packages/node/logger.go | 59 ------- packages/node/node.go | 166 ------------------ packages/node/parameters.go | 17 -- packages/node/plugin.go | 75 -------- packages/node/types.go | 3 - packages/timeutil/sleep.go | 2 +- packages/timeutil/ticker.go | 2 +- .../transactionspammer/transactionspammer.go | 2 +- plugins/analysis/client/plugin.go | 9 +- plugins/analysis/plugin.go | 10 +- plugins/analysis/server/plugin.go | 18 +- .../webinterface/httpserver/plugin.go | 4 +- plugins/analysis/webinterface/plugin.go | 2 +- .../recordedevents/recorded_events.go | 2 +- .../instances/acceptedneighbors/plugin.go | 2 +- .../instances/chosenneighbors/plugin.go | 2 +- .../instances/entrynodes/instance.go | 2 +- .../instances/knownpeers/instance.go | 2 +- .../instances/neighborhood/instance.go | 4 +- .../instances/outgoingrequest/instance.go | 2 +- .../autopeering/instances/ownpeer/instance.go | 2 +- plugins/autopeering/instances/plugin.go | 2 +- .../autopeering/peerstorage/peerstorage.go | 10 +- plugins/autopeering/plugin.go | 22 ++- .../protocol/accepted_neighbor_dropper.go | 4 +- .../protocol/chosen_neighbor_dropper.go | 4 +- plugins/autopeering/protocol/error_handler.go | 4 +- .../protocol/incoming_drop_processor.go | 4 +- .../protocol/incoming_ping_processor.go | 4 +- .../protocol/incoming_request_processor.go | 12 +- .../protocol/incoming_response_processor.go | 4 +- .../protocol/outgoing_ping_processor.go | 16 +- .../protocol/outgoing_request_processor.go | 16 +- plugins/autopeering/protocol/plugin.go | 7 +- .../autopeering/saltmanager/saltmanager.go | 4 +- plugins/autopeering/server/server.go | 2 +- plugins/autopeering/server/tcp/server.go | 24 +-- plugins/autopeering/server/udp/server.go | 26 +-- .../bundleprocessor/bundleprocessor_test.go | 2 +- plugins/bundleprocessor/plugin.go | 28 ++- plugins/cli/cli.go | 2 +- plugins/cli/plugin.go | 7 +- plugins/dashboard/plugin.go | 8 +- plugins/gossip-on-solidification/plugin.go | 2 +- plugins/gossip/neighbors.go | 16 +- plugins/gossip/plugin.go | 4 +- plugins/gossip/send_queue.go | 12 +- plugins/gossip/server.go | 18 +- plugins/gracefulshutdown/plugin.go | 15 +- plugins/metrics/plugin.go | 6 +- plugins/statusscreen-tps/plugin.go | 4 +- plugins/statusscreen/logger.go | 31 +--- plugins/statusscreen/status_message.go | 3 +- plugins/statusscreen/statusscreen.go | 20 ++- plugins/statusscreen/ui_log_entry.go | 20 ++- plugins/tangle/approvers.go | 2 +- plugins/tangle/bundle.go | 2 +- plugins/tangle/plugin.go | 4 +- plugins/tangle/solidifier.go | 26 ++- plugins/tangle/solidifier_test.go | 2 +- plugins/tangle/transaction.go | 2 +- plugins/tangle/transaction_metadata.go | 2 +- plugins/tipselection/plugin.go | 2 +- plugins/ui/logger.go | 41 ++--- plugins/ui/ui.go | 12 +- plugins/validator/plugin.go | 12 +- plugins/webapi-gtta/plugin.go | 2 +- plugins/webapi-spammer/plugin.go | 2 +- plugins/webapi/plugin.go | 16 +- plugins/webauth/webauth.go | 4 +- plugins/zeromq/plugin.go | 23 +-- 79 files changed, 306 insertions(+), 774 deletions(-) delete mode 100644 packages/daemon/daemon.go delete mode 100644 packages/daemon/events.go delete mode 100644 packages/daemon/types.go delete mode 100644 packages/node/constants.go delete mode 100644 packages/node/events.go delete mode 100644 packages/node/logger.go delete mode 100644 packages/node/node.go delete mode 100644 packages/node/parameters.go delete mode 100644 packages/node/plugin.go delete mode 100644 packages/node/types.go diff --git a/go.mod b/go.mod index c2ee7f4c..4778b1a3 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/golang/protobuf v1.3.2 // indirect github.com/google/open-location-code/go v0.0.0-20190903173953-119bc96a3a51 github.com/gorilla/websocket v1.4.1 - github.com/iotaledger/hive.go v0.0.0-20191113184748-b545de9170d9 + github.com/iotaledger/hive.go v0.0.0-20191116130349-b8be71b827be github.com/iotaledger/iota.go v1.0.0-beta.9 github.com/labstack/echo v3.3.10+incompatible github.com/labstack/gommon v0.3.0 // indirect diff --git a/go.sum b/go.sum index f9244b0a..25c48c4c 100644 --- a/go.sum +++ b/go.sum @@ -80,6 +80,16 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/iotaledger/hive.go v0.0.0-20191113184748-b545de9170d9 h1:zlolyGALm324vLK6zJuw9cNp/XoNqsxqqx4jzHgoaFU= github.com/iotaledger/hive.go v0.0.0-20191113184748-b545de9170d9/go.mod h1:Ks2y/bEyfvb7nUA7l69a+8Epsv16UlGev0BvxggHius= +github.com/iotaledger/hive.go v0.0.0-20191115085829-f860e155ac2a h1:TNEDXmA66NE+0DdAtErNuOu/aep6YlYTqbDACiM4aQc= +github.com/iotaledger/hive.go v0.0.0-20191115085829-f860e155ac2a/go.mod h1:Ks2y/bEyfvb7nUA7l69a+8Epsv16UlGev0BvxggHius= +github.com/iotaledger/hive.go v0.0.0-20191115132232-9512db691c82 h1:J954SXMQS7Z6gnd/z/AFckKEZ+yLscsvMIbwsm9fnjQ= +github.com/iotaledger/hive.go v0.0.0-20191115132232-9512db691c82/go.mod h1:Ks2y/bEyfvb7nUA7l69a+8Epsv16UlGev0BvxggHius= +github.com/iotaledger/hive.go v0.0.0-20191115132634-8a8861c2801f h1:QPkMzHt4TBzZH7piaVz+eEFyV7CBXL/oSBc5lC0ijAE= +github.com/iotaledger/hive.go v0.0.0-20191115132634-8a8861c2801f/go.mod h1:Ks2y/bEyfvb7nUA7l69a+8Epsv16UlGev0BvxggHius= +github.com/iotaledger/hive.go v0.0.0-20191115134440-92f05839b6e0 h1:rHv9I8UNWO3u5QHY+IpxGLIoGKTChZAMSR/GwL3vWKo= +github.com/iotaledger/hive.go v0.0.0-20191115134440-92f05839b6e0/go.mod h1:Ks2y/bEyfvb7nUA7l69a+8Epsv16UlGev0BvxggHius= +github.com/iotaledger/hive.go v0.0.0-20191116130349-b8be71b827be h1:8aE2Pv9Z2db42CscDf78Yt/uHzHnkAOLmaXvzFqlX7o= +github.com/iotaledger/hive.go v0.0.0-20191116130349-b8be71b827be/go.mod h1:Ks2y/bEyfvb7nUA7l69a+8Epsv16UlGev0BvxggHius= github.com/iotaledger/iota.go v1.0.0-beta.9 h1:c654s9pkdhMBkABUvWg+6k91MEBbdtmZXP1xDfQpajg= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= diff --git a/main.go b/main.go index 8f742526..b43e2240 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/analysis" "github.com/iotaledger/goshimmer/plugins/autopeering" "github.com/iotaledger/goshimmer/plugins/bundleprocessor" @@ -21,6 +20,7 @@ import ( webapi_spammer "github.com/iotaledger/goshimmer/plugins/webapi-spammer" "github.com/iotaledger/goshimmer/plugins/webauth" "github.com/iotaledger/goshimmer/plugins/zeromq" + "github.com/iotaledger/hive.go/node" ) func main() { diff --git a/packages/daemon/daemon.go b/packages/daemon/daemon.go deleted file mode 100644 index 2e6aaadd..00000000 --- a/packages/daemon/daemon.go +++ /dev/null @@ -1,123 +0,0 @@ -package daemon - -import ( - "sync" -) - -var ( - running bool - wg sync.WaitGroup - ShutdownSignal = make(chan int, 1) - backgroundWorkers = make([]func(), 0) - backgroundWorkerNames = make([]string, 0) - runningBackgroundWorkers = make(map[string]bool) - lock = sync.Mutex{} -) - -func GetRunningBackgroundWorkers() []string { - lock.Lock() - - result := make([]string, 0) - for runningBackgroundWorker := range runningBackgroundWorkers { - result = append(result, runningBackgroundWorker) - } - - lock.Unlock() - - return result -} - -func runBackgroundWorker(name string, backgroundWorker func()) { - wg.Add(1) - - go func() { - lock.Lock() - runningBackgroundWorkers[name] = true - lock.Unlock() - - backgroundWorker() - - lock.Lock() - delete(runningBackgroundWorkers, name) - lock.Unlock() - - wg.Done() - }() -} - -func BackgroundWorker(name string, handler func()) { - lock.Lock() - - if IsRunning() { - runBackgroundWorker(name, handler) - } else { - backgroundWorkerNames = append(backgroundWorkerNames, name) - backgroundWorkers = append(backgroundWorkers, handler) - } - - lock.Unlock() -} - -func Start() { - if !running { - lock.Lock() - - if !running { - ShutdownSignal = make(chan int, 1) - - running = true - - Events.Run.Trigger() - - for i, backgroundWorker := range backgroundWorkers { - runBackgroundWorker(backgroundWorkerNames[i], backgroundWorker) - } - } - - lock.Unlock() - } -} - -func Run() { - Start() - - wg.Wait() -} - -func Shutdown() { - if running { - lock.Lock() - - if running { - close(ShutdownSignal) - - running = false - - Events.Shutdown.Trigger() - } - - lock.Unlock() - } -} - -func ShutdownAndWait() { - if running { - lock.Lock() - - if running { - close(ShutdownSignal) - - running = false - - Events.Shutdown.Trigger() - } - - lock.Unlock() - } - - wg.Wait() -} - -func IsRunning() bool { - return running -} diff --git a/packages/daemon/events.go b/packages/daemon/events.go deleted file mode 100644 index 256d4c43..00000000 --- a/packages/daemon/events.go +++ /dev/null @@ -1,13 +0,0 @@ -package daemon - -import ( - "github.com/iotaledger/hive.go/events" -) - -var Events = struct { - Run *events.Event - Shutdown *events.Event -}{ - Run: events.NewEvent(events.CallbackCaller), - Shutdown: events.NewEvent(events.CallbackCaller), -} diff --git a/packages/daemon/types.go b/packages/daemon/types.go deleted file mode 100644 index e87a1a75..00000000 --- a/packages/daemon/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package daemon - -type Callback = func() diff --git a/packages/node/constants.go b/packages/node/constants.go deleted file mode 100644 index 4e90679e..00000000 --- a/packages/node/constants.go +++ /dev/null @@ -1,9 +0,0 @@ -package node - -const ( - LOG_LEVEL_FAILURE = 0 - LOG_LEVEL_WARNING = 1 - LOG_LEVEL_SUCCESS = 2 - LOG_LEVEL_INFO = 3 - LOG_LEVEL_DEBUG = 4 -) diff --git a/packages/node/events.go b/packages/node/events.go deleted file mode 100644 index 820be882..00000000 --- a/packages/node/events.go +++ /dev/null @@ -1,14 +0,0 @@ -package node - -import ( - "github.com/iotaledger/hive.go/events" -) - -type pluginEvents struct { - Configure *events.Event - Run *events.Event -} - -func pluginCaller(handler interface{}, params ...interface{}) { - handler.(func(*Plugin))(params[0].(*Plugin)) -} diff --git a/packages/node/logger.go b/packages/node/logger.go deleted file mode 100644 index ded29108..00000000 --- a/packages/node/logger.go +++ /dev/null @@ -1,59 +0,0 @@ -package node - -import ( - "fmt" - "sync" -) - -type Logger struct { - enabled bool - enabledMutex sync.RWMutex - LogInfo func(pluginName string, message string) - LogSuccess func(pluginName string, message string) - LogWarning func(pluginName string, message string) - LogFailure func(pluginName string, message string) - LogDebug func(pluginName string, message string) -} - -func (logger *Logger) SetEnabled(value bool) { - logger.enabledMutex.Lock() - logger.enabled = value - logger.enabledMutex.Unlock() -} - -func (logger *Logger) GetEnabled() (result bool) { - logger.enabledMutex.RLock() - result = logger.enabled - logger.enabledMutex.RUnlock() - return -} - -func pluginPrefix(pluginName string) string { - var pluginPrefix string - if pluginName == "Node" { - pluginPrefix = "" - } else { - pluginPrefix = pluginName + ": " - } - - return pluginPrefix -} - -var DEFAULT_LOGGER = &Logger{ - enabled: true, - LogSuccess: func(pluginName string, message string) { - fmt.Println("[ OK ] " + pluginPrefix(pluginName) + message) - }, - LogInfo: func(pluginName string, message string) { - fmt.Println("[ INFO ] " + pluginPrefix(pluginName) + message) - }, - LogWarning: func(pluginName string, message string) { - fmt.Println("[ WARN ] " + pluginPrefix(pluginName) + message) - }, - LogFailure: func(pluginName string, message string) { - fmt.Println("[ FAIL ] " + pluginPrefix(pluginName) + message) - }, - LogDebug: func(pluginName string, message string) { - fmt.Println("[ NOTE ] " + pluginPrefix(pluginName) + message) - }, -} diff --git a/packages/node/node.go b/packages/node/node.go deleted file mode 100644 index af82862d..00000000 --- a/packages/node/node.go +++ /dev/null @@ -1,166 +0,0 @@ -package node - -import ( - "sync" - - "github.com/iotaledger/hive.go/parameter" - - "github.com/iotaledger/goshimmer/packages/daemon" -) - -type Node struct { - wg *sync.WaitGroup - loggers []*Logger - loadedPlugins []*Plugin -} - -var DisabledPlugins = make(map[string]bool) -var EnabledPlugins = make(map[string]bool) - -func New(plugins ...*Plugin) *Node { - node := &Node{ - loggers: make([]*Logger, 0), - wg: &sync.WaitGroup{}, - loadedPlugins: make([]*Plugin, 0), - } - - node.AddLogger(DEFAULT_LOGGER) - - // configure the enabled plugins - node.configure(plugins...) - - return node -} - -func Start(plugins ...*Plugin) *Node { - node := New(plugins...) - node.Start() - - return node -} - -func Run(plugins ...*Plugin) *Node { - node := New(plugins...) - node.Run() - - return node -} - -func Shutdown() { - daemon.ShutdownAndWait() -} - -func (node *Node) AddLogger(logger *Logger) { - node.loggers = append(node.loggers, logger) -} - -func (node *Node) LogSuccess(pluginName string, message string) { - if parameter.NodeConfig.GetInt(CFG_LOG_LEVEL) >= LOG_LEVEL_SUCCESS { - for _, logger := range node.loggers { - if logger.GetEnabled() { - logger.LogSuccess(pluginName, message) - } - } - } -} - -func (node *Node) LogInfo(pluginName string, message string) { - if parameter.NodeConfig.GetInt(CFG_LOG_LEVEL) >= LOG_LEVEL_INFO { - for _, logger := range node.loggers { - if logger.GetEnabled() { - logger.LogInfo(pluginName, message) - } - } - } -} - -func (node *Node) LogDebug(pluginName string, message string) { - if parameter.NodeConfig.GetInt(CFG_LOG_LEVEL) >= LOG_LEVEL_DEBUG { - for _, logger := range node.loggers { - if logger.GetEnabled() { - logger.LogDebug(pluginName, message) - } - } - } -} - -func (node *Node) LogWarning(pluginName string, message string) { - if parameter.NodeConfig.GetInt(CFG_LOG_LEVEL) >= LOG_LEVEL_WARNING { - for _, logger := range node.loggers { - if logger.GetEnabled() { - logger.LogWarning(pluginName, message) - } - } - } -} - -func (node *Node) LogFailure(pluginName string, message string) { - if parameter.NodeConfig.GetInt(CFG_LOG_LEVEL) >= LOG_LEVEL_FAILURE { - for _, logger := range node.loggers { - if logger.GetEnabled() { - logger.LogFailure(pluginName, message) - } - } - } -} - -func isDisabled(plugin *Plugin) bool { - _, exists := DisabledPlugins[GetPluginIdentifier(plugin.Name)] - - return exists -} - -func isEnabled(plugin *Plugin) bool { - _, exists := EnabledPlugins[GetPluginIdentifier(plugin.Name)] - - return exists -} - -func (node *Node) configure(plugins ...*Plugin) { - for _, plugin := range plugins { - 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") - } else { - node.LogInfo("Node", "Skipping Plugin: "+plugin.Name) - } - } -} - -func (node *Node) Start() { - node.LogInfo("Node", "Executing plugins ...") - - for _, plugin := range node.loadedPlugins { - plugin.Events.Run.Trigger(plugin) - - node.LogSuccess("Node", "Starting Plugin: "+plugin.Name+" ... done") - } - - node.LogSuccess("Node", "Starting background workers ...") - - daemon.Start() -} - -func (node *Node) Run() { - node.LogInfo("Node", "Executing plugins ...") - - for _, plugin := range node.loadedPlugins { - plugin.Events.Run.Trigger(plugin) - - node.LogSuccess("Node", "Starting Plugin: "+plugin.Name+" ... done") - } - - node.LogSuccess("Node", "Starting background workers ...") - - daemon.Run() - - node.LogSuccess("Node", "Shutdown complete!") -} diff --git a/packages/node/parameters.go b/packages/node/parameters.go deleted file mode 100644 index 78862fea..00000000 --- a/packages/node/parameters.go +++ /dev/null @@ -1,17 +0,0 @@ -package node - -import ( - flag "github.com/spf13/pflag" -) - -const ( - CFG_LOG_LEVEL = "node.logLevel" - CFG_DISABLE_PLUGINS = "node.disablePlugins" - CFG_ENABLE_PLGUINS = "node.enablePlugins" -) - -func init() { - flag.Int(CFG_LOG_LEVEL, LOG_LEVEL_INFO, "controls the log types that are shown") - flag.String(CFG_DISABLE_PLUGINS, "", "a list of plugins that shall be disabled") - flag.String(CFG_ENABLE_PLGUINS, "", "a list of plugins that shall be enabled") -} diff --git a/packages/node/plugin.go b/packages/node/plugin.go deleted file mode 100644 index 7a937e99..00000000 --- a/packages/node/plugin.go +++ /dev/null @@ -1,75 +0,0 @@ -package node - -import ( - "strings" - "sync" - - "github.com/iotaledger/hive.go/events" - "github.com/iotaledger/hive.go/parameter" -) - -const ( - Disabled = iota - Enabled -) - -type Plugin struct { - Node *Node - Name string - Status int - Events pluginEvents - wg *sync.WaitGroup -} - -// Creates a new plugin with the given name, default status and callbacks. -// The last specified callback is the mandatory run callback, while all other callbacks are configure callbacks. -func NewPlugin(name string, status int, callback Callback, callbacks ...Callback) *Plugin { - plugin := &Plugin{ - Name: name, - Status: status, - Events: pluginEvents{ - Configure: events.NewEvent(pluginCaller), - Run: events.NewEvent(pluginCaller), - }, - } - - // make the plugin known to the parameters - parameter.AddPlugin(name, status) - - if len(callbacks) >= 1 { - plugin.Events.Configure.Attach(events.NewClosure(callback)) - for _, callback = range callbacks[:len(callbacks)-1] { - plugin.Events.Configure.Attach(events.NewClosure(callback)) - } - - plugin.Events.Run.Attach(events.NewClosure(callbacks[len(callbacks)-1])) - } else { - plugin.Events.Run.Attach(events.NewClosure(callback)) - } - - return plugin -} - -func GetPluginIdentifier(name string) string { - return strings.ToLower(strings.Replace(name, " ", "", -1)) -} - -func (plugin *Plugin) LogSuccess(message string) { - plugin.Node.LogSuccess(plugin.Name, message) -} - -func (plugin *Plugin) LogInfo(message string) { - plugin.Node.LogInfo(plugin.Name, message) -} - -func (plugin *Plugin) LogWarning(message string) { - plugin.Node.LogWarning(plugin.Name, message) -} - -func (plugin *Plugin) LogFailure(message string) { - plugin.Node.LogFailure(plugin.Name, message) -} - -func (plugin *Plugin) LogDebug(message string) { - plugin.Node.LogDebug(plugin.Name, message) -} diff --git a/packages/node/types.go b/packages/node/types.go deleted file mode 100644 index fff6b603..00000000 --- a/packages/node/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package node - -type Callback = func(plugin *Plugin) diff --git a/packages/timeutil/sleep.go b/packages/timeutil/sleep.go index 0f2577f2..448c54d0 100644 --- a/packages/timeutil/sleep.go +++ b/packages/timeutil/sleep.go @@ -3,7 +3,7 @@ package timeutil import ( "time" - "github.com/iotaledger/goshimmer/packages/daemon" + "github.com/iotaledger/hive.go/daemon" ) func Sleep(interval time.Duration) bool { diff --git a/packages/timeutil/ticker.go b/packages/timeutil/ticker.go index eb076521..7530cd09 100644 --- a/packages/timeutil/ticker.go +++ b/packages/timeutil/ticker.go @@ -3,7 +3,7 @@ package timeutil import ( "time" - "github.com/iotaledger/goshimmer/packages/daemon" + "github.com/iotaledger/hive.go/daemon" ) func Ticker(handler func(), interval time.Duration) { diff --git a/packages/transactionspammer/transactionspammer.go b/packages/transactionspammer/transactionspammer.go index 936519f9..ac1834f6 100644 --- a/packages/transactionspammer/transactionspammer.go +++ b/packages/transactionspammer/transactionspammer.go @@ -6,9 +6,9 @@ import ( "github.com/iotaledger/goshimmer/plugins/gossip" - "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/plugins/tipselection" + "github.com/iotaledger/hive.go/daemon" ) var spamming = false diff --git a/plugins/analysis/client/plugin.go b/plugins/analysis/client/plugin.go index fc882b05..0fe91709 100644 --- a/plugins/analysis/client/plugin.go +++ b/plugins/analysis/client/plugin.go @@ -1,14 +1,13 @@ package client import ( + "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/parameter" "net" "time" "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/network" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/timeutil" "github.com/iotaledger/goshimmer/plugins/analysis/types/addnode" "github.com/iotaledger/goshimmer/plugins/analysis/types/connectnodes" @@ -18,9 +17,13 @@ import ( "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) +var log = logger.NewLogger("Analysis-Client") + func Run(plugin *node.Plugin) { daemon.BackgroundWorker("Analysis Client", func() { shuttingDown := false @@ -32,7 +35,7 @@ func Run(plugin *node.Plugin) { default: if conn, err := net.Dial("tcp", parameter.NodeConfig.GetString(CFG_SERVER_ADDRESS)); err != nil { - plugin.LogDebug("Could not connect to reporting server: " + err.Error()) + log.Debugf("Could not connect to reporting server: %s", err.Error()) timeutil.Sleep(1 * time.Second) } else { diff --git a/plugins/analysis/plugin.go b/plugins/analysis/plugin.go index 4756341b..7721f971 100644 --- a/plugins/analysis/plugin.go +++ b/plugins/analysis/plugin.go @@ -1,16 +1,18 @@ package analysis import ( - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/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/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/parameter" ) var PLUGIN = node.NewPlugin("Analysis", node.Enabled, configure, run) +var log = logger.NewLogger("Analysis") func configure(plugin *node.Plugin) { if parameter.NodeConfig.GetInt(server.CFG_SERVER_PORT) != 0 { @@ -28,12 +30,12 @@ func run(plugin *node.Plugin) { webinterface.Run(plugin) server.Run(plugin) } else { - plugin.Node.LogSuccess("Node", "Starting Plugin: Analysis ... server is disabled (server-port is 0)") + log.Info("Starting Plugin: Analysis ... server is disabled (server-port is 0)") } if parameter.NodeConfig.GetString(client.CFG_SERVER_ADDRESS) != "" { client.Run(plugin) } else { - plugin.Node.LogSuccess("Node", "Starting Plugin: Analysis ... client is disabled (server-address is empty)") + log.Info("Starting Plugin: Analysis ... client is disabled (server-address is empty)") } } diff --git a/plugins/analysis/server/plugin.go b/plugins/analysis/server/plugin.go index 35917d4e..517a3df1 100644 --- a/plugins/analysis/server/plugin.go +++ b/plugins/analysis/server/plugin.go @@ -2,16 +2,17 @@ package server import ( "encoding/hex" - "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/network" "github.com/iotaledger/goshimmer/packages/network/tcp" - "github.com/iotaledger/goshimmer/packages/node" "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/node" "github.com/iotaledger/hive.go/parameter" "github.com/pkg/errors" "math" @@ -19,31 +20,32 @@ import ( var server *tcp.Server +var log = logger.NewLogger("Analysis-Server") + func Configure(plugin *node.Plugin) { server = tcp.NewServer() server.Events.Connect.Attach(events.NewClosure(HandleConnection)) server.Events.Error.Attach(events.NewClosure(func(err error) { - plugin.LogFailure("error in server: " + err.Error()) + log.Error("error in server: %s", err.Error()) })) server.Events.Start.Attach(events.NewClosure(func() { - plugin.LogSuccess("Starting Server (port " + string(parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) + ") ... done") + log.Infof("Starting Server (port %d) ... done", parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) })) server.Events.Shutdown.Attach(events.NewClosure(func() { - plugin.LogSuccess("Stopping Server ... done") + log.Info("Stopping Server ... done") })) } func Run(plugin *node.Plugin) { daemon.BackgroundWorker("Analysis Server", func() { - plugin.LogInfo("Starting Server (port " + string(parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) + ") ...") - + log.Infof("Starting Server (port %d) ... done", parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) server.Listen(parameter.NodeConfig.GetInt(CFG_SERVER_PORT)) }) } func Shutdown(plugin *node.Plugin) { - plugin.LogInfo("Stopping Server ...") + log.Info("Stopping Server ...") server.Shutdown() } diff --git a/plugins/analysis/webinterface/httpserver/plugin.go b/plugins/analysis/webinterface/httpserver/plugin.go index a86fb7df..d02d449e 100644 --- a/plugins/analysis/webinterface/httpserver/plugin.go +++ b/plugins/analysis/webinterface/httpserver/plugin.go @@ -4,9 +4,9 @@ import ( "net/http" "time" - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" "golang.org/x/net/context" "golang.org/x/net/websocket" ) diff --git a/plugins/analysis/webinterface/plugin.go b/plugins/analysis/webinterface/plugin.go index 9719472c..f217dde6 100644 --- a/plugins/analysis/webinterface/plugin.go +++ b/plugins/analysis/webinterface/plugin.go @@ -1,9 +1,9 @@ package webinterface import ( - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/analysis/webinterface/httpserver" "github.com/iotaledger/goshimmer/plugins/analysis/webinterface/recordedevents" + "github.com/iotaledger/hive.go/node" ) func Configure(plugin *node.Plugin) { diff --git a/plugins/analysis/webinterface/recordedevents/recorded_events.go b/plugins/analysis/webinterface/recordedevents/recorded_events.go index 2a85fbc5..c31574b8 100644 --- a/plugins/analysis/webinterface/recordedevents/recorded_events.go +++ b/plugins/analysis/webinterface/recordedevents/recorded_events.go @@ -3,10 +3,10 @@ package recordedevents import ( "sync" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/analysis/server" "github.com/iotaledger/goshimmer/plugins/analysis/webinterface/types" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) var nodes = make(map[string]bool) diff --git a/plugins/autopeering/instances/acceptedneighbors/plugin.go b/plugins/autopeering/instances/acceptedneighbors/plugin.go index 9870c182..46f3eb31 100644 --- a/plugins/autopeering/instances/acceptedneighbors/plugin.go +++ b/plugins/autopeering/instances/acceptedneighbors/plugin.go @@ -1,6 +1,6 @@ package acceptedneighbors -import "github.com/iotaledger/goshimmer/packages/node" +import "github.com/iotaledger/hive.go/node" func Configure(plugin *node.Plugin) { configureOwnDistance() diff --git a/plugins/autopeering/instances/chosenneighbors/plugin.go b/plugins/autopeering/instances/chosenneighbors/plugin.go index 0e1224fc..7a33d35f 100644 --- a/plugins/autopeering/instances/chosenneighbors/plugin.go +++ b/plugins/autopeering/instances/chosenneighbors/plugin.go @@ -1,7 +1,7 @@ package chosenneighbors import ( - "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/node" ) func Configure(plugin *node.Plugin) { diff --git a/plugins/autopeering/instances/entrynodes/instance.go b/plugins/autopeering/instances/entrynodes/instance.go index aae083c6..ee6c2ad3 100644 --- a/plugins/autopeering/instances/entrynodes/instance.go +++ b/plugins/autopeering/instances/entrynodes/instance.go @@ -9,9 +9,9 @@ import ( "strings" "github.com/iotaledger/goshimmer/packages/identity" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerlist" + "github.com/iotaledger/hive.go/node" ) var INSTANCE *peerlist.PeerList diff --git a/plugins/autopeering/instances/knownpeers/instance.go b/plugins/autopeering/instances/knownpeers/instance.go index 1cf3c56d..91c12c96 100644 --- a/plugins/autopeering/instances/knownpeers/instance.go +++ b/plugins/autopeering/instances/knownpeers/instance.go @@ -1,9 +1,9 @@ package knownpeers import ( - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/entrynodes" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerregister" + "github.com/iotaledger/hive.go/node" ) var INSTANCE *peerregister.PeerRegister diff --git a/plugins/autopeering/instances/neighborhood/instance.go b/plugins/autopeering/instances/neighborhood/instance.go index 8c693d0f..7568b529 100644 --- a/plugins/autopeering/instances/neighborhood/instance.go +++ b/plugins/autopeering/instances/neighborhood/instance.go @@ -3,14 +3,14 @@ package neighborhood import ( "time" - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/timeutil" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/outgoingrequest" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerlist" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerregister" "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" + "github.com/iotaledger/hive.go/daemon" + "github.com/iotaledger/hive.go/node" ) var INSTANCE *peerregister.PeerRegister diff --git a/plugins/autopeering/instances/outgoingrequest/instance.go b/plugins/autopeering/instances/outgoingrequest/instance.go index 455e558e..238a6086 100644 --- a/plugins/autopeering/instances/outgoingrequest/instance.go +++ b/plugins/autopeering/instances/outgoingrequest/instance.go @@ -1,12 +1,12 @@ package outgoingrequest import ( - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" "github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager" "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) var INSTANCE *request.Request diff --git a/plugins/autopeering/instances/ownpeer/instance.go b/plugins/autopeering/instances/ownpeer/instance.go index 157a5f2d..fcd60e7e 100644 --- a/plugins/autopeering/instances/ownpeer/instance.go +++ b/plugins/autopeering/instances/ownpeer/instance.go @@ -5,11 +5,11 @@ import ( "net" "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/packages/node" autopeering_params "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" "github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" "github.com/iotaledger/goshimmer/plugins/gossip" + "github.com/iotaledger/hive.go/node" ) var INSTANCE *peer.Peer diff --git a/plugins/autopeering/instances/plugin.go b/plugins/autopeering/instances/plugin.go index ed02fdf6..c1f02da2 100644 --- a/plugins/autopeering/instances/plugin.go +++ b/plugins/autopeering/instances/plugin.go @@ -1,7 +1,6 @@ package instances import ( - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/entrynodes" @@ -9,6 +8,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/outgoingrequest" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" + "github.com/iotaledger/hive.go/node" ) func Configure(plugin *node.Plugin) { diff --git a/plugins/autopeering/peerstorage/peerstorage.go b/plugins/autopeering/peerstorage/peerstorage.go index b65f21ff..f886d076 100644 --- a/plugins/autopeering/peerstorage/peerstorage.go +++ b/plugins/autopeering/peerstorage/peerstorage.go @@ -2,18 +2,20 @@ package peerstorage import ( "bytes" - "strconv" + "github.com/iotaledger/hive.go/logger" "sync" "github.com/iotaledger/goshimmer/packages/database" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) const peerDbName string = "peers" +var log = logger.NewLogger("Autopeering-Peerstorage") + var peerDb database.Database var once sync.Once @@ -61,13 +63,13 @@ func loadPeers(plugin *node.Plugin) { knownpeers.INSTANCE.AddOrUpdate(peer) count++ - plugin.LogDebug("Added stored peer: " + peer.GetAddress().String() + " / " + peer.GetIdentity().StringIdentifier) + log.Debugf("Added stored peer: %s / %s", peer.GetAddress().String(), peer.GetIdentity().StringIdentifier) }) if err != nil { panic(err) } - plugin.LogSuccess("Restored " + strconv.Itoa(count) + " peers from database") + log.Infof("Restored %d peers from database", count) } func Configure(plugin *node.Plugin) { diff --git a/plugins/autopeering/plugin.go b/plugins/autopeering/plugin.go index 04c6a414..86b8a749 100644 --- a/plugins/autopeering/plugin.go +++ b/plugins/autopeering/plugin.go @@ -1,8 +1,6 @@ package autopeering import ( - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" @@ -13,10 +11,14 @@ import ( "github.com/iotaledger/goshimmer/plugins/autopeering/server" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" "github.com/iotaledger/goshimmer/plugins/gossip" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/hive.go/node" ) var PLUGIN = node.NewPlugin("Auto Peering", node.Enabled, configure, run) +var log = logger.NewLogger("Autopeering") func configure(plugin *node.Plugin) { saltmanager.Configure(plugin) @@ -45,36 +47,32 @@ func configureLogging(plugin *node.Plugin) { })) acceptedneighbors.INSTANCE.Events.Add.Attach(events.NewClosure(func(p *peer.Peer) { - plugin.LogDebug("accepted neighbor added: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier) - + log.Debugf("accepted neighbor added: %s / %s", p.GetAddress().String(), p.GetIdentity().StringIdentifier) gossip.AddNeighbor(gossip.NewNeighbor(p.GetIdentity(), p.GetAddress(), p.GetGossipPort())) })) acceptedneighbors.INSTANCE.Events.Remove.Attach(events.NewClosure(func(p *peer.Peer) { - plugin.LogDebug("accepted neighbor removed: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier) - + log.Debugf("accepted neighbor removed: %s / %s", p.GetAddress().String(), p.GetIdentity().StringIdentifier) gossip.RemoveNeighbor(p.GetIdentity().StringIdentifier) })) chosenneighbors.INSTANCE.Events.Add.Attach(events.NewClosure(func(p *peer.Peer) { - plugin.LogDebug("chosen neighbor added: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier) - + log.Debugf("chosen neighbor added: %s / %s", p.GetAddress().String(), p.GetIdentity().StringIdentifier) gossip.AddNeighbor(gossip.NewNeighbor(p.GetIdentity(), p.GetAddress(), p.GetGossipPort())) })) chosenneighbors.INSTANCE.Events.Remove.Attach(events.NewClosure(func(p *peer.Peer) { - plugin.LogDebug("chosen neighbor removed: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier) - + log.Debugf("chosen neighbor removed: %s / %s", p.GetAddress().String(), p.GetIdentity().StringIdentifier) gossip.RemoveNeighbor(p.GetIdentity().StringIdentifier) })) knownpeers.INSTANCE.Events.Add.Attach(events.NewClosure(func(p *peer.Peer) { - plugin.LogInfo("new peer discovered: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier) + log.Infof("new peer discovered: %s / %s", p.GetAddress().String(), p.GetIdentity().StringIdentifier) if _, exists := gossip.GetNeighbor(p.GetIdentity().StringIdentifier); exists { gossip.AddNeighbor(gossip.NewNeighbor(p.GetIdentity(), p.GetAddress(), p.GetGossipPort())) } })) knownpeers.INSTANCE.Events.Update.Attach(events.NewClosure(func(p *peer.Peer) { - plugin.LogDebug("peer updated: " + p.GetAddress().String() + " / " + p.GetIdentity().StringIdentifier) + log.Infof("peer updated: %s / %s", p.GetAddress().String(), p.GetIdentity().StringIdentifier) if _, exists := gossip.GetNeighbor(p.GetIdentity().StringIdentifier); exists { gossip.AddNeighbor(gossip.NewNeighbor(p.GetIdentity(), p.GetAddress(), p.GetGossipPort())) diff --git a/plugins/autopeering/protocol/accepted_neighbor_dropper.go b/plugins/autopeering/protocol/accepted_neighbor_dropper.go index f11c9169..056023f2 100644 --- a/plugins/autopeering/protocol/accepted_neighbor_dropper.go +++ b/plugins/autopeering/protocol/accepted_neighbor_dropper.go @@ -3,13 +3,13 @@ package protocol import ( "time" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/timeutil" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" "github.com/iotaledger/goshimmer/plugins/autopeering/types/drop" + "github.com/iotaledger/hive.go/node" ) func createAcceptedNeighborDropper(plugin *node.Plugin) func() { @@ -29,7 +29,7 @@ func createAcceptedNeighborDropper(plugin *node.Plugin) func() { acceptedneighbors.INSTANCE.Remove(furthestNeighbor.GetIdentity().StringIdentifier) go func() { if _, err := furthestNeighbor.Send(dropMessage.Marshal(), types.PROTOCOL_TYPE_UDP, false); err != nil { - plugin.LogDebug("error when sending drop message to" + acceptedneighbors.FURTHEST_NEIGHBOR.String()) + log.Debugf("error when sending drop message to %s", acceptedneighbors.FURTHEST_NEIGHBOR.String()) } }() } diff --git a/plugins/autopeering/protocol/chosen_neighbor_dropper.go b/plugins/autopeering/protocol/chosen_neighbor_dropper.go index 23d23533..4071d04e 100644 --- a/plugins/autopeering/protocol/chosen_neighbor_dropper.go +++ b/plugins/autopeering/protocol/chosen_neighbor_dropper.go @@ -3,13 +3,13 @@ package protocol import ( "time" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/timeutil" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" "github.com/iotaledger/goshimmer/plugins/autopeering/types/drop" + "github.com/iotaledger/hive.go/node" ) func createChosenNeighborDropper(plugin *node.Plugin) func() { @@ -29,7 +29,7 @@ func createChosenNeighborDropper(plugin *node.Plugin) func() { chosenneighbors.INSTANCE.Remove(furthestNeighbor.GetIdentity().StringIdentifier) go func() { if _, err := furthestNeighbor.Send(dropMessage.Marshal(), types.PROTOCOL_TYPE_UDP, false); err != nil { - plugin.LogDebug("error when sending drop message to" + chosenneighbors.FURTHEST_NEIGHBOR.String()) + log.Debugf("error when sending drop message to %s", chosenneighbors.FURTHEST_NEIGHBOR.String()) } }() } diff --git a/plugins/autopeering/protocol/error_handler.go b/plugins/autopeering/protocol/error_handler.go index d64eddc3..71f22fcf 100644 --- a/plugins/autopeering/protocol/error_handler.go +++ b/plugins/autopeering/protocol/error_handler.go @@ -3,12 +3,12 @@ package protocol import ( "net" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) func createErrorHandler(plugin *node.Plugin) *events.Closure { return events.NewClosure(func(ip net.IP, err error) { - plugin.LogDebug("error when communicating with " + ip.String() + ": " + err.Error()) + log.Debugf("error when communicating with %s: %s", ip.String(), err.Error()) }) } diff --git a/plugins/autopeering/protocol/incoming_drop_processor.go b/plugins/autopeering/protocol/incoming_drop_processor.go index 808b5c2e..3ab80f3b 100644 --- a/plugins/autopeering/protocol/incoming_drop_processor.go +++ b/plugins/autopeering/protocol/incoming_drop_processor.go @@ -1,16 +1,16 @@ package protocol import ( - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/types/drop" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) func createIncomingDropProcessor(plugin *node.Plugin) *events.Closure { return events.NewClosure(func(drop *drop.Drop) { - plugin.LogDebug("received drop message from " + drop.Issuer.String()) + log.Debugf("received drop message from %s", drop.Issuer.String()) chosenneighbors.INSTANCE.Remove(drop.Issuer.GetIdentity().StringIdentifier) acceptedneighbors.INSTANCE.Remove(drop.Issuer.GetIdentity().StringIdentifier) diff --git a/plugins/autopeering/protocol/incoming_ping_processor.go b/plugins/autopeering/protocol/incoming_ping_processor.go index 035abaab..ee52bf53 100644 --- a/plugins/autopeering/protocol/incoming_ping_processor.go +++ b/plugins/autopeering/protocol/incoming_ping_processor.go @@ -1,15 +1,15 @@ package protocol import ( - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) func createIncomingPingProcessor(plugin *node.Plugin) *events.Closure { return events.NewClosure(func(ping *ping.Ping) { - plugin.LogDebug("received ping from " + ping.Issuer.String()) + log.Debugf("received ping from %s", ping.Issuer.String()) knownpeers.INSTANCE.AddOrUpdate(ping.Issuer) for _, neighbor := range ping.Neighbors.GetPeers() { diff --git a/plugins/autopeering/protocol/incoming_request_processor.go b/plugins/autopeering/protocol/incoming_request_processor.go index 66493c08..2dbc6f65 100644 --- a/plugins/autopeering/protocol/incoming_request_processor.go +++ b/plugins/autopeering/protocol/incoming_request_processor.go @@ -6,7 +6,6 @@ import ( "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" @@ -15,6 +14,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/autopeering/types/peerlist" "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) func createIncomingRequestProcessor(plugin *node.Plugin) *events.Closure { @@ -24,7 +24,7 @@ func createIncomingRequestProcessor(plugin *node.Plugin) *events.Closure { } func processIncomingRequest(plugin *node.Plugin, req *request.Request) { - plugin.LogDebug("received peering request from " + req.Issuer.String()) + log.Debugf("received peering request from %s", req.Issuer.String()) knownpeers.INSTANCE.AddOrUpdate(req.Issuer) @@ -51,20 +51,20 @@ func requestShouldBeAccepted(req *request.Request) bool { func acceptRequest(plugin *node.Plugin, req *request.Request) { if err := req.Accept(generateProposedPeeringCandidates(req).GetPeers()); err != nil { - plugin.LogDebug("error when sending response to" + req.Issuer.String()) + log.Debugf("error when sending response to %s", req.Issuer.String()) } - plugin.LogDebug("sent positive peering response to " + req.Issuer.String()) + log.Debugf("sent positive peering response to %s", req.Issuer.String()) acceptedneighbors.INSTANCE.AddOrUpdate(req.Issuer) } func rejectRequest(plugin *node.Plugin, req *request.Request) { if err := req.Reject(generateProposedPeeringCandidates(req).GetPeers()); err != nil { - plugin.LogDebug("error when sending response to" + req.Issuer.String()) + log.Debugf("error when sending response to %s", req.Issuer.String()) } - plugin.LogDebug("sent negative peering response to " + req.Issuer.String()) + log.Debugf("sent negative peering response to %s", req.Issuer.String()) } func generateProposedPeeringCandidates(req *request.Request) *peerlist.PeerList { diff --git a/plugins/autopeering/protocol/incoming_response_processor.go b/plugins/autopeering/protocol/incoming_response_processor.go index e2f45f96..60b222c0 100644 --- a/plugins/autopeering/protocol/incoming_response_processor.go +++ b/plugins/autopeering/protocol/incoming_response_processor.go @@ -1,11 +1,11 @@ package protocol import ( - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers" "github.com/iotaledger/goshimmer/plugins/autopeering/types/response" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) func createIncomingResponseProcessor(plugin *node.Plugin) *events.Closure { @@ -15,7 +15,7 @@ func createIncomingResponseProcessor(plugin *node.Plugin) *events.Closure { } func processIncomingResponse(plugin *node.Plugin, peeringResponse *response.Response) { - plugin.LogDebug("received peering response from " + peeringResponse.Issuer.String()) + log.Debugf("received peering response from %s", peeringResponse.Issuer.String()) if conn := peeringResponse.Issuer.GetConn(); conn != nil { _ = conn.Close() diff --git a/plugins/autopeering/protocol/outgoing_ping_processor.go b/plugins/autopeering/protocol/outgoing_ping_processor.go index aacc3edd..1aa0dafc 100644 --- a/plugins/autopeering/protocol/outgoing_ping_processor.go +++ b/plugins/autopeering/protocol/outgoing_ping_processor.go @@ -5,8 +5,6 @@ import ( "time" "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/neighborhood" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/ownpeer" "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" @@ -15,15 +13,17 @@ import ( "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) var lastPing time.Time func createOutgoingPingProcessor(plugin *node.Plugin) func() { return func() { - plugin.LogInfo("Starting Ping Processor ...") - plugin.LogSuccess("Starting Ping Processor ... done") + log.Info("Starting Ping Processor ...") + log.Info("Starting Ping Processor ... done") lastPing = time.Now().Add(-constants.PING_CYCLE_LENGTH) @@ -43,7 +43,7 @@ func createOutgoingPingProcessor(plugin *node.Plugin) func() { for { select { case <-daemon.ShutdownSignal: - plugin.LogInfo("Stopping Ping Processor ...") + log.Info("Stopping Ping Processor ...") break ticker case <-ticker.C: @@ -51,7 +51,7 @@ func createOutgoingPingProcessor(plugin *node.Plugin) func() { } } - plugin.LogSuccess("Stopping Ping Processor ... done") + log.Info("Stopping Ping Processor ... done") } } @@ -73,9 +73,9 @@ func pingPeers(plugin *node.Plugin, outgoingPing *ping.Ping) { for _, chosenPeer := range chosenPeers { go func(chosenPeer *peer.Peer) { if _, err := chosenPeer.Send(outgoingPing.Marshal(), types.PROTOCOL_TYPE_UDP, false); err != nil { - plugin.LogDebug("error when sending ping to " + chosenPeer.String() + ": " + err.Error()) + log.Debugf("error when sending ping to %s: %s", chosenPeer.String(), err.Error()) } else { - plugin.LogDebug("sent ping to " + chosenPeer.String()) + log.Debugf("sent ping to %s", chosenPeer.String()) } }(chosenPeer) } diff --git a/plugins/autopeering/protocol/outgoing_request_processor.go b/plugins/autopeering/protocol/outgoing_request_processor.go index f36c08af..8f6c3d7e 100644 --- a/plugins/autopeering/protocol/outgoing_request_processor.go +++ b/plugins/autopeering/protocol/outgoing_request_processor.go @@ -10,18 +10,18 @@ import ( "github.com/iotaledger/goshimmer/packages/timeutil" "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" + "github.com/iotaledger/hive.go/daemon" + "github.com/iotaledger/hive.go/node" ) func createOutgoingRequestProcessor(plugin *node.Plugin) func() { return func() { - plugin.LogInfo("Starting Chosen Neighbor Processor ...") - plugin.LogSuccess("Starting Chosen Neighbor Processor ... done") + log.Info("Starting Chosen Neighbor Processor ...") + log.Info("Starting Chosen Neighbor Processor ... done") sendOutgoingRequests(plugin) @@ -30,7 +30,7 @@ func createOutgoingRequestProcessor(plugin *node.Plugin) func() { for { select { case <-daemon.ShutdownSignal: - plugin.LogInfo("Stopping Chosen Neighbor Processor ...") + log.Info("Stopping Chosen Neighbor Processor ...") break ticker case <-ticker.C: @@ -38,7 +38,7 @@ func createOutgoingRequestProcessor(plugin *node.Plugin) func() { } } - plugin.LogSuccess("Stopping Chosen Neighbor Processor ... done") + log.Info("Stopping Chosen Neighbor Processor ... done") } } @@ -51,9 +51,9 @@ func sendOutgoingRequests(plugin *node.Plugin) { go func(doneChan chan int) { if dialed, err := chosenNeighborCandidate.Send(outgoingrequest.INSTANCE.Marshal(), types.PROTOCOL_TYPE_TCP, true); err != nil { - plugin.LogDebug(err.Error()) + log.Debug(err.Error()) } else { - plugin.LogDebug("sent peering request to " + chosenNeighborCandidate.String()) + log.Debugf("sent peering request to %s", chosenNeighborCandidate.String()) if dialed { tcp.HandleConnection(chosenNeighborCandidate.GetConn()) diff --git a/plugins/autopeering/protocol/plugin.go b/plugins/autopeering/protocol/plugin.go index 569871e4..c026f2aa 100644 --- a/plugins/autopeering/protocol/plugin.go +++ b/plugins/autopeering/protocol/plugin.go @@ -1,14 +1,17 @@ package protocol import ( - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" "github.com/iotaledger/goshimmer/plugins/autopeering/server/tcp" "github.com/iotaledger/goshimmer/plugins/autopeering/server/udp" + "github.com/iotaledger/hive.go/daemon" + "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/parameter" ) +var log = logger.NewLogger("Autopeering-Protocol") + func Configure(plugin *node.Plugin) { errorHandler := createErrorHandler(plugin) diff --git a/plugins/autopeering/saltmanager/saltmanager.go b/plugins/autopeering/saltmanager/saltmanager.go index 6cb06a9a..a8e47b78 100644 --- a/plugins/autopeering/saltmanager/saltmanager.go +++ b/plugins/autopeering/saltmanager/saltmanager.go @@ -3,11 +3,11 @@ package saltmanager import ( "time" - "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/database" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/settings" "github.com/iotaledger/goshimmer/plugins/autopeering/types/salt" + "github.com/iotaledger/hive.go/daemon" + "github.com/iotaledger/hive.go/node" ) var ( diff --git a/plugins/autopeering/server/server.go b/plugins/autopeering/server/server.go index cf51cd30..d04941f2 100644 --- a/plugins/autopeering/server/server.go +++ b/plugins/autopeering/server/server.go @@ -1,9 +1,9 @@ package server import ( - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/server/tcp" "github.com/iotaledger/goshimmer/plugins/autopeering/server/udp" + "github.com/iotaledger/hive.go/node" ) func Configure(plugin *node.Plugin) { diff --git a/plugins/autopeering/server/tcp/server.go b/plugins/autopeering/server/tcp/server.go index a5b83951..9ac9454e 100644 --- a/plugins/autopeering/server/tcp/server.go +++ b/plugins/autopeering/server/tcp/server.go @@ -4,51 +4,53 @@ import ( "math" "net" - "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/network" "github.com/iotaledger/goshimmer/packages/network/tcp" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" "github.com/iotaledger/goshimmer/plugins/autopeering/types/response" + "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/parameter" "github.com/pkg/errors" ) var server = tcp.NewServer() +var log = logger.NewLogger("Autopeering-TCPServer") func ConfigureServer(plugin *node.Plugin) { serverAddress := parameter.NodeConfig.GetString(parameters.CFG_ADDRESS) - serverPortStr := parameter.NodeConfig.GetString(parameters.CFG_PORT) + serverPort := parameter.NodeConfig.GetInt(parameters.CFG_PORT) server.Events.Connect.Attach(events.NewClosure(HandleConnection)) server.Events.Error.Attach(events.NewClosure(func(err error) { - plugin.LogFailure("error in tcp server: " + err.Error()) + log.Errorf("error in tcp server: %s", err.Error()) })) server.Events.Start.Attach(events.NewClosure(func() { if serverAddress == "0.0.0.0" { - plugin.LogSuccess("Starting TCP Server (port " + serverPortStr + ") ... done") + log.Infof("Starting TCP Server (port %d) ... done", serverPort) } else { - plugin.LogSuccess("Starting TCP Server (" + serverAddress + ":" + serverPortStr + ") ... done") + log.Infof("Starting TCP Server (%s:%d) ... done", serverAddress, serverPort) } })) server.Events.Shutdown.Attach(events.NewClosure(func() { - plugin.LogSuccess("Stopping TCP Server ... done") + log.Info("Stopping TCP Server ... done") })) } func RunServer(plugin *node.Plugin) { serverAddress := parameter.NodeConfig.GetString(parameters.CFG_ADDRESS) - serverPortStr := parameter.NodeConfig.GetString(parameters.CFG_PORT) + serverPort := parameter.NodeConfig.GetInt(parameters.CFG_PORT) daemon.BackgroundWorker("Autopeering TCP Server", func() { if serverAddress == "0.0.0.0" { - plugin.LogInfo("Starting TCP Server (port " + serverPortStr + ") ...") + log.Infof("Starting TCP Server (port %d) ...", serverPort) } else { - plugin.LogInfo("Starting TCP Server (" + serverAddress + ":" + serverPortStr + ") ...") + log.Infof("Starting TCP Server (%s:%d) ...", serverAddress, serverPort) } server.Listen(parameter.NodeConfig.GetInt(parameters.CFG_PORT)) @@ -56,7 +58,7 @@ func RunServer(plugin *node.Plugin) { } func ShutdownServer(plugin *node.Plugin) { - plugin.LogInfo("Stopping TCP Server ...") + log.Info("Stopping TCP Server ...") server.Shutdown() } diff --git a/plugins/autopeering/server/udp/server.go b/plugins/autopeering/server/udp/server.go index 4af9f312..5c6019bc 100644 --- a/plugins/autopeering/server/udp/server.go +++ b/plugins/autopeering/server/udp/server.go @@ -1,15 +1,16 @@ package udp import ( - "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/network/udp" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/parameters" "github.com/iotaledger/goshimmer/plugins/autopeering/types/drop" "github.com/iotaledger/goshimmer/plugins/autopeering/types/ping" "github.com/iotaledger/goshimmer/plugins/autopeering/types/request" "github.com/iotaledger/goshimmer/plugins/autopeering/types/response" + "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/parameter" "github.com/pkg/errors" "math" @@ -17,40 +18,41 @@ import ( ) var udpServer = udp.NewServer(int(math.Max(float64(request.MARSHALED_TOTAL_SIZE), float64(response.MARSHALED_TOTAL_SIZE)))) +var log = logger.NewLogger("Autopeering-UDPServer") func ConfigureServer(plugin *node.Plugin) { serverAddress := parameter.NodeConfig.GetString(parameters.CFG_ADDRESS) - serverPortStr := parameter.NodeConfig.GetString(parameters.CFG_PORT) + serverPort := parameter.NodeConfig.GetInt(parameters.CFG_PORT) Events.Error.Attach(events.NewClosure(func(ip net.IP, err error) { - plugin.LogFailure(err.Error()) + log.Error(err.Error()) })) udpServer.Events.ReceiveData.Attach(events.NewClosure(processReceivedData)) udpServer.Events.Error.Attach(events.NewClosure(func(err error) { - plugin.LogFailure("error in udp server: " + err.Error()) + log.Errorf("error in udp server: %s", err.Error()) })) udpServer.Events.Start.Attach(events.NewClosure(func() { if serverAddress == "0.0.0.0" { - plugin.LogSuccess("Starting UDP Server (port " + serverPortStr + ") ... done") + log.Infof("Starting UDP Server (port %d) ... done", serverPort) } else { - plugin.LogSuccess("Starting UDP Server (" + serverAddress + ":" + serverPortStr + ") ... done") + log.Infof("Starting UDP Server (%s:%d) ... done", serverAddress, serverPort) } })) udpServer.Events.Shutdown.Attach(events.NewClosure(func() { - plugin.LogSuccess("Stopping UDP Server ... done") + log.Info("Stopping UDP Server ... done") })) } func RunServer(plugin *node.Plugin) { serverAddress := parameter.NodeConfig.GetString(parameters.CFG_ADDRESS) - serverPortStr := parameter.NodeConfig.GetString(parameters.CFG_PORT) + serverPort := parameter.NodeConfig.GetInt(parameters.CFG_PORT) daemon.BackgroundWorker("Autopeering UDP Server", func() { if serverAddress == "0.0.0.0" { - plugin.LogInfo("Starting UDP Server (port " + serverPortStr + ") ...") + log.Infof("Starting UDP Server (port %d) ...", serverPort) } else { - plugin.LogInfo("Starting UDP Server (" + serverAddress + ":" + serverPortStr + ") ...") + log.Infof("Starting UDP Server (%s:%d) ...", serverAddress, serverPort) } udpServer.Listen(serverAddress, parameter.NodeConfig.GetInt(parameters.CFG_PORT)) @@ -58,7 +60,7 @@ func RunServer(plugin *node.Plugin) { } func ShutdownUDPServer(plugin *node.Plugin) { - plugin.LogInfo("Stopping UDP Server ...") + log.Info("Stopping UDP Server ...") udpServer.Shutdown() } diff --git a/plugins/bundleprocessor/bundleprocessor_test.go b/plugins/bundleprocessor/bundleprocessor_test.go index 99a47471..6fda9085 100644 --- a/plugins/bundleprocessor/bundleprocessor_test.go +++ b/plugins/bundleprocessor/bundleprocessor_test.go @@ -14,7 +14,7 @@ import ( "github.com/iotaledger/goshimmer/packages/client" - "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/iota.go/consts" diff --git a/plugins/bundleprocessor/plugin.go b/plugins/bundleprocessor/plugin.go index f9b01433..2344caa6 100644 --- a/plugins/bundleprocessor/plugin.go +++ b/plugins/bundleprocessor/plugin.go @@ -1,15 +1,17 @@ package bundleprocessor import ( - "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/tangle" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/hive.go/node" ) var PLUGIN = node.NewPlugin("Bundle Processor", node.Enabled, configure, run) +var log = logger.NewLogger("Bundle Processor") func configure(plugin *node.Plugin) { tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) { @@ -19,38 +21,34 @@ func configure(plugin *node.Plugin) { })) Events.Error.Attach(events.NewClosure(func(err errors.IdentifiableError) { - plugin.LogFailure(err.Error()) + log.Error(err.Error()) })) daemon.Events.Shutdown.Attach(events.NewClosure(func() { - plugin.LogInfo("Stopping Bundle Processor ...") + log.Info("Stopping Bundle Processor ...") workerPool.Stop() - plugin.LogInfo("Stopping Value Bundle Processor ...") + log.Info("Stopping Value Bundle Processor ...") valueBundleProcessorWorkerPool.Stop() })) } func run(plugin *node.Plugin) { - plugin.LogInfo("Starting Bundle Processor ...") + log.Info("Starting Bundle Processor ...") daemon.BackgroundWorker("Bundle Processor", func() { - plugin.LogSuccess("Starting Bundle Processor ... done") - + log.Info("Starting Bundle Processor ... done") workerPool.Run() - - plugin.LogSuccess("Stopping Bundle Processor ... done") + log.Info("Stopping Bundle Processor ... done") }) - plugin.LogInfo("Starting Value Bundle Processor ...") + log.Info("Starting Value Bundle Processor ...") daemon.BackgroundWorker("Value Bundle Processor", func() { - plugin.LogSuccess("Starting Value Bundle Processor ... done") - + log.Info("Starting Value Bundle Processor ... done") valueBundleProcessorWorkerPool.Run() - - plugin.LogSuccess("Stopping Value Bundle Processor ... done") + log.Info("Stopping Value Bundle Processor ... done") }) } diff --git a/plugins/cli/cli.go b/plugins/cli/cli.go index 55106e01..9275838b 100644 --- a/plugins/cli/cli.go +++ b/plugins/cli/cli.go @@ -9,7 +9,7 @@ import ( flag "github.com/spf13/pflag" - "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/node" ) var enabledPlugins []string diff --git a/plugins/cli/plugin.go b/plugins/cli/plugin.go index c7ac5908..4439bb91 100644 --- a/plugins/cli/plugin.go +++ b/plugins/cli/plugin.go @@ -7,7 +7,8 @@ import ( "github.com/iotaledger/hive.go/events" flag "github.com/spf13/pflag" - "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/node" + "github.com/iotaledger/hive.go/parameter" ) @@ -39,7 +40,7 @@ func parseParameters() { for _, pluginName := range parameter.NodeConfig.GetStringSlice(node.CFG_DISABLE_PLUGINS) { node.DisabledPlugins[strings.ToLower(pluginName)] = true } - for _, pluginName := range parameter.NodeConfig.GetStringSlice(node.CFG_ENABLE_PLGUINS) { + for _, pluginName := range parameter.NodeConfig.GetStringSlice(node.CFG_ENABLE_PLUGINS) { node.EnabledPlugins[strings.ToLower(pluginName)] = true } } @@ -57,7 +58,7 @@ func configure(ctx *node.Plugin) { parameter.FetchConfig() parseParameters() - ctx.Node.LogInfo("Node", "Loading plugins ...") + ctx.Node.Logger.Info("Loading plugins ...") } func run(ctx *node.Plugin) { diff --git a/plugins/dashboard/plugin.go b/plugins/dashboard/plugin.go index 5b38ebed..a5815826 100644 --- a/plugins/dashboard/plugin.go +++ b/plugins/dashboard/plugin.go @@ -1,15 +1,16 @@ package dashboard import ( + "github.com/iotaledger/hive.go/logger" "net/http" "time" "golang.org/x/net/context" - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/metrics" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) var server *http.Server @@ -17,6 +18,7 @@ var server *http.Server var router *http.ServeMux var PLUGIN = node.NewPlugin("Dashboard", node.Disabled, configure, run) +var log = logger.NewLogger("Dashboard") func configure(plugin *node.Plugin) { router = http.NewServeMux() @@ -45,7 +47,7 @@ func run(plugin *node.Plugin) { daemon.BackgroundWorker("Dashboard Updater", func() { go func() { if err := server.ListenAndServe(); err != nil { - plugin.LogFailure(err.Error()) + log.Error(err.Error()) } }() }) diff --git a/plugins/gossip-on-solidification/plugin.go b/plugins/gossip-on-solidification/plugin.go index 22c0f106..42b09256 100644 --- a/plugins/gossip-on-solidification/plugin.go +++ b/plugins/gossip-on-solidification/plugin.go @@ -2,10 +2,10 @@ package gossip_on_solidification import ( "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) var PLUGIN = node.NewPlugin("Gossip On Solidification", node.Enabled, func(plugin *node.Plugin) { diff --git a/plugins/gossip/neighbors.go b/plugins/gossip/neighbors.go index 23107679..ef3431c1 100644 --- a/plugins/gossip/neighbors.go +++ b/plugins/gossip/neighbors.go @@ -8,30 +8,30 @@ import ( "time" "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/packages/daemon" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/identity" "github.com/iotaledger/goshimmer/packages/network" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) func configureNeighbors(plugin *node.Plugin) { Events.AddNeighbor.Attach(events.NewClosure(func(neighbor *Neighbor) { - plugin.LogSuccess("new neighbor added " + neighbor.GetIdentity().StringIdentifier + "@" + neighbor.GetAddress().String() + ":" + strconv.Itoa(int(neighbor.GetPort()))) + log.Infof("new neighbor added %s@%s:%d", neighbor.GetIdentity().StringIdentifier, neighbor.GetAddress().String(), neighbor.GetPort()) })) Events.UpdateNeighbor.Attach(events.NewClosure(func(neighbor *Neighbor) { - plugin.LogSuccess("existing neighbor updated " + neighbor.GetIdentity().StringIdentifier + "@" + neighbor.GetAddress().String() + ":" + strconv.Itoa(int(neighbor.GetPort()))) + log.Infof("existing neighbor updated %s@%s:%d", neighbor.GetIdentity().StringIdentifier, neighbor.GetAddress().String(), neighbor.GetPort()) })) Events.RemoveNeighbor.Attach(events.NewClosure(func(neighbor *Neighbor) { - plugin.LogSuccess("existing neighbor removed " + neighbor.GetIdentity().StringIdentifier + "@" + neighbor.GetAddress().String() + ":" + strconv.Itoa(int(neighbor.GetPort()))) + log.Infof("existing neighbor removed %s@%s:%d", neighbor.GetIdentity().StringIdentifier, neighbor.GetAddress().String(), neighbor.GetPort()) })) } func runNeighbors(plugin *node.Plugin) { - plugin.LogInfo("Starting Neighbor Connection Manager ...") + log.Info("Starting Neighbor Connection Manager ...") neighborLock.RLock() for _, neighbor := range neighbors.GetMap() { @@ -43,7 +43,7 @@ func runNeighbors(plugin *node.Plugin) { manageConnection(plugin, neighbor) })) - plugin.LogSuccess("Starting Neighbor Connection Manager ... done") + log.Info("Starting Neighbor Connection Manager ... done") } func manageConnection(plugin *node.Plugin, neighbor *Neighbor) { @@ -55,7 +55,7 @@ func manageConnection(plugin *node.Plugin, neighbor *Neighbor) { if err != nil { failedConnectionAttempts++ - plugin.LogFailure("connection attempt [" + strconv.Itoa(int(failedConnectionAttempts)) + "/" + strconv.Itoa(CONNECTION_MAX_ATTEMPTS) + "] " + err.Error()) + log.Errorf("connection attempt [%d / %d] %s", failedConnectionAttempts, CONNECTION_MAX_ATTEMPTS, err.Error()) if failedConnectionAttempts <= CONNECTION_MAX_ATTEMPTS { select { diff --git a/plugins/gossip/plugin.go b/plugins/gossip/plugin.go index 872e3cac..c3d7ffef 100644 --- a/plugins/gossip/plugin.go +++ b/plugins/gossip/plugin.go @@ -1,10 +1,12 @@ package gossip import ( - "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/hive.go/node" ) var PLUGIN = node.NewPlugin("Gossip", node.Enabled, configure, run) +var log = logger.NewLogger("Gossip") func configure(plugin *node.Plugin) { configureNeighbors(plugin) diff --git a/plugins/gossip/send_queue.go b/plugins/gossip/send_queue.go index 7b92be4a..b3b78bb0 100644 --- a/plugins/gossip/send_queue.go +++ b/plugins/gossip/send_queue.go @@ -3,10 +3,10 @@ package gossip import ( "sync" - "github.com/iotaledger/goshimmer/packages/daemon" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) // region plugin module setup ////////////////////////////////////////////////////////////////////////////////////////// @@ -19,20 +19,20 @@ func configureSendQueue(plugin *node.Plugin) { Events.AddNeighbor.Attach(events.NewClosure(setupEventHandlers)) daemon.Events.Shutdown.Attach(events.NewClosure(func() { - plugin.LogInfo("Stopping Send Queue Dispatcher ...") + log.Info("Stopping Send Queue Dispatcher ...") })) } func runSendQueue(plugin *node.Plugin) { - plugin.LogInfo("Starting Send Queue Dispatcher ...") + log.Info("Starting Send Queue Dispatcher ...") daemon.BackgroundWorker("Gossip Send Queue Dispatcher", func() { - plugin.LogSuccess("Starting Send Queue Dispatcher ... done") + log.Info("Starting Send Queue Dispatcher ... done") for { select { case <-daemon.ShutdownSignal: - plugin.LogSuccess("Stopping Send Queue Dispatcher ... done") + log.Info("Stopping Send Queue Dispatcher ... done") return diff --git a/plugins/gossip/server.go b/plugins/gossip/server.go index 5577d446..99520078 100644 --- a/plugins/gossip/server.go +++ b/plugins/gossip/server.go @@ -2,13 +2,13 @@ package gossip import ( "github.com/iotaledger/goshimmer/packages/accountability" - "github.com/iotaledger/goshimmer/packages/daemon" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/identity" "github.com/iotaledger/goshimmer/packages/network" "github.com/iotaledger/goshimmer/packages/network/tcp" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/parameter" ) @@ -20,7 +20,7 @@ func configureServer(plugin *node.Plugin) { // print protocol errors protocol.Events.Error.Attach(events.NewClosure(func(err errors.IdentifiableError) { - plugin.LogFailure(err.Error()) + log.Error(err.Error()) })) // store protocol in neighbor if its a neighbor calling @@ -57,21 +57,21 @@ func configureServer(plugin *node.Plugin) { })) daemon.Events.Shutdown.Attach(events.NewClosure(func() { - plugin.LogInfo("Stopping TCP Server ...") + log.Info("Stopping TCP Server ...") TCPServer.Shutdown() })) } func runServer(plugin *node.Plugin) { - gossipPort := parameter.NodeConfig.GetString(GOSSIP_PORT) - plugin.LogInfo("Starting TCP Server (port " + gossipPort + ") ...") + gossipPort := parameter.NodeConfig.GetInt(GOSSIP_PORT) + log.Infof("Starting TCP Server (port %d) ...", gossipPort) daemon.BackgroundWorker("Gossip TCP Server", func() { - plugin.LogSuccess("Starting TCP Server (port " + gossipPort + ") ... done") + log.Infof("Starting TCP Server (port %d) ... done", gossipPort) - TCPServer.Listen(parameter.NodeConfig.GetInt(GOSSIP_PORT)) + TCPServer.Listen(gossipPort) - plugin.LogSuccess("Stopping TCP Server ... done") + log.Info("Stopping TCP Server ... done") }) } diff --git a/plugins/gracefulshutdown/plugin.go b/plugins/gracefulshutdown/plugin.go index 41da78c2..d24c61b2 100644 --- a/plugins/gracefulshutdown/plugin.go +++ b/plugins/gracefulshutdown/plugin.go @@ -1,20 +1,21 @@ package gracefulshutdown import ( + "github.com/iotaledger/hive.go/logger" "os" "os/signal" - "strconv" "strings" "syscall" "time" - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/daemon" + "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 +var log = logger.NewLogger("Graceful Shutdown") var PLUGIN = node.NewPlugin("Graceful Shutdown", node.Enabled, func(plugin *node.Plugin) { gracefulStop := make(chan os.Signal) @@ -24,7 +25,7 @@ var PLUGIN = node.NewPlugin("Graceful Shutdown", node.Enabled, func(plugin *node go func() { <-gracefulStop - plugin.LogWarning("Received shutdown request - waiting (max " + strconv.Itoa(WAIT_TO_KILL_TIME_IN_SECONDS) + " seconds) to finish processing ...") + log.Warningf("Received shutdown request - waiting (max %d) to finish processing ...", WAIT_TO_KILL_TIME_IN_SECONDS) go func() { start := time.Now() @@ -37,11 +38,9 @@ var PLUGIN = node.NewPlugin("Graceful Shutdown", node.Enabled, func(plugin *node if len(runningBackgroundWorkers) >= 1 { processList = "(" + strings.Join(runningBackgroundWorkers, ", ") + ") " } - - plugin.LogWarning("Received shutdown request - waiting (max " + strconv.Itoa(WAIT_TO_KILL_TIME_IN_SECONDS-int(secondsSinceStart)) + " seconds) to finish processing " + processList + "...") + log.Warningf("Received shutdown request - waiting (max %d seconds) to finish processing ...", WAIT_TO_KILL_TIME_IN_SECONDS-int(secondsSinceStart), processList) } else { - plugin.LogFailure("Background processes did not terminate in time! Forcing shutdown ...") - + log.Error("Background processes did not terminate in time! Forcing shutdown ...") os.Exit(1) } } diff --git a/plugins/metrics/plugin.go b/plugins/metrics/plugin.go index 6d8aa2fd..c483a42a 100644 --- a/plugins/metrics/plugin.go +++ b/plugins/metrics/plugin.go @@ -1,14 +1,14 @@ package metrics -import( +import ( "time" - "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/timeutil" "github.com/iotaledger/goshimmer/plugins/gossip" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) var PLUGIN = node.NewPlugin("Metrics", node.Enabled, configure, run) diff --git a/plugins/statusscreen-tps/plugin.go b/plugins/statusscreen-tps/plugin.go index 1b81a29e..15f4d1ba 100644 --- a/plugins/statusscreen-tps/plugin.go +++ b/plugins/statusscreen-tps/plugin.go @@ -5,14 +5,14 @@ import ( "sync/atomic" "time" - "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/goshimmer/plugins/statusscreen" "github.com/iotaledger/goshimmer/plugins/tangle" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) var receivedTpsCounter uint64 diff --git a/plugins/statusscreen/logger.go b/plugins/statusscreen/logger.go index f4734e3f..a32db7fd 100644 --- a/plugins/statusscreen/logger.go +++ b/plugins/statusscreen/logger.go @@ -1,24 +1,23 @@ package statusscreen import ( + "github.com/iotaledger/hive.go/logger" "time" - - "github.com/iotaledger/goshimmer/packages/node" ) -func storeStatusMessage(pluginName string, message string, logLevel int) { +func storeStatusMessage(logLevel logger.LogLevel, prefix string, message string, ) { mutex.Lock() defer mutex.Unlock() messageLog = append(messageLog, &StatusMessage{ - Source: pluginName, + Source: prefix, LogLevel: logLevel, Message: message, Time: time.Now(), }) - if statusMessage, exists := statusMessages[pluginName]; !exists { - statusMessages[pluginName] = &StatusMessage{ - Source: pluginName, + if statusMessage, exists := statusMessages[prefix]; !exists { + statusMessages[prefix] = &StatusMessage{ + Source: prefix, LogLevel: logLevel, Message: message, Time: time.Now(), @@ -29,21 +28,3 @@ func storeStatusMessage(pluginName string, message string, logLevel int) { statusMessage.Time = time.Now() } } - -var DEFAULT_LOGGER = &node.Logger{ - LogInfo: func(pluginName string, message string) { - storeStatusMessage(pluginName, message, node.LOG_LEVEL_INFO) - }, - LogSuccess: func(pluginName string, message string) { - storeStatusMessage(pluginName, message, node.LOG_LEVEL_SUCCESS) - }, - LogWarning: func(pluginName string, message string) { - storeStatusMessage(pluginName, message, node.LOG_LEVEL_WARNING) - }, - LogFailure: func(pluginName string, message string) { - storeStatusMessage(pluginName, message, node.LOG_LEVEL_FAILURE) - }, - LogDebug: func(pluginName string, message string) { - storeStatusMessage(pluginName, message, node.LOG_LEVEL_DEBUG) - }, -} diff --git a/plugins/statusscreen/status_message.go b/plugins/statusscreen/status_message.go index a3b55bec..6ac60673 100644 --- a/plugins/statusscreen/status_message.go +++ b/plugins/statusscreen/status_message.go @@ -1,12 +1,13 @@ package statusscreen import ( + "github.com/iotaledger/hive.go/logger" "time" ) type StatusMessage struct { Source string - LogLevel int + LogLevel logger.LogLevel Message string Time time.Time } diff --git a/plugins/statusscreen/statusscreen.go b/plugins/statusscreen/statusscreen.go index f76e097e..93db9a19 100644 --- a/plugins/statusscreen/statusscreen.go +++ b/plugins/statusscreen/statusscreen.go @@ -1,14 +1,16 @@ package statusscreen import ( + "github.com/iotaledger/hive.go/logger" + "io/ioutil" "os" "sync" "time" "github.com/gdamore/tcell" - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" "github.com/rivo/tview" "golang.org/x/crypto/ssh/terminal" ) @@ -24,13 +26,19 @@ func configure(plugin *node.Plugin) { return } - node.DEFAULT_LOGGER.SetEnabled(false) + // don't write anything to stdout anymore + // as log messages are now stored and displayed via this plugin + logger.InjectWriters(ioutil.Discard) - DEFAULT_LOGGER.SetEnabled(true) - plugin.Node.AddLogger(DEFAULT_LOGGER) + // store any log message for display + anyLogMsgClosure := events.NewClosure(func(logLevel logger.LogLevel, prefix string, msg string) { + storeStatusMessage(logLevel, prefix, msg) + }) + logger.Events.AnyMsg.Attach(anyLogMsgClosure) daemon.Events.Shutdown.Attach(events.NewClosure(func() { - node.DEFAULT_LOGGER.SetEnabled(true) + logger.InjectWriters(os.Stdout) + logger.Events.AnyMsg.Detach(anyLogMsgClosure) if app != nil { app.Stop() diff --git a/plugins/statusscreen/ui_log_entry.go b/plugins/statusscreen/ui_log_entry.go index df9a608d..168d6d1f 100644 --- a/plugins/statusscreen/ui_log_entry.go +++ b/plugins/statusscreen/ui_log_entry.go @@ -2,9 +2,9 @@ package statusscreen import ( "fmt" + "github.com/iotaledger/hive.go/logger" "github.com/gdamore/tcell" - "github.com/iotaledger/goshimmer/packages/node" "github.com/rivo/tview" ) @@ -37,19 +37,25 @@ func NewUILogEntry(message StatusMessage) *UILogEntry { textColor := "black::d" switch message.LogLevel { - case node.LOG_LEVEL_INFO: + case logger.LevelInfo: fmt.Fprintf(logEntry.LogLevelContainer, " [black::d][ [blue::d]INFO [black::d]]") - case node.LOG_LEVEL_SUCCESS: - fmt.Fprintf(logEntry.LogLevelContainer, " [black::d][ [green::d]OK [black::d]]") - case node.LOG_LEVEL_WARNING: + case logger.LevelNotice: + fmt.Fprintf(logEntry.LogLevelContainer, " [black::d][ [blue::d]NOTICE [black::d]]") + case logger.LevelWarning: fmt.Fprintf(logEntry.LogLevelContainer, " [black::d][ [yellow::d]WARN [black::d]]") textColor = "yellow::d" - case node.LOG_LEVEL_FAILURE: + case logger.LevelError: + fallthrough + case logger.LevelCritical: + fallthrough + case logger.LevelPanic: + fallthrough + case logger.LevelFatal: fmt.Fprintf(logEntry.LogLevelContainer, " [black::d][ [red::d]FAIL [black::d]]") textColor = "red::d" - case node.LOG_LEVEL_DEBUG: + case logger.LevelDebug: fmt.Fprintf(logEntry.LogLevelContainer, " [black::d][ [black::b]NOTE [black::d]]") textColor = "black::b" diff --git a/plugins/tangle/approvers.go b/plugins/tangle/approvers.go index f0fbd883..e1503396 100644 --- a/plugins/tangle/approvers.go +++ b/plugins/tangle/approvers.go @@ -5,8 +5,8 @@ import ( "github.com/iotaledger/goshimmer/packages/datastructure" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/model/approvers" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/typeutils" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/iota.go/trinary" ) diff --git a/plugins/tangle/bundle.go b/plugins/tangle/bundle.go index c0d9ecb8..ac5b1cd3 100644 --- a/plugins/tangle/bundle.go +++ b/plugins/tangle/bundle.go @@ -5,8 +5,8 @@ import ( "github.com/iotaledger/goshimmer/packages/datastructure" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/model/bundle" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/typeutils" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/iota.go/trinary" ) diff --git a/plugins/tangle/plugin.go b/plugins/tangle/plugin.go index f1efc83a..62006c6b 100644 --- a/plugins/tangle/plugin.go +++ b/plugins/tangle/plugin.go @@ -1,12 +1,14 @@ package tangle import ( - "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/hive.go/node" ) // region plugin module setup ////////////////////////////////////////////////////////////////////////////////////////// var PLUGIN = node.NewPlugin("Tangle", node.Enabled, configure, run) +var log = logger.NewLogger("Tangle") func configure(plugin *node.Plugin) { configureTransactionDatabase(plugin) diff --git a/plugins/tangle/solidifier.go b/plugins/tangle/solidifier.go index 2a0dca58..53a0fe61 100644 --- a/plugins/tangle/solidifier.go +++ b/plugins/tangle/solidifier.go @@ -3,16 +3,16 @@ package tangle import ( "runtime" - "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/model/approvers" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/model/transactionmetadata" "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/workerpool" "github.com/iotaledger/goshimmer/plugins/gossip" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/iota.go/trinary" ) @@ -32,21 +32,18 @@ func configureSolidifier(plugin *node.Plugin) { })) daemon.Events.Shutdown.Attach(events.NewClosure(func() { - plugin.LogInfo("Stopping Solidifier ...") - + log.Info("Stopping Solidifier ...") workerPool.Stop() })) } func runSolidifier(plugin *node.Plugin) { - plugin.LogInfo("Starting Solidifier ...") + log.Info("Starting Solidifier ...") daemon.BackgroundWorker("Tangle Solidifier", func() { - plugin.LogSuccess("Starting Solidifier ... done") - + log.Info("Starting Solidifier ... done") workerPool.Run() - - plugin.LogSuccess("Stopping Solidifier ... done") + log.Info("Stopping Solidifier ... done") }) } @@ -153,7 +150,7 @@ func processMetaTransaction(plugin *node.Plugin, metaTransaction *meta_transacti return value_transaction.FromMetaTransaction(metaTransaction) }); err != nil { - plugin.LogFailure(err.Error()) + log.Errorf("Unable to load transaction %s: %s", metaTransaction.GetHash(), err.Error()) } else if newTransaction { processTransaction(plugin, tx) } @@ -166,8 +163,7 @@ func processTransaction(plugin *node.Plugin, transaction *value_transaction.Valu // register tx as approver for trunk if trunkApprovers, err := GetApprovers(transaction.GetTrunkTransactionHash(), approvers.New); err != nil { - plugin.LogFailure(err.Error()) - + log.Errorf("Unable to get approvers of transaction %s: %s", transaction.GetTrunkTransactionHash(), err.Error()) return } else { trunkApprovers.Add(transactionHash) @@ -175,8 +171,7 @@ func processTransaction(plugin *node.Plugin, transaction *value_transaction.Valu // register tx as approver for branch if branchApprovers, err := GetApprovers(transaction.GetBranchTransactionHash(), approvers.New); err != nil { - plugin.LogFailure(err.Error()) - + log.Errorf("Unable to get approvers of transaction %s: %s", transaction.GetBranchTransactionHash(), err.Error()) return } else { branchApprovers.Add(transactionHash) @@ -184,8 +179,7 @@ func processTransaction(plugin *node.Plugin, transaction *value_transaction.Valu // update the solidity flags of this transaction and its approvers if _, err := IsSolid(transaction); err != nil { - plugin.LogFailure(err.Error()) - + log.Errorf("Unable to check solidity: %s", err.Error()) return } } diff --git a/plugins/tangle/solidifier_test.go b/plugins/tangle/solidifier_test.go index b6a1b8bf..f13daf1b 100644 --- a/plugins/tangle/solidifier_test.go +++ b/plugins/tangle/solidifier_test.go @@ -7,9 +7,9 @@ import ( "testing" "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/iota.go/trinary" ) diff --git a/plugins/tangle/transaction.go b/plugins/tangle/transaction.go index 187e5df6..611a73df 100644 --- a/plugins/tangle/transaction.go +++ b/plugins/tangle/transaction.go @@ -5,8 +5,8 @@ import ( "github.com/iotaledger/goshimmer/packages/datastructure" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/typeutils" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/iota.go/trinary" ) diff --git a/plugins/tangle/transaction_metadata.go b/plugins/tangle/transaction_metadata.go index 16674b21..75c1086f 100644 --- a/plugins/tangle/transaction_metadata.go +++ b/plugins/tangle/transaction_metadata.go @@ -5,8 +5,8 @@ import ( "github.com/iotaledger/goshimmer/packages/datastructure" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/model/transactionmetadata" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/typeutils" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/iota.go/trinary" ) diff --git a/plugins/tipselection/plugin.go b/plugins/tipselection/plugin.go index a2c7ba17..2f919f58 100644 --- a/plugins/tipselection/plugin.go +++ b/plugins/tipselection/plugin.go @@ -2,9 +2,9 @@ package tipselection import ( "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) var PLUGIN = node.NewPlugin("Tipselection", node.Enabled, configure, run) diff --git a/plugins/ui/logger.go b/plugins/ui/logger.go index 9b159c6a..b34519ce 100644 --- a/plugins/ui/logger.go +++ b/plugins/ui/logger.go @@ -1,50 +1,33 @@ package ui import ( + "github.com/iotaledger/hive.go/logger" + "sync" "time" - - "github.com/iotaledger/goshimmer/packages/node" ) +var logMutex = sync.Mutex{} var logHistory = make([]*statusMessage, 0) type statusMessage struct { - Source string `json:"source"` - Level int `json:"level"` - Message string `json:"message"` - Time time.Time `json:"time"` + Source string `json:"source"` + Level logger.LogLevel `json:"level"` + Message string `json:"message"` + Time time.Time `json:"time"` } type resp map[string]interface{} -func storeAndSendStatusMessage(pluginName string, message string, level int) { +func storeAndSendStatusMessage(logLevel logger.LogLevel, pluginName string, message string) { msg := &statusMessage{ Source: pluginName, - Level: level, + Level: logLevel, Message: message, Time: time.Now(), } + logMutex.Lock() logHistory = append(logHistory, msg) - ws.send(resp{ - "logs": []*statusMessage{msg}, - }) -} - -var uiLogger = &node.Logger{ - LogInfo: func(pluginName string, message string) { - storeAndSendStatusMessage(pluginName, message, node.LOG_LEVEL_INFO) - }, - LogSuccess: func(pluginName string, message string) { - storeAndSendStatusMessage(pluginName, message, node.LOG_LEVEL_SUCCESS) - }, - LogWarning: func(pluginName string, message string) { - storeAndSendStatusMessage(pluginName, message, node.LOG_LEVEL_WARNING) - }, - LogFailure: func(pluginName string, message string) { - storeAndSendStatusMessage(pluginName, message, node.LOG_LEVEL_FAILURE) - }, - LogDebug: func(pluginName string, message string) { - storeAndSendStatusMessage(pluginName, message, node.LOG_LEVEL_DEBUG) - }, + logMutex.Unlock() + ws.send(resp{"logs": []*statusMessage{msg}}) } diff --git a/plugins/ui/ui.go b/plugins/ui/ui.go index 6ca34f3d..f4e5afad 100644 --- a/plugins/ui/ui.go +++ b/plugins/ui/ui.go @@ -1,19 +1,20 @@ package ui import ( + "github.com/iotaledger/hive.go/logger" "net/http" "strings" "sync/atomic" "time" - "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/goshimmer/plugins/webapi" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" "github.com/labstack/echo" ) @@ -46,8 +47,11 @@ func configure(plugin *node.Plugin) { }() })) - uiLogger.SetEnabled(true) - plugin.Node.AddLogger(uiLogger) + // store log messages to send them down via the websocket + anyMsgClosure := events.NewClosure(func(logLvl logger.LogLevel, prefix string, msg string) { + storeAndSendStatusMessage(logLvl, prefix, msg) + }) + logger.Events.AnyMsg.Attach(anyMsgClosure) } func staticFileServer(c echo.Context) error { diff --git a/plugins/validator/plugin.go b/plugins/validator/plugin.go index 70f5241b..11217efc 100644 --- a/plugins/validator/plugin.go +++ b/plugins/validator/plugin.go @@ -3,15 +3,17 @@ package validator import ( "github.com/iotaledger/goshimmer/packages/model/bundle" "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/bundleprocessor" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/iota.go/kerl" "github.com/iotaledger/iota.go/signing" . "github.com/iotaledger/iota.go/trinary" ) var PLUGIN = node.NewPlugin("Validator", node.Enabled, configure, run) +var log = logger.NewLogger("Validator") func validateSignatures(bundleHash Hash, txs []*value_transaction.ValueTransaction) (bool, error) { for i, tx := range txs { @@ -52,9 +54,13 @@ func configure(plugin *node.Plugin) { bundleprocessor.Events.BundleSolid.Attach(events.NewClosure(func(b *bundle.Bundle, txs []*value_transaction.ValueTransaction) { // signature are verified against the bundle hash - valid, _ := validateSignatures(b.GetBundleEssenceHash(), txs) + valid, err := validateSignatures(b.GetBundleEssenceHash(), txs) if !valid { - plugin.LogFailure("Invalid signature") + if err != nil { + log.Errorf("Invalid signature: %s", err.Error()) + } else { + log.Error("Invalid signature") + } } })) } diff --git a/plugins/webapi-gtta/plugin.go b/plugins/webapi-gtta/plugin.go index 73ee6f22..c873f7a4 100644 --- a/plugins/webapi-gtta/plugin.go +++ b/plugins/webapi-gtta/plugin.go @@ -4,9 +4,9 @@ import ( "net/http" "time" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/tipselection" "github.com/iotaledger/goshimmer/plugins/webapi" + "github.com/iotaledger/hive.go/node" "github.com/iotaledger/iota.go/trinary" "github.com/labstack/echo" ) diff --git a/plugins/webapi-spammer/plugin.go b/plugins/webapi-spammer/plugin.go index e40b962d..fb169eb8 100644 --- a/plugins/webapi-spammer/plugin.go +++ b/plugins/webapi-spammer/plugin.go @@ -4,9 +4,9 @@ import ( "net/http" "time" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/packages/transactionspammer" "github.com/iotaledger/goshimmer/plugins/webapi" + "github.com/iotaledger/hive.go/node" "github.com/labstack/echo" ) diff --git a/plugins/webapi/plugin.go b/plugins/webapi/plugin.go index 9bce5f6e..e73d1a09 100644 --- a/plugins/webapi/plugin.go +++ b/plugins/webapi/plugin.go @@ -2,15 +2,17 @@ package webapi import ( "context" + "github.com/iotaledger/hive.go/logger" "time" - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" "github.com/labstack/echo" ) var PLUGIN = node.NewPlugin("WebAPI", node.Enabled, configure, run) +var log = logger.NewLogger("WebAPI") var Server = echo.New() @@ -20,25 +22,25 @@ func configure(plugin *node.Plugin) { Server.GET("/", IndexRequest) daemon.Events.Shutdown.Attach(events.NewClosure(func() { - plugin.LogInfo("Stopping Web Server ...") + log.Info("Stopping Web Server ...") ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) defer cancel() if err := Server.Shutdown(ctx); err != nil { - plugin.LogFailure(err.Error()) + log.Errorf("Couldn't stop server cleanly: %s", err.Error()) } })) } func run(plugin *node.Plugin) { - plugin.LogInfo("Starting Web Server ...") + log.Info("Starting Web Server ...") daemon.BackgroundWorker("WebAPI Server", func() { - plugin.LogSuccess("Starting Web Server ... done") + log.Info("Starting Web Server ... done") if err := Server.Start(":8080"); err != nil { - plugin.LogSuccess("Stopping Web Server ... done") + log.Info("Stopping Web Server ... done") } }) } diff --git a/plugins/webauth/webauth.go b/plugins/webauth/webauth.go index 805590dc..b8e11814 100644 --- a/plugins/webauth/webauth.go +++ b/plugins/webauth/webauth.go @@ -6,9 +6,9 @@ import ( "strings" "time" - "github.com/iotaledger/goshimmer/packages/daemon" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/webapi" + "github.com/iotaledger/hive.go/daemon" + "github.com/iotaledger/hive.go/node" "github.com/labstack/echo" "github.com/labstack/echo/middleware" diff --git a/plugins/zeromq/plugin.go b/plugins/zeromq/plugin.go index ce8ad4c0..b3355ea0 100644 --- a/plugins/zeromq/plugin.go +++ b/plugins/zeromq/plugin.go @@ -1,21 +1,22 @@ package zeromq import ( + "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/parameter" "strconv" "strings" "time" - "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/tangle" + "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/node" ) // zeromq logging is disabled by default var PLUGIN = node.NewPlugin("ZeroMQ", node.Disabled, configure, run) - +var log = logger.NewLogger("ZeroMQ") var publisher *Publisher var emptyTag = strings.Repeat("9", 27) @@ -23,12 +24,12 @@ var emptyTag = strings.Repeat("9", 27) func configure(plugin *node.Plugin) { daemon.Events.Shutdown.Attach(events.NewClosure(func() { - plugin.LogInfo("Stopping ZeroMQ Publisher ...") + log.Info("Stopping ZeroMQ Publisher ...") if err := publisher.Shutdown(); err != nil { - plugin.LogFailure("Stopping ZeroMQ Publisher: " + err.Error()) + log.Errorf("Stopping ZeroMQ Publisher: %s", err.Error()) } else { - plugin.LogSuccess("Stopping ZeroMQ Publisher ... done") + log.Info("Stopping ZeroMQ Publisher ... done") } })) @@ -36,7 +37,7 @@ func configure(plugin *node.Plugin) { // create goroutine for every event go func() { if err := publishTx(tx); err != nil { - plugin.LogFailure(err.Error()) + log.Errorf("error publishing tx: %s", err.Error()) } }() })) @@ -44,14 +45,14 @@ func configure(plugin *node.Plugin) { // Start the zeromq plugin func run(plugin *node.Plugin) { - zeromqPort := parameter.NodeConfig.GetString(ZEROMQ_PORT) - plugin.LogInfo("Starting ZeroMQ Publisher (port " + zeromqPort + ") ...") + zeromqPort := parameter.NodeConfig.GetInt(ZEROMQ_PORT) + log.Infof("Starting ZeroMQ Publisher (port %d) ...", zeromqPort) daemon.BackgroundWorker("ZeroMQ Publisher", func() { if err := startPublisher(plugin); err != nil { - plugin.LogFailure("Stopping ZeroMQ Publisher: " + err.Error()) + log.Errorf("Stopping ZeroMQ Publisher: %s", err.Error()) } else { - plugin.LogSuccess("Starting ZeroMQ Publisher (port " + zeromqPort + ") ... done") + log.Infof("Starting ZeroMQ Publisher (port %d) ... done", zeromqPort) } }) } -- GitLab