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

Add display node ip field to the main config #1392

Merged
merged 8 commits into from
Oct 24, 2022
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: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `log_store` field to `transport` in config [#1386](https://github.com/skycoin/skywire/pull/1386)
- `type`, `location`, `rotation_interval`, field to `log_store` inside `transport` in config [#1374](https://github.com/skycoin/skywire/pull/1374)
- transport file logging to CSV [#1374](https://github.com/skycoin/skywire/pull/1374)
- transport file logging to CSV [#1374](https://github.com/skycoin/skywire/pull/1374)
- `skywire-cli config priv` & `skywire-cli visor priv` subcommands and rpc [#1369](https://github.com/skycoin/skywire/issues/1369)
- dmsghttp server [#1364](https://github.com/skycoin/skywire/issues/1364)
- `display_node_ip` field to `launcher` in config [#1392](https://github.com/skycoin/skywire/pull/1392)

### Changed
- moved `skywire-cli visor` subcommands into `skywire-cil visor hv` [#1390](https://github.com/skycoin/skywire/pull/1390)
Expand Down
4 changes: 4 additions & 0 deletions cmd/skywire-cli/commands/config/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func init() {
gHiddenFlags = append(gHiddenFlags, "hide")
genConfigCmd.Flags().BoolVarP(&isPublic, "public", "z", false, "publicize visor in service discovery")
gHiddenFlags = append(gHiddenFlags, "public")
genConfigCmd.Flags().BoolVar(&displayNodeIP, "publicip", false, "display node ip")
genConfigCmd.Flags().StringVar(&ver, "version", "", "custom version testing override")
gHiddenFlags = append(gHiddenFlags, "version")
genConfigCmd.Flags().BoolVar(&isAll, "all", false, "show all flags")
Expand Down Expand Up @@ -357,6 +358,9 @@ var genConfigCmd = &cobra.Command{
conf.IsPublic = true
}

if displayNodeIP {
conf.Launcher.DisplayNodeIP = true
}
//don't write file with stdout
if !isStdout {
// Save config to file.
Expand Down
3 changes: 0 additions & 3 deletions cmd/skywire-cli/commands/config/private.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
)

var (
displayNodeIP bool
rewardAddress string
)

Expand All @@ -23,7 +22,6 @@ func init() {
RootCmd.AddCommand(privacyConfigCmd)
privacyConfigCmd.AddCommand(setPrivacyConfigCmd)
privacyConfigCmd.AddCommand(getPrivacyConfigCmd)
setPrivacyConfigCmd.Flags().BoolVarP(&displayNodeIP, "publicip", "i", false, "display node ip")
// default is genesis address for skycoin blockchain ; for testing
setPrivacyConfigCmd.Flags().StringVarP(&rewardAddress, "address", "a", "2jBbGxZRGoQG1mqhPBnXnLTxK6oxsTf8os6", "reward address")

Expand Down Expand Up @@ -70,7 +68,6 @@ var setPrivacyConfigCmd = &cobra.Command{
}

confP := &privacyconfig.Privacy{
DisplayNodeIP: displayNodeIP,
RewardAddress: cAddr.String(),
}

Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var (
isUsr bool
isPublic bool
isPublicAutoConn bool
displayNodeIP bool
)

// RootCmd contains commands that interact with the config of local skywire-visor
Expand Down
4 changes: 1 addition & 3 deletions cmd/skywire-cli/commands/visor/privacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
)

var (
displayNodeIP bool
rewardAddress string
)

Expand All @@ -23,7 +22,6 @@ func init() {
privacyCmd.Flags().SortFlags = false
privacyCmd.AddCommand(setPrivacyCmd)
privacyCmd.AddCommand(getPrivacyCmd)
setPrivacyCmd.Flags().BoolVarP(&displayNodeIP, "publicip", "i", false, "display node ip")
// default is genesis address for skycoin blockchain ; for testing
setPrivacyCmd.Flags().StringVarP(&rewardAddress, "address", "a", "2jBbGxZRGoQG1mqhPBnXnLTxK6oxsTf8os6", "reward address")
}
Expand All @@ -46,7 +44,7 @@ var setPrivacyCmd = &cobra.Command{
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("invalid address specified: %v", err))
}

pConfig, err := client.SetPrivacy(&privacyconfig.Privacy{DisplayNodeIP: displayNodeIP, RewardAddress: cAddr.String()})
pConfig, err := client.SetPrivacy(&privacyconfig.Privacy{RewardAddress: cAddr.String()})
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Failed to connect: %v", err))
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/skywire-cli/commands/visor/transports.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ var lsTpCmd = &cobra.Command{
Long: "\n Available transports\n\n displays transports of the local visor",
Run: func(cmd *cobra.Command, _ []string) {
var pks cipher.PubKeys

internal.Catch(cmd.Flags(), pks.Set(strings.Join(filterPubKeys, ",")))
if filterPubKeys != nil {
internal.Catch(cmd.Flags(), pks.Set(strings.Join(filterPubKeys, ",")))
}
transports, err := clirpc.Client(cmd.Flags()).Transports(filterTypes, pks, showLogs)
internal.Catch(cmd.Flags(), err)
PrintTransports(cmd.Flags(), transports...)
Expand Down
26 changes: 16 additions & 10 deletions cmd/skywire-cli/commands/vpn/vvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,32 +147,38 @@ var vpnStartCmd = &cobra.Command{
var pk cipher.PubKey
internal.Catch(cmd.Flags(), pk.Set(args[0]))
internal.Catch(cmd.Flags(), clirpc.Client(cmd.Flags()).StartVPNClient(pk))
internal.PrintOutput(cmd.Flags(), "Starting.", "Starting.")
internal.PrintOutput(cmd.Flags(), nil, "Starting.")
startProcess := true
for startProcess {
time.Sleep(time.Second * 1)
internal.PrintOutput(cmd.Flags(), ".", ".")
internal.PrintOutput(cmd.Flags(), nil, ".")
states, err := clirpc.Client(cmd.Flags()).Apps()
internal.Catch(cmd.Flags(), err)

var b bytes.Buffer
w := tabwriter.NewWriter(&b, 0, 0, 5, ' ', tabwriter.TabIndent)
internal.Catch(cmd.Flags(), err)
type output struct {
CurrentIP string `json:"current_ip,omitempty"`
AppError string `json:"app_error,omitempty"`
}

for _, state := range states {
if state.Name == "vpn-client" {
if state.Status == appserver.AppStatusRunning {
startProcess = false
internal.Catch(cmd.Flags(), w.Flush())
internal.PrintOutput(cmd.Flags(), "\nRunning!", fmt.Sprintln("\nRunning!"))
internal.PrintOutput(cmd.Flags(), nil, fmt.Sprintln("\nRunning!"))
ip, err := visor.GetIP()
out := output{
CurrentIP: ip,
}
if err == nil {
internal.PrintOutput(cmd.Flags(), fmt.Sprintf("\nYour current IP: %s", ip), fmt.Sprintf("Your current IP: %s\n", ip))
internal.PrintOutput(cmd.Flags(), out, fmt.Sprintf("Your current IP: %s\n", ip))
}
}
if state.Status == appserver.AppStatusErrored {
startProcess = false
internal.Catch(cmd.Flags(), w.Flush())
internal.PrintOutput(cmd.Flags(), "\nError! > "+state.DetailedStatus, fmt.Sprintln("\nError! > "+state.DetailedStatus))
out := output{
AppError: state.DetailedStatus,
}
internal.PrintOutput(cmd.Flags(), out, fmt.Sprintln("\nError! > "+state.DetailedStatus))
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions cmd/skywire-cli/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ type CLIOutput struct {
func PrintOutput(cmdFlags *pflag.FlagSet, outputJSON, output interface{}) {
isJSON, _ := cmdFlags.GetBool(JSONString) //nolint:errcheck
if isJSON {
outputJSON := CLIOutput{
Output: outputJSON,
if outputJSON != nil {
outputJSON := CLIOutput{
Output: outputJSON,
}
b, err := json.MarshalIndent(outputJSON, "", " ")
if err != nil {
fmt.Println(err)
}
fmt.Print(string(b) + "\n")
}
b, err := json.MarshalIndent(outputJSON, "", " ")
if err != nil {
fmt.Println(err)
}
fmt.Print(string(b) + "\n")
return
}
if output != "" {
Expand Down
12 changes: 7 additions & 5 deletions pkg/app/appdisc/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Factory struct {
PK cipher.PubKey
SK cipher.SecKey
ServiceDisc string // Address of service-discovery
DisplayNodeIP bool
Client *http.Client
ClientPublicIP string
}
Expand All @@ -41,11 +42,12 @@ func (f *Factory) VisorUpdater(port uint16) Updater {
}

conf := servicedisc.Config{
Type: servicedisc.ServiceTypeVisor,
PK: f.PK,
SK: f.SK,
Port: port,
DiscAddr: f.ServiceDisc,
Type: servicedisc.ServiceTypeVisor,
PK: f.PK,
SK: f.SK,
Port: port,
DiscAddr: f.ServiceDisc,
DisplayNodeIP: f.DisplayNodeIP,
}

return &serviceUpdater{
Expand Down
11 changes: 6 additions & 5 deletions pkg/app/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ var (

// Config configures the launcher.
type Config struct {
VisorPK cipher.PubKey
Apps []appserver.AppConfig
ServerAddr string
BinPath string
LocalPath string
VisorPK cipher.PubKey
Apps []appserver.AppConfig
ServerAddr string
BinPath string
LocalPath string
DisplayNodeIP bool
}

// Launcher is responsible for launching and keeping track of app states.
Expand Down
18 changes: 10 additions & 8 deletions pkg/servicedisc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ const (

// Config configures the HTTPClient.
type Config struct {
Type string
PK cipher.PubKey
SK cipher.SecKey
Port uint16
DiscAddr string
Type string
PK cipher.PubKey
SK cipher.SecKey
Port uint16
DiscAddr string
DisplayNodeIP bool
}

// HTTPClient is responsible for interacting with the service-discovery
Expand All @@ -60,9 +61,10 @@ func NewClient(log logrus.FieldLogger, mLog *logging.MasterLogger, conf Config,
mLog: mLog,
conf: conf,
entry: Service{
Addr: NewSWAddr(conf.PK, conf.Port),
Type: conf.Type,
Version: buildinfo.Version(),
Addr: NewSWAddr(conf.PK, conf.Port),
Type: conf.Type,
Version: buildinfo.Version(),
DisplayNodeIP: conf.DisplayNodeIP,
},
client: client,
clientPublicIP: clientPublicIP,
Expand Down
17 changes: 9 additions & 8 deletions pkg/servicedisc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ func (a SWAddr) Value() (driver.Value, error) {

// Service represents a service entry in service-discovery.
type Service struct {
ID uint `json:"-" gorm:"primarykey"`
CreatedAt time.Time `json:"-"`
Addr SWAddr `json:"address"`
Type string `json:"type"`
Geo *geo.LocationData `json:"geo,omitempty" gorm:"embedded"`
Version string `json:"version,omitempty"`
LocalIPs pq.StringArray `json:"local_ips,omitempty" gorm:"type:text[]"`
Info *VPNInfo `json:"info,omitempty" gorm:"-"`
ID uint `json:"-" gorm:"primarykey"`
CreatedAt time.Time `json:"-"`
Addr SWAddr `json:"address"`
Type string `json:"type"`
Geo *geo.LocationData `json:"geo,omitempty" gorm:"embedded"`
DisplayNodeIP bool `json:"display_node_ip,omitempty"`
Version string `json:"version,omitempty"`
LocalIPs pq.StringArray `json:"local_ips,omitempty" gorm:"type:text[]"`
Info *VPNInfo `json:"info,omitempty" gorm:"-"`
}

// VPNInfo used for showing VPN metrics info, like latency, uptime and count of connections
Expand Down
9 changes: 5 additions & 4 deletions pkg/visor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,11 @@ func (v *Visor) VPNServers(version, country string) ([]servicedisc.Service, erro
vLog.SetLevel(logrus.InfoLevel)

sdClient := servicedisc.NewClient(log, vLog, servicedisc.Config{
Type: servicedisc.ServiceTypeVPN,
PK: v.conf.PK,
SK: v.conf.SK,
DiscAddr: v.conf.Launcher.ServiceDisc,
Type: servicedisc.ServiceTypeVPN,
PK: v.conf.PK,
SK: v.conf.SK,
DiscAddr: v.conf.Launcher.ServiceDisc,
DisplayNodeIP: v.conf.Launcher.DisplayNodeIP,
}, &http.Client{Timeout: time.Duration(20) * time.Second}, "")
vpnServers, err := sdClient.Services(context.Background(), 0, version, country)
if err != nil {
Expand Down
23 changes: 13 additions & 10 deletions pkg/visor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func initDiscovery(ctx context.Context, v *Visor, log *logging.Logger) error {
factory.PK = v.conf.PK
factory.SK = v.conf.SK
factory.ServiceDisc = conf.ServiceDisc
factory.DisplayNodeIP = conf.DisplayNodeIP
factory.Client = httpC
// only needed for dmsghttp
pIP, err := getPublicIP(v, conf.ServiceDisc)
Expand Down Expand Up @@ -709,11 +710,12 @@ func initLauncher(ctx context.Context, v *Visor, log *logging.Logger) error {

// Prepare launcher.
launchConf := launcher.Config{
VisorPK: v.conf.PK,
Apps: conf.Apps,
ServerAddr: conf.ServerAddr,
BinPath: conf.BinPath,
LocalPath: v.conf.LocalPath,
VisorPK: v.conf.PK,
Apps: conf.Apps,
ServerAddr: conf.ServerAddr,
BinPath: conf.BinPath,
LocalPath: v.conf.LocalPath,
DisplayNodeIP: conf.DisplayNodeIP,
}

launchLog := v.MasterLogger().PackageLogger("launcher")
Expand Down Expand Up @@ -1081,11 +1083,12 @@ func initPublicAutoconnect(ctx context.Context, v *Visor, log *logging.Logger) e
// advertising oneself and requires things like port that are not used
// in connecting to services
conf := servicedisc.Config{
Type: servicedisc.ServiceTypeVisor,
PK: v.conf.PK,
SK: v.conf.SK,
Port: uint16(0),
DiscAddr: serviceDisc,
Type: servicedisc.ServiceTypeVisor,
PK: v.conf.PK,
SK: v.conf.SK,
Port: uint16(0),
DiscAddr: serviceDisc,
DisplayNodeIP: v.conf.Launcher.DisplayNodeIP,
}
// only needed for dmsghttp
pIP, err := getPublicIP(v, serviceDisc)
Expand Down
1 change: 0 additions & 1 deletion pkg/visor/privacyconfig/privacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

// Privacy represents the json-encoded contents of the privacy.json file
type Privacy struct {
DisplayNodeIP bool `json:"display_node_ip"`
RewardAddress string `json:"reward_address,omitempty"`
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/visor/visorconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ func MakeBaseConfig(common *Common, testEnv bool, dmsgHTTP bool, services *Servi
RouteFinderTimeout: DefaultTimeout,
}
conf.Launcher = &Launcher{
ServiceDisc: services.ServiceDiscovery, //utilenv.ServiceDiscAddr,
Apps: nil,
ServerAddr: skyenv.AppSrvAddr,
BinPath: skyenv.AppBinPath,
ServiceDisc: services.ServiceDiscovery, //utilenv.ServiceDiscAddr,
Apps: nil,
ServerAddr: skyenv.AppSrvAddr,
BinPath: skyenv.AppBinPath,
DisplayNodeIP: false,
}
conf.UptimeTracker = &UptimeTracker{
Addr: services.UptimeTracker, //utilenv.UptimeTrackerAddr,
Expand Down
23 changes: 13 additions & 10 deletions pkg/visor/visorconfig/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ type UptimeTracker struct {

// Launcher configures the app appserver.
type Launcher struct {
ServiceDisc string `json:"service_discovery"`
Apps []appserver.AppConfig `json:"apps"`
ServerAddr string `json:"server_addr"`
BinPath string `json:"bin_path"`
ServiceDisc string `json:"service_discovery"`
Apps []appserver.AppConfig `json:"apps"`
ServerAddr string `json:"server_addr"`
BinPath string `json:"bin_path"`
DisplayNodeIP bool `json:"display_node_ip"`
}

// Flush flushes the config to file (if specified).
Expand Down Expand Up @@ -117,9 +118,10 @@ func (v1 *V1) UpdateAppAutostart(launch *launcher.Launcher, appName string, auto
}

launch.ResetConfig(launcher.Config{
VisorPK: v1.PK,
Apps: conf.Apps,
ServerAddr: conf.ServerAddr,
VisorPK: v1.PK,
Apps: conf.Apps,
ServerAddr: conf.ServerAddr,
DisplayNodeIP: conf.DisplayNodeIP,
})
return v1.flush(v1)
}
Expand Down Expand Up @@ -147,9 +149,10 @@ func (v1 *V1) UpdateAppArg(launch *launcher.Launcher, appName, argName string, v
}

launch.ResetConfig(launcher.Config{
VisorPK: v1.PK,
Apps: conf.Apps,
ServerAddr: conf.ServerAddr,
VisorPK: v1.PK,
Apps: conf.Apps,
ServerAddr: conf.ServerAddr,
DisplayNodeIP: conf.DisplayNodeIP,
})

return v1.flush(v1)
Expand Down