diff --git a/plugins/dashboard/drng_livefeed.go b/plugins/dashboard/drng_livefeed.go index abe3ce33c8ec677ed07a5ba8fb528b78a912eabb..bd65799d67a60bc89d0f541ebc14da9a317aefbc 100644 --- a/plugins/dashboard/drng_livefeed.go +++ b/plugins/dashboard/drng_livefeed.go @@ -4,13 +4,12 @@ import ( "encoding/hex" "time" - "github.com/iotaledger/hive.go/daemon" - "github.com/iotaledger/hive.go/events" - "github.com/iotaledger/hive.go/workerpool" - "github.com/iotaledger/goshimmer/packages/binary/drng/state" "github.com/iotaledger/goshimmer/packages/shutdown" "github.com/iotaledger/goshimmer/plugins/drng" + "github.com/iotaledger/hive.go/daemon" + "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/workerpool" ) var drngLiveFeedWorkerCount = 1 diff --git a/plugins/dashboard/explorer_routes.go b/plugins/dashboard/explorer_routes.go index f394901e7e1ad59f1f679aee82b2244be569f050..ab24c1d14b844a8d614b414913fe87e869a5c784 100644 --- a/plugins/dashboard/explorer_routes.go +++ b/plugins/dashboard/explorer_routes.go @@ -6,50 +6,60 @@ import ( "github.com/iotaledger/goshimmer/packages/binary/messagelayer/message" "github.com/iotaledger/goshimmer/plugins/messagelayer" - "github.com/labstack/echo" "github.com/pkg/errors" ) +// ExplorerMessage defines the struct of the ExplorerMessage. type ExplorerMessage struct { - Id string `json:"id"` - Timestamp uint `json:"timestamp"` - TrunkMessageId string `json:"trunk_message_id"` - BranchMessageId string `json:"branch_message_id"` - Solid bool `json:"solid"` + // ID is the message ID. + ID string `json:"id"` + // Timestamp is the timestamp of the message. + Timestamp uint `json:"timestamp"` + // TrunkMessageId is the Trunk ID of the message. + TrunkMessageID string `json:"trunk_message_id"` + // BranchMessageId is the Branch ID of the message. + BranchMessageID string `json:"branch_message_id"` + // Solid defines the solid status of the message. + Solid bool `json:"solid"` } func createExplorerMessage(msg *message.Message) (*ExplorerMessage, error) { - messageId := msg.Id() - messageMetadata := messagelayer.Tangle.MessageMetadata(messageId) + messageID := msg.Id() + messageMetadata := messagelayer.Tangle.MessageMetadata(messageID) t := &ExplorerMessage{ - Id: messageId.String(), + ID: messageID.String(), Timestamp: 0, - TrunkMessageId: msg.TrunkId().String(), - BranchMessageId: msg.BranchId().String(), + TrunkMessageID: msg.TrunkId().String(), + BranchMessageID: msg.BranchId().String(), Solid: messageMetadata.Unwrap().IsSolid(), } return t, nil } +// ExplorerAddress defines the struct of the ExplorerAddress. type ExplorerAddress struct { + // Messagess hold the list of *ExplorerMessage. Messages []*ExplorerMessage `json:"message"` } +// SearchResult defines the struct of the SearchResult. type SearchResult struct { + // Message is the *ExplorerMessage. Message *ExplorerMessage `json:"message"` + // Address is the *ExplorerAddress. Address *ExplorerAddress `json:"address"` } func setupExplorerRoutes(routeGroup *echo.Group) { routeGroup.GET("/message/:id", func(c echo.Context) (err error) { - messageId, err := message.NewId(c.Param("id")) + messageID, err := message.NewId(c.Param("id")) if err != nil { return } - t, err := findMessage(messageId) + t, err := findMessage(messageID) if err != nil { return } @@ -78,12 +88,12 @@ func setupExplorerRoutes(routeGroup *echo.Group) { go func() { defer wg.Done() - messageId, err := message.NewId(search) + messageID, err := message.NewId(search) if err != nil { return } - msg, err := findMessage(messageId) + msg, err := findMessage(messageID) if err == nil { result.Message = msg } @@ -102,11 +112,11 @@ func setupExplorerRoutes(routeGroup *echo.Group) { }) } -func findMessage(messageId message.Id) (explorerMsg *ExplorerMessage, err error) { - if !messagelayer.Tangle.Message(messageId).Consume(func(msg *message.Message) { +func findMessage(messageID message.Id) (explorerMsg *ExplorerMessage, err error) { + if !messagelayer.Tangle.Message(messageID).Consume(func(msg *message.Message) { explorerMsg, err = createExplorerMessage(msg) }) { - err = errors.Wrapf(ErrNotFound, "message: %s", messageId.String()) + err = errors.Wrapf(ErrNotFound, "message: %s", messageID.String()) } return diff --git a/plugins/dashboard/livefeed.go b/plugins/dashboard/livefeed.go index 8a23e24716e5eeb7abaac477e6eb6d5d8d303aa0..d005e500c39ce4e6f9c816fb11a6f2006aeebbd6 100644 --- a/plugins/dashboard/livefeed.go +++ b/plugins/dashboard/livefeed.go @@ -3,14 +3,13 @@ package dashboard import ( "time" - "github.com/iotaledger/hive.go/daemon" - "github.com/iotaledger/hive.go/events" - "github.com/iotaledger/hive.go/workerpool" - "github.com/iotaledger/goshimmer/packages/binary/messagelayer/message" "github.com/iotaledger/goshimmer/packages/binary/messagelayer/tangle" "github.com/iotaledger/goshimmer/packages/shutdown" "github.com/iotaledger/goshimmer/plugins/messagelayer" + "github.com/iotaledger/hive.go/daemon" + "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/workerpool" ) var liveFeedWorkerCount = 1 diff --git a/plugins/dashboard/parameters.go b/plugins/dashboard/parameters.go index 8ef57da91c5df4ae67d2da8dab39a2e2b9476c6b..ee74a3ec19304249f612dea675f4b16ea1c6c83f 100644 --- a/plugins/dashboard/parameters.go +++ b/plugins/dashboard/parameters.go @@ -5,17 +5,22 @@ import ( ) const ( - CFG_BIND_ADDRESS = "dashboard.bindAddress" - CFG_DEV = "dashboard.dev" - CFG_BASIC_AUTH_ENABLED = "dashboard.basic_auth.enabled" - CFG_BASIC_AUTH_USERNAME = "dashboard.basic_auth.username" - CFG_BASIC_AUTH_PASSWORD = "dashboard.basic_auth.password" + // CfgBindAddress defines the config flag of the dashboard binding address. + CfgBindAddress = "dashboard.bindAddress" + // CfgDev defines the config flag of the dashboard dev mode. + CfgDev = "dashboard.dev" + // CfgBasicAuthEnabled defines the config flag of the dashboard basic auth enabler. + CfgBasicAuthEnabled = "dashboard.basic_auth.enabled" + // CfgBasicAuthUsername defines the config flag of the dashboard basic auth username. + CfgBasicAuthUsername = "dashboard.basic_auth.username" + // CfgBasicAuthPassword defines the config flag of the dashboard basic auth password. + CfgBasicAuthPassword = "dashboard.basic_auth.password" ) func init() { - flag.String(CFG_BIND_ADDRESS, "127.0.0.1", "the bind address of the dashboard") - flag.Bool(CFG_DEV, false, "whether the dashboard runs in dev mode") - flag.Bool(CFG_BASIC_AUTH_ENABLED, false, "whether to enable HTTP basic auth") - flag.String(CFG_BASIC_AUTH_USERNAME, "goshimmer", "HTTP basic auth username") - flag.String(CFG_BASIC_AUTH_PASSWORD, "goshimmer", "HTTP basic auth password") + flag.String(CfgBindAddress, "127.0.0.1", "the bind address of the dashboard") + flag.Bool(CfgDev, false, "whether the dashboard runs in dev mode") + flag.Bool(CfgBasicAuthEnabled, false, "whether to enable HTTP basic auth") + flag.String(CfgBasicAuthUsername, "goshimmer", "HTTP basic auth username") + flag.String(CfgBasicAuthPassword, "goshimmer", "HTTP basic auth password") } diff --git a/plugins/dashboard/plugin.go b/plugins/dashboard/plugin.go index 2f91ea3d84fc95dbd2b1c62fb554d2c514dc9f12..91b9e6953e8b4e19ad76636f15ad99e836120aff 100644 --- a/plugins/dashboard/plugin.go +++ b/plugins/dashboard/plugin.go @@ -9,10 +9,6 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/iotaledger/hive.go/autopeering/peer/service" - "github.com/labstack/echo" - "github.com/labstack/echo/middleware" - "github.com/iotaledger/goshimmer/packages/shutdown" "github.com/iotaledger/goshimmer/plugins/autopeering" "github.com/iotaledger/goshimmer/plugins/autopeering/local" @@ -21,12 +17,14 @@ import ( "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/goshimmer/plugins/messagelayer" "github.com/iotaledger/goshimmer/plugins/metrics" - + "github.com/iotaledger/hive.go/autopeering/peer/service" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/workerpool" + "github.com/labstack/echo" + "github.com/labstack/echo/middleware" ) // PluginName is the name of the dashboard plugin. @@ -40,8 +38,8 @@ var ( nodeStartAt = time.Now() clientsMu sync.Mutex - clients = make(map[uint64]chan interface{}) - nextClientID uint64 = 0 + clients = make(map[uint64]chan interface{}) + nextClientID uint64 wsSendWorkerCount = 1 wsSendWorkerQueueSize = 250 @@ -90,10 +88,10 @@ func run(plugin *node.Plugin) { e.HideBanner = true e.Use(middleware.Recover()) - if config.Node.GetBool(CFG_BASIC_AUTH_ENABLED) { + if config.Node.GetBool(CfgBasicAuthEnabled) { e.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) { - if username == config.Node.GetString(CFG_BASIC_AUTH_USERNAME) && - password == config.Node.GetString(CFG_BASIC_AUTH_PASSWORD) { + if username == config.Node.GetString(CfgBasicAuthUsername) && + password == config.Node.GetString(CfgBasicAuthPassword) { return true, nil } return false, nil @@ -101,7 +99,7 @@ func run(plugin *node.Plugin) { } setupRoutes(e) - addr := config.Node.GetString(CFG_BIND_ADDRESS) + addr := config.Node.GetString(CfgBindAddress) log.Infof("You can now access the dashboard using: http://%s", addr) go e.Start(addr) @@ -130,11 +128,17 @@ var ( ) const ( + // MsgTypeNodeStatus is the type of the NodeStatus message. MsgTypeNodeStatus byte = iota + // MsgTypeMPSMetric is the type of the message per second (MPS) metric message. MsgTypeMPSMetric + // MsgTypeMessage is the type of the message. MsgTypeMessage + // MsgTypeNeighborMetric is the type of the NeighborMetric message. MsgTypeNeighborMetric + // MsgTypeDrng is the type of the dRNG message. MsgTypeDrng + // MsgTypeTipsMetric is the type of the TipsMetric message. MsgTypeTipsMetric ) @@ -144,7 +148,7 @@ type wsmsg struct { } type msg struct { - Id string `json:"id"` + ID string `json:"id"` Value int64 `json:"value"` } diff --git a/plugins/dashboard/routes.go b/plugins/dashboard/routes.go index 0e9d9f2419377f65faba07bde98aba98654c52ae..eb8f21a40cb75064230da675fcef2c00296804da 100644 --- a/plugins/dashboard/routes.go +++ b/plugins/dashboard/routes.go @@ -12,9 +12,16 @@ import ( "github.com/pkg/errors" ) +// ErrInvalidParameter defines the invalid parameter error. var ErrInvalidParameter = errors.New("invalid parameter") + +// ErrInternalError defines the internal error. var ErrInternalError = errors.New("internal error") + +// ErrNotFound defines the not found error. var ErrNotFound = errors.New("not found") + +// ErrForbidden defines the forbidden error. var ErrForbidden = errors.New("forbidden") // holds SPA assets @@ -22,7 +29,7 @@ var appBox = packr.New("Dashboard_App", "./frontend/build") var assetsBox = packr.New("Dashboard_Assets", "./frontend/src/assets") func indexRoute(e echo.Context) error { - if config.Node.GetBool(CFG_DEV) { + if config.Node.GetBool(CfgDev) { res, err := http.Get("http://127.0.0.1:9090/") if err != nil { return err