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

Config refactor #802

Merged
merged 4 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5k
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/skycoin/dmsg v0.0.0-20210603142231-3cba29fefe94 h1:pEXB812hRagn23n/SJQkFE/Pj0CJ1L5bA3qWSbUyC9M=
github.com/skycoin/dmsg v0.0.0-20210603142231-3cba29fefe94/go.mod h1:kd73tig/WUzBvcRmR7UwPi1JprzDDBUcSSBmF7RTJjo=
github.com/skycoin/dmsg v0.0.0-20210607131549-0c02e58ac5ee h1:amNDcQH4yce7nqs+P8RptKWhloC5q2upsQOk4YTXOKs=
github.com/skycoin/dmsg v0.0.0-20210607131549-0c02e58ac5ee/go.mod h1:kd73tig/WUzBvcRmR7UwPi1JprzDDBUcSSBmF7RTJjo=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 h1:1Nc5EBY6pjfw1kwW0duwyG+7WliWz5u9kgk1h5MnLuA=
Expand Down
14 changes: 5 additions & 9 deletions pkg/skyenv/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ const (
const (
DmsgPtyPort uint16 = 22

DefaultDmsgPtyCLINet = "unix"
DefaultDmsgPtyCLIAddr = "/tmp/dmsgpty.sock"
DefaultDmsgPtyWhitelist = DefaultSkywirePath + "/dmsgpty/whitelist.json"
PackageDmsgPtyWhiteList = PackageSkywirePath + "/dmsgpty/whitelist.json"
DefaultDmsgPtyCLINet = "unix"
DefaultDmsgPtyCLIAddr = "/tmp/dmsgpty.sock"
)

// Default STCP constants.
Expand Down Expand Up @@ -93,17 +91,15 @@ const (
const (
DefaultAppSrvAddr = "localhost:5505"
AppDiscUpdateInterval = time.Minute
DefaultAppLocalPath = DefaultSkywirePath + "/local"
DefaultAppBinPath = DefaultSkywirePath + "/apps"
DefaultLogLevel = "info"
PackageAppLocalPath = PackageSkywirePath + "/local"
PackageAppBinPath = PackageSkywirePath + "/apps"
)

// Default routing constants
// Default local constants
const (
DefaultTpLogStore = DefaultSkywirePath + "/transport_logs"
PackageTpLogStore = PackageSkywirePath + "/transport_logs"
DefaultLocalPath = DefaultSkywirePath + "/local"
PackageLocalPath = PackageSkywirePath + "/local"
)

// Default hypervisor constants
Expand Down
18 changes: 2 additions & 16 deletions pkg/visor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,28 +235,14 @@ func initDmsgCtrl(ctx context.Context, v *Visor, _ *logging.Logger) error {
}

func initTransport(ctx context.Context, v *Visor, log *logging.Logger) error {
conf := v.conf.Transport

tpdC, err := connectToTpDisc(v)
if err != nil {
err := fmt.Errorf("failed to create transport discovery client: %w", err)
return err
}

var logS transport.LogStore
switch conf.LogStore.Type {
case visorconfig.FileLogStore:
logS, err = transport.FileTransportLogStore(conf.LogStore.Location)
if err != nil {
err := fmt.Errorf("failed to create %s log store: %w", visorconfig.FileLogStore, err)
return err
}
case visorconfig.MemoryLogStore:
logS = transport.InMemoryTransportLogStore()
default:
err := fmt.Errorf("invalid log store type: %s", conf.LogStore.Type)
return err
}
logS := transport.InMemoryTransportLogStore()

tpMConf := transport.ManagerConfig{
PubKey: v.conf.PK,
Expand Down Expand Up @@ -402,7 +388,7 @@ func initLauncher(ctx context.Context, v *Visor, log *logging.Logger) error {
Apps: conf.Apps,
ServerAddr: conf.ServerAddr,
BinPath: conf.BinPath,
LocalPath: conf.LocalPath,
LocalPath: v.conf.LocalPath,
}

launchLog := v.MasterLogger().PackageLogger("launcher")
Expand Down
18 changes: 2 additions & 16 deletions pkg/visor/visorconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ func MakeBaseConfig(common *Common) *V1 {
conf.Transport = &V1Transport{
Discovery: skyenv.DefaultTpDiscAddr,
AddressResolver: skyenv.DefaultAddressResolverAddr,
LogStore: &V1LogStore{
Type: "memory",
},
}
conf.Routing = &V1Routing{
SetupNodes: []cipher.PubKey{skyenv.MustPK(skyenv.DefaultSetupPK)},
Expand All @@ -39,10 +36,10 @@ func MakeBaseConfig(common *Common) *V1 {
Apps: nil,
ServerAddr: skyenv.DefaultAppSrvAddr,
BinPath: skyenv.DefaultAppBinPath,
LocalPath: skyenv.DefaultAppLocalPath,
}
conf.CLIAddr = skyenv.DefaultRPCAddr
conf.LogLevel = skyenv.DefaultLogLevel
conf.LocalPath = skyenv.DefaultLocalPath
conf.ShutdownTimeout = DefaultTimeout
conf.RestartCheckDelay = Duration(restart.DefaultCheckDelay)
return conf
Expand Down Expand Up @@ -81,11 +78,6 @@ func defaultConfigFromCommon(cc *Common, hypervisor bool) (*V1, error) {
PKTable: nil,
}

conf.Transport.LogStore = &V1LogStore{
Type: "file",
Location: skyenv.DefaultTpLogStore,
}

conf.UptimeTracker = &V1UptimeTracker{
Addr: skyenv.DefaultUptimeTrackerAddr,
}
Expand Down Expand Up @@ -160,14 +152,8 @@ func MakePackageConfig(log *logging.MasterLogger, confPath string, sk *cipher.Se
CLINet: skyenv.DefaultDmsgPtyCLINet,
CLIAddr: skyenv.DefaultDmsgPtyCLIAddr,
}

conf.Transport.LogStore = &V1LogStore{
Type: "file",
Location: skyenv.PackageTpLogStore,
}

conf.LocalPath = skyenv.PackageLocalPath
conf.Launcher.BinPath = skyenv.PackageAppBinPath
conf.Launcher.LocalPath = skyenv.PackageAppLocalPath

if conf.Hypervisor != nil {
conf.Hypervisor.EnableAuth = skyenv.DefaultEnableAuth
Expand Down
9 changes: 2 additions & 7 deletions pkg/visor/visorconfig/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ func Parse(log *logging.MasterLogger, path string, raw []byte) (*V1, error) {

switch cc.Version {
// parse any v1-compatible version with v1 parse procedure
case V112Name:
fallthrough
case V111Name:
fallthrough
case V110Name:
fallthrough
case V100Name:
Expand All @@ -52,7 +48,6 @@ func Parse(log *logging.MasterLogger, path string, raw []byte) (*V1, error) {

func parseV1(cc *Common, raw []byte) (*V1, error) {
conf := MakeBaseConfig(cc)

dec := json.NewDecoder(bytes.NewReader(raw))
if err := dec.Decode(&conf); err != nil {
return nil, err
Expand All @@ -61,6 +56,7 @@ func parseV1(cc *Common, raw []byte) (*V1, error) {
if err := conf.ensureKeys(); err != nil {
return nil, fmt.Errorf("%v: %w", ErrInvalidSK, err)
}
conf.Version = V1Name
return conf, conf.flush(conf)
}

Expand Down Expand Up @@ -106,7 +102,6 @@ func parseV0(cc *Common, raw []byte) (*V1, error) {

if old.Transport != nil {
conf.Transport.Discovery = old.Transport.Discovery
conf.Transport.LogStore = old.Transport.LogStore
}

if old.Routing != nil {
Expand Down Expand Up @@ -142,8 +137,8 @@ func parseV0(cc *Common, raw []byte) (*V1, error) {

conf.Launcher.Apps = append(conf.Launcher.Apps, vpnApps...)

conf.LocalPath = old.LocalPath
conf.Launcher.BinPath = old.AppsPath
conf.Launcher.LocalPath = old.LocalPath
conf.Launcher.ServerAddr = old.AppServerAddr

for _, hv := range old.Hypervisors {
Expand Down
14 changes: 4 additions & 10 deletions pkg/visor/visorconfig/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,16 @@ const V100Name = "v1.0.0"

// V110Name is the semantic version string for v1.1.0.
// Added MinHops field to V1Routing section of config
const V110Name = "v1.1.0"

// V111Name is the semantic version string for v1.1.1.
// Removed public_trusted_visor field from root section
// Removed trusted_visors field from transport section
// Added is_public field to root section
// Added public_autoconnect field to transport section
const V111Name = "v1.1.1"

// V112Name is the semantic version string for v1.1.2.
// Added transport_setup_nodes field to transport section
const V112Name = "v1.1.2"
// Removed authorization_file field from dmsgpty section
const V110Name = "v1.1.0"

// V1Name is the semantic version string for the most recent version of V1.
const V1Name = V112Name
const V1Name = V110Name

// V1 is visor config
type V1 struct {
Expand All @@ -52,6 +47,7 @@ type V1 struct {
CLIAddr string `json:"cli_addr"`

LogLevel string `json:"log_level"`
LocalPath string `json:"local_path"`
ShutdownTimeout Duration `json:"shutdown_timeout,omitempty"` // time value, examples: 10s, 1m, etc
RestartCheckDelay Duration `json:"restart_check_delay,omitempty"` // time value, examples: 10s, 1m, etc
IsPublic bool `json:"is_public"`
Expand All @@ -70,7 +66,6 @@ type V1Dmsgpty struct {
type V1Transport struct {
Discovery string `json:"discovery"`
AddressResolver string `json:"address_resolver"`
LogStore *V1LogStore `json:"log_store"`
AutoconnectPublic bool `json:"public_autoconnect"`
TransportSetup []cipher.PubKey `json:"transport_setup_nodes"`
}
Expand Down Expand Up @@ -107,7 +102,6 @@ type V1Launcher struct {
Apps []launcher.AppConfig `json:"apps"`
ServerAddr string `json:"server_addr"`
BinPath string `json:"bin_path"`
LocalPath string `json:"local_path"`
}

// Flush flushes the config to file (if specified).
Expand Down