Skip to content

Commit

Permalink
Merge pull request #1003 from mrpalide/feature/local-servers
Browse files Browse the repository at this point in the history
Use local servers to generate config file
  • Loading branch information
jdknives authored Nov 17, 2021
2 parents 08e379b + d8bfd64 commit 6fcd7b1
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
46 changes: 46 additions & 0 deletions cmd/skywire-cli/commands/config/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
skybianConfig bool
hypervisor bool
hypervisorPKs string
dmsgHTTP bool
)

func init() {
Expand All @@ -43,6 +44,7 @@ func init() {
genConfigCmd.Flags().BoolVarP(&testEnv, "testenv", "t", false, "use test deployment service.")
genConfigCmd.Flags().BoolVarP(&hypervisor, "is-hypervisor", "i", false, "generate a hypervisor configuration.")
genConfigCmd.Flags().StringVar(&hypervisorPKs, "hypervisor-pks", "", "public keys of hypervisors that should be added to this visor")
genConfigCmd.Flags().BoolVarP(&dmsgHTTP, "dmsghttp", "d", false, "connect to Skywire Services via dmsg")
}

var genConfigCmd = &cobra.Command{
Expand Down Expand Up @@ -102,6 +104,36 @@ var genConfigCmd = &cobra.Command{
logger.WithError(err).Fatal("Failed to create config.")
}

// Use local servers
if dmsgHTTP {
var dmsgHTTPServersList dmsgHTTPServers
serversListJSON, err := ioutil.ReadFile("localServers.json")
if err != nil {
logger.WithError(err).Fatal("Failed to read servers.json file.")
}
err = json.Unmarshal(serversListJSON, &dmsgHTTPServersList)
if err != nil {
logger.WithError(err).Fatal("Error during parsing servers list")
}
if testEnv {
conf.Dmsg.Servers = dmsgHTTPServersList.Test.DMSGServers
conf.Dmsg.Discovery = dmsgHTTPServersList.Test.DMSGDiscovery
conf.Transport.AddressResolver = dmsgHTTPServersList.Test.AddressResolver
conf.Transport.Discovery = dmsgHTTPServersList.Test.TransportDiscovery
conf.UptimeTracker.Addr = dmsgHTTPServersList.Test.UptimeTracker
conf.Routing.RouteFinder = dmsgHTTPServersList.Test.RouteFinder
conf.Launcher.ServiceDisc = dmsgHTTPServersList.Test.ServiceDiscovery
} else {
conf.Dmsg.Servers = dmsgHTTPServersList.Prod.DMSGServers
conf.Dmsg.Discovery = dmsgHTTPServersList.Prod.DMSGDiscovery
conf.Transport.AddressResolver = dmsgHTTPServersList.Prod.AddressResolver
conf.Transport.Discovery = dmsgHTTPServersList.Prod.TransportDiscovery
conf.UptimeTracker.Addr = dmsgHTTPServersList.Prod.UptimeTracker
conf.Routing.RouteFinder = dmsgHTTPServersList.Prod.RouteFinder
conf.Launcher.ServiceDisc = dmsgHTTPServersList.Prod.ServiceDiscovery
}
}

// Read in old config (if any) and obtain old hypervisors.
if replaceHypervisors {
if oldConf, ok := readOldConfig(mLog, output, true); ok {
Expand Down Expand Up @@ -154,3 +186,17 @@ func readOldConfig(log *logging.MasterLogger, confPath string, replace bool) (*v

return conf, true
}

type dmsgHTTPServers struct {
Test dmsgHTTPServersData `json:"test"`
Prod dmsgHTTPServersData `json:"prod"`
}
type dmsgHTTPServersData struct {
DMSGServers []string `json:"dmsg_servers"`
DMSGDiscovery string `json:"dmsg_discovery"`
TransportDiscovery string `json:"transport_discovery"`
AddressResolver string `json:"address_resolver"`
RouteFinder string `json:"route_finder"`
UptimeTracker string `json:"uptime_tracker"`
ServiceDiscovery string `json:"service_discovery"`
}
28 changes: 28 additions & 0 deletions localServers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"test": {
"dmsg_servers": [
"ip:port",
"ip:port",
"ip:port"
],
"dmsg_discovery": "dmsg://pk:port",
"transport_discovery": "dmsg://pk:port",
"address_resolver": "dmsg://pk:port",
"route_finder": "dmsg://pk:port",
"uptime_tracker": "dmsg://pk:port",
"service_discovery": "dmsg://pk:port"
},
"prod": {
"dmsg_servers": [
"ip:port",
"ip:port",
"ip:port"
],
"dmsg_discovery": "dmsg://pk:port",
"transport_discovery": "dmsg://pk:port",
"address_resolver": "dmsg://pk:port",
"route_finder": "dmsg://pk:port",
"uptime_tracker": "dmsg://pk:port",
"service_discovery": "dmsg://pk:port"
}
}
5 changes: 3 additions & 2 deletions pkg/dmsgc/dmsgc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (

// DmsgConfig defines config for Dmsg network.
type DmsgConfig struct {
Discovery string `json:"discovery"`
SessionsCount int `json:"sessions_count"`
Discovery string `json:"discovery"`
SessionsCount int `json:"sessions_count"`
Servers []string `json:"servers"`
}

// New makes new dmsg client from configuration
Expand Down
1 change: 1 addition & 0 deletions pkg/visor/visorconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func MakeBaseConfig(common *Common) *V1 {
conf.Dmsg = &dmsgc.DmsgConfig{
Discovery: skyenv.DefaultDmsgDiscAddr,
SessionsCount: 1,
Servers: []string{},
}
conf.Transport = &V1Transport{
Discovery: skyenv.DefaultTpDiscAddr,
Expand Down

0 comments on commit 6fcd7b1

Please sign in to comment.