Skip to content

Commit

Permalink
Merge pull request #1069 from mrpalide/feature/best-protocol
Browse files Browse the repository at this point in the history
--best-protocol flag
  • Loading branch information
jdknives committed Jan 27, 2022
2 parents 5693c6b + b331fd9 commit ed3633e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- added `--os` flag to `skywire-cli config gen`
- added `--disable-apps` flag to `skywire-cli config gen`
- added `--disable-auth` and `--enable-auth` flags to `skywire-cli config gen`
- added `--best-protocol` flag to `skywire-cli config gen`
## 0.5.0

### Changed
Expand Down
25 changes: 25 additions & 0 deletions cmd/skywire-cli/commands/config/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package config

import (
"encoding/json"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -38,6 +40,7 @@ var (
enableAUTH bool
selectedOS string
disableApps string
bestProtocol bool
)

func init() {
Expand All @@ -56,6 +59,7 @@ func init() {
genConfigCmd.Flags().BoolVar(&enableAUTH, "enable-auth", false, "enable auth on hypervisor UI.")
genConfigCmd.Flags().StringVar(&selectedOS, "os", "linux", "generate configuration with paths for 'macos' or 'windows'")
genConfigCmd.Flags().StringVar(&disableApps, "disable-apps", "", "set list of apps to disable, separated by ','")
genConfigCmd.Flags().BoolVarP(&bestProtocol, "best-protocol", "b", false, "choose best protocol (dmsg / direct) to connect based on location")
}

var genConfigCmd = &cobra.Command{
Expand Down Expand Up @@ -140,6 +144,12 @@ var genConfigCmd = &cobra.Command{
}
}

if bestProtocol {
if dmsgProtocol() {
dmsgHTTP = true
}
}

// Use dmsg urls for services and add dmsg-servers
if dmsgHTTP {
var dmsgHTTPServersList visorconfig.DmsgHTTPServers
Expand Down Expand Up @@ -267,3 +277,18 @@ func readOldConfig(log *logging.MasterLogger, confPath string, replace bool) (*v

return conf, true
}

func dmsgProtocol() bool {
resp, err := http.Get("https://ipinfo.io/country")
if err != nil {
return false
}
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return false
}
if string(respBody)[:2] == "CN" {
return true
}
return false
}

0 comments on commit ed3633e

Please sign in to comment.