Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve visor config and startup/shutdown logic. #360

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cmd/skywire-cli/commands/visor/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"text/tabwriter"
"time"

"github.com/SkycoinProject/skywire-mainnet/pkg/app/launcher"
evanlinjin marked this conversation as resolved.
Show resolved Hide resolved

"github.com/spf13/cobra"

"github.com/SkycoinProject/skywire-mainnet/cmd/skywire-cli/internal"
"github.com/SkycoinProject/skywire-mainnet/pkg/visor"
)

func init() {
Expand All @@ -38,10 +39,10 @@ var lsAppsCmd = &cobra.Command{

for _, state := range states {
status := "stopped"
if state.Status == visor.AppStatusRunning {
if state.Status == launcher.AppStatusRunning {
status = "running"
}
_, err = fmt.Fprintf(w, "%s\t%s\t%t\t%s\n", state.App, strconv.Itoa(int(state.Port)), state.AutoStart, status)
_, err = fmt.Fprintf(w, "%s\t%s\t%t\t%s\n", state.Name, strconv.Itoa(int(state.Port)), state.AutoStart, status)
internal.Catch(err)
}
internal.Catch(w.Flush())
Expand Down
156 changes: 10 additions & 146 deletions cmd/skywire-cli/commands/visor/gen-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import (
"path"
"path/filepath"

"github.com/SkycoinProject/skywire-mainnet/pkg/app/appcommon"
"github.com/SkycoinProject/skywire-mainnet/pkg/restart"
"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
"github.com/SkycoinProject/skywire-mainnet/pkg/skyenv"

"github.com/SkycoinProject/dmsg/cipher"
"github.com/spf13/cobra"

Expand All @@ -37,8 +32,10 @@ func init() {
genConfigCmd.Flags().StringVarP(&output, "output", "o", "", "path of output config file. Uses default of 'type' flag if unspecified.")
genConfigCmd.Flags().BoolVarP(&replace, "replace", "r", false, "whether to allow rewrite of a file that already exists.")
genConfigCmd.Flags().BoolVar(&retainKeys, "retain-keys", false, "retain current keys")
genConfigCmd.Flags().VarP(&configLocType, "type", "m", fmt.Sprintf("config generation mode. Valid values: %v", pathutil.AllConfigLocationTypes()))
genConfigCmd.Flags().BoolVarP(&testenv, "testing-environment", "t", false, "whether to use production or test deployment service.")

// TODO(evanlinjin): Re-implement this at a later stage.
//genConfigCmd.Flags().VarP(&configLocType, "type", "m", fmt.Sprintf("config generation mode. Valid values: %v", pathutil.AllConfigLocationTypes()))
}

var genConfigCmd = &cobra.Command{
Expand All @@ -56,13 +53,15 @@ var genConfigCmd = &cobra.Command{
},
Run: func(_ *cobra.Command, _ []string) {
var conf *visor.Config

// TODO(evanlinjin): Decide whether we still need this feature in the future.
// https://github.com/SkycoinProject/skywire-mainnet/pull/360#discussion_r425080223
switch configLocType {
case pathutil.WorkingDirLoc:
conf = defaultConfig()
case pathutil.HomeLoc:
conf = homeConfig()
case pathutil.LocalLoc:
conf = localConfig()
var err error
if conf, err = visor.DefaultConfig(nil, output, visor.NewKeyPair()); err != nil {
evanlinjin marked this conversation as resolved.
Show resolved Hide resolved
logger.WithError(err).Fatal("Failed to create default config.")
}
default:
logger.Fatalln("invalid config type:", configLocType)
}
Expand Down Expand Up @@ -90,138 +89,3 @@ func fillInOldKeys(confPath string, conf *visor.Config) error {

return nil
}

func homeConfig() *visor.Config {
c := defaultConfig()
c.AppsPath = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/apps")
c.Transport.LogStore.Location = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/transport_logs")
return c
}

func localConfig() *visor.Config {
c := defaultConfig()
c.AppsPath = "/usr/local/skycoin/skywire/apps"
c.Transport.LogStore.Location = "/usr/local/skycoin/skywire/transport_logs"
return c
}

func defaultConfig() *visor.Config {
conf := &visor.Config{}

if sk.Null() {
conf.KeyPair = visor.NewKeyPair()
} else {
conf.KeyPair = visor.RestoreKeyPair(sk)
}

stcp, err := visor.DefaultSTCPConfig()
if err != nil {
logger.Warn(err)
} else {
conf.STCP = stcp
}

conf.Dmsg = visor.DefaultDmsgConfig()

ptyConf := defaultDmsgPtyConfig()
conf.DmsgPty = &ptyConf

// TODO(evanlinjin): We have disabled skysocks passcode by default for now - We should make a cli arg for this.
//passcode := base64.StdEncoding.Strict().EncodeToString(cipher.RandByte(8))
conf.Apps = []visor.AppConfig{
defaultSkychatConfig(),
defaultSkysocksConfig(""),
defaultSkysocksClientConfig(),
defaultVPNServerConfig(),
defaultVPNClientConfig(),
}

conf.TrustedVisors = []cipher.PubKey{}

conf.Transport = visor.DefaultTransportConfig()
conf.Routing = visor.DefaultRoutingConfig()

conf.Hypervisors = []visor.HypervisorConfig{}

conf.UptimeTracker = visor.DefaultUptimeTrackerConfig()

conf.AppDiscovery = visor.DefaultAppDiscConfig()

conf.AppsPath = visor.DefaultAppsPath
conf.LocalPath = visor.DefaultLocalPath

conf.LogLevel = visor.DefaultLogLevel
conf.ShutdownTimeout = visor.DefaultTimeout

conf.Interfaces = &visor.InterfaceConfig{
RPCAddress: "localhost:3435",
}

conf.AppServerAddr = appcommon.DefaultAppSrvAddr
conf.RestartCheckDelay = restart.DefaultCheckDelay.String()

if testenv {
conf.Dmsg.Discovery = skyenv.TestDmsgDiscAddr
conf.Transport.Discovery = skyenv.TestTpDiscAddr
conf.Routing.RouteFinder = skyenv.TestRouteFinderAddr
conf.Routing.SetupNodes = []cipher.PubKey{skyenv.MustPK(skyenv.TestSetupPK)}
conf.AppDiscovery.ProxyDisc = skyenv.TestProxyDiscAddr
}

return conf
}

func defaultDmsgPtyConfig() visor.DmsgPtyConfig {
return visor.DmsgPtyConfig{
Port: skyenv.DmsgPtyPort,
AuthFile: "./skywire/dmsgpty/whitelist.json",
CLINet: skyenv.DefaultDmsgPtyCLINet,
CLIAddr: skyenv.DefaultDmsgPtyCLIAddr,
}
}

func defaultSkychatConfig() visor.AppConfig {
return visor.AppConfig{
App: skyenv.SkychatName,
AutoStart: true,
Port: routing.Port(skyenv.SkychatPort),
Args: []string{"-addr", skyenv.SkychatAddr},
}
}

func defaultSkysocksConfig(passcode string) visor.AppConfig {
var args []string
if passcode != "" {
args = []string{"-passcode", passcode}
}
return visor.AppConfig{
App: skyenv.SkysocksName,
AutoStart: true,
Port: routing.Port(skyenv.SkysocksPort),
Args: args,
}
}

func defaultSkysocksClientConfig() visor.AppConfig {
return visor.AppConfig{
App: skyenv.SkysocksClientName,
AutoStart: false,
Port: routing.Port(skyenv.SkysocksClientPort),
}
}

func defaultVPNServerConfig() visor.AppConfig {
return visor.AppConfig{
App: skyenv.VPNServerName,
AutoStart: true,
Port: routing.Port(skyenv.VPNServerPort),
}
}

func defaultVPNClientConfig() visor.AppConfig {
return visor.AppConfig{
App: skyenv.VPNClientName,
AutoStart: false,
Port: routing.Port(skyenv.VPNClientPort),
}
}
Loading