Skip to content

Commit

Permalink
Merge pull request #1077 from mysteriumnetwork/embed-web
Browse files Browse the repository at this point in the history
A UI for node is now available
  • Loading branch information
Waldz committed May 16, 2019
2 parents ac17bea + fa1a95c commit 7a4b172
Show file tree
Hide file tree
Showing 11 changed files with 413 additions and 2 deletions.
113 changes: 113 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Gopkg.toml
Expand Up @@ -113,3 +113,15 @@
[[constraint]]
revision = "f6122f5b2fbd92ace9b2819f0be4148be5690a1f"
name = "github.com/songgao/water"

[[constraint]]
version = "1.3.0"
name = "github.com/gin-contrib/cors"

[[constraint]]
version = "1.4.0"
name = "github.com/gin-gonic/gin"

[[constraint]]
version = "=0.0.1"
name = "github.com/mysteriumnetwork/go-dvpn-web"
22 changes: 21 additions & 1 deletion cmd/di.go
Expand Up @@ -73,6 +73,7 @@ import (
"github.com/mysteriumnetwork/node/session/promise/validators"
"github.com/mysteriumnetwork/node/tequilapi"
tequilapi_endpoints "github.com/mysteriumnetwork/node/tequilapi/endpoints"
"github.com/mysteriumnetwork/node/ui"
"github.com/mysteriumnetwork/node/utils"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -130,6 +131,12 @@ type CacheResolver interface {
HandleConnectionEvent(connection.StateEvent)
}

// UIServer represents our web server
type UIServer interface {
Serve() error
Stop()
}

// Dependencies is DI container for top level components which is reused in several places
type Dependencies struct {
Node *node.Node
Expand Down Expand Up @@ -172,6 +179,8 @@ type Dependencies struct {
PortPool *port.Pool

MetricsSender *metrics.Sender

UIServer UIServer
}

// Bootstrap initiates all container dependencies
Expand Down Expand Up @@ -207,6 +216,8 @@ func (di *Dependencies) Bootstrap(nodeOptions node.Options) error {
return err
}

di.bootstrapUIServer(nodeOptions.UI)

di.bootstrapMetrics(nodeOptions)

di.PortPool = port.NewPool()
Expand Down Expand Up @@ -302,6 +313,15 @@ func (di *Dependencies) bootstrapStorage(path string) error {
return nil
}

func (di *Dependencies) bootstrapUIServer(options node.OptionsUI) {
if options.UIEnabled {
di.UIServer = ui.NewServer(options.UIPort)
return
}

di.UIServer = ui.NewNoopServer()
}

func (di *Dependencies) subscribeEventConsumers() error {
// state events
err := di.EventBus.Subscribe(connection.SessionEventTopic, di.StatisticsTracker.ConsumeSessionEvent)
Expand Down Expand Up @@ -380,7 +400,7 @@ func (di *Dependencies) bootstrapNodeComponents(nodeOptions node.Options, listen
corsPolicy := tequilapi.NewMysteriumCorsPolicy()
httpAPIServer := tequilapi.NewServer(listener, router, corsPolicy)

di.Node = node.NewNode(di.ConnectionManager, httpAPIServer, di.EventBus, di.MetricsSender, di.NATPinger)
di.Node = node.NewNode(di.ConnectionManager, httpAPIServer, di.EventBus, di.MetricsSender, di.NATPinger, di.UIServer)
}

func newSessionManagerFactory(
Expand Down
2 changes: 2 additions & 0 deletions cmd/flags_node.go
Expand Up @@ -70,6 +70,7 @@ func RegisterFlagsNode(flags *[]cli.Flag) error {
RegisterFlagsNetwork(flags)
openvpn_core.RegisterFlags(flags)
RegisterFlagsLocation(flags)
RegisterFlagsUI(flags)

return nil
}
Expand All @@ -90,6 +91,7 @@ func ParseFlagsNode(ctx *cli.Context) node.Options {

Openvpn: wrapper{nodeOptions: openvpn_core.ParseFlags(ctx)},
Location: ParseFlagsLocation(ctx),
UI: ParseFlagsUI(ctx),
OptionsNetwork: ParseFlagsNetwork(ctx),
}
}
Expand Down
48 changes: 48 additions & 0 deletions cmd/flags_ui.go
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2019 The "MysteriumNetwork/node" Authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package cmd

import (
"github.com/mysteriumnetwork/node/core/node"
"github.com/urfave/cli"
)

var (
uiPortFlag = cli.IntFlag{
Name: "ui.port",
Usage: "the port to run ui on",
Value: 4449,
}
uiEnableFlag = cli.BoolFlag{
Name: "ui.enable",
Usage: "enables the ui",
}
)

// RegisterFlagsUI function register UI flags to flag list
func RegisterFlagsUI(flags *[]cli.Flag) {
*flags = append(*flags, uiPortFlag, uiEnableFlag)
}

// ParseFlagsUI function fills in UI options from CLI context
func ParseFlagsUI(ctx *cli.Context) node.OptionsUI {
return node.OptionsUI{
UIEnabled: ctx.GlobalBool(uiEnableFlag.Name),
UIPort: ctx.GlobalInt(uiPortFlag.Name),
}
}

0 comments on commit 7a4b172

Please sign in to comment.