From cccc3d9c86738dbb98fe8aa68b8e6bbb95f69494 Mon Sep 17 00:00:00 2001 From: Moses Narrow Date: Sun, 14 Aug 2022 19:02:47 -0500 Subject: [PATCH 1/5] service discovery query filtering for vpn servers --- cmd/skywire-cli/commands/vpn/vvpn.go | 28 +------------------ pkg/servicedisc/autoconnect.go | 3 +- pkg/servicedisc/client.go | 41 +++++++++++----------------- pkg/visor/api.go | 9 ++---- pkg/visor/rpc.go | 8 ++---- pkg/visor/rpc_client.go | 13 +++------ 6 files changed, 27 insertions(+), 75 deletions(-) diff --git a/cmd/skywire-cli/commands/vpn/vvpn.go b/cmd/skywire-cli/commands/vpn/vvpn.go index 8d65268140..80a2b52b79 100644 --- a/cmd/skywire-cli/commands/vpn/vvpn.go +++ b/cmd/skywire-cli/commands/vpn/vvpn.go @@ -15,7 +15,6 @@ import ( clirpc "github.com/skycoin/skywire/cmd/skywire-cli/commands/rpc" "github.com/skycoin/skywire/cmd/skywire-cli/internal" "github.com/skycoin/skywire/pkg/app/appserver" - "github.com/skycoin/skywire/pkg/servicedisc" "github.com/skycoin/skywire/pkg/visor/visorconfig" ) @@ -104,35 +103,10 @@ var vpnListCmd = &cobra.Command{ ver = "" country = "" } - // servers, err := client.VPNServers(ver, country) //query filtering - servers, err := client.VPNServers() + servers, err := client.VPNServers(ver, country) if err != nil { logger.Fatal("Failed to connect; is skywire running?\n", err) } - - /*vv remove when query filtering is implemented vv*/ - var a []servicedisc.Service - for _, i := range servers { - if (ver == "") || (ver == "unknown") || (strings.Replace(i.Version, "v", "", 1) == ver) { - a = append(a, i) - } - } - if len(a) > 0 { - servers = a - a = []servicedisc.Service{} - } - if country != "" { - for _, i := range servers { - if i.Geo != nil { - if i.Geo.Country == country { - a = append(a, i) - } - } - } - servers = a - } - /*^^ remove when query filtering is implemented ^^*/ - if len(servers) == 0 { fmt.Printf("No VPN Servers found\n") os.Exit(0) diff --git a/pkg/servicedisc/autoconnect.go b/pkg/servicedisc/autoconnect.go index 4761c8e20a..63399c78bf 100644 --- a/pkg/servicedisc/autoconnect.go +++ b/pkg/servicedisc/autoconnect.go @@ -113,8 +113,7 @@ func (a *autoconnector) fetchPubAddresses(ctx context.Context) ([]cipher.PubKey, var services []Service fetch := func() (err error) { // "return" services up from the closure - //services, err = a.client.Services(ctx, a.maxConns, "", "") //query filtering - services, err = a.client.Services(ctx, a.maxConns) + services, err = a.client.Services(ctx, a.maxConns, "", "") if err != nil { return err } diff --git a/pkg/servicedisc/client.go b/pkg/servicedisc/client.go index d54986fc1d..0a0061635b 100644 --- a/pkg/servicedisc/client.go +++ b/pkg/servicedisc/client.go @@ -26,12 +26,11 @@ import ( var ErrVisorUnreachable = errors.New("visor is unreachable") const ( - updateRetryDelay = 5 * time.Second - discServiceTypeParam = "type" - discServiceQtyParam = "quantity" - -// discServiceCountryParam = "country" //query filtering -// discServiceVersionParam = "version" //query filtering + updateRetryDelay = 5 * time.Second + discServiceTypeParam = "type" + discServiceQtyParam = "quantity" + discServiceCountryParam = "country" + discServiceVersionParam = "version" ) // Config configures the HTTPClient. @@ -70,8 +69,7 @@ func NewClient(log logrus.FieldLogger, mLog *logging.MasterLogger, conf Config, } } -func (c *HTTPClient) addr(path, serviceType string, quantity int) (string, error) { - //func (c *HTTPClient) addr(path, serviceType, version, country string, quantity int) (string, error) { //query filtering +func (c *HTTPClient) addr(path, serviceType, version, country string, quantity int) (string, error) { addr := c.conf.DiscAddr url, err := url.Parse(addr) if err != nil { @@ -85,15 +83,12 @@ func (c *HTTPClient) addr(path, serviceType string, quantity int) (string, error if quantity > 1 { q.Set(discServiceQtyParam, strconv.Itoa(quantity)) } - //query filtering - /* - if version != "" { - q.Set(discServiceVersionParam, version) - } - if country != "" { - q.Set(discServiceCountryParam, country) - } - */ + if version != "" { + q.Set(discServiceVersionParam, version) + } + if country != "" { + q.Set(discServiceCountryParam, country) + } url.RawQuery = q.Encode() return url.String(), nil } @@ -124,10 +119,8 @@ func (c *HTTPClient) Auth(ctx context.Context) (*httpauth.Client, error) { } // Services calls 'GET /api/services'. -func (c *HTTPClient) Services(ctx context.Context, quantity int) (out []Service, err error) { - //func (c *HTTPClient) Services(ctx context.Context, quantity int, version, country string) (out []Service, err error) { //query filtering - //url, err := c.addr("/api/services", c.entry.Type, version, country, quantity) - url, err := c.addr("/api/services", c.entry.Type, quantity) +func (c *HTTPClient) Services(ctx context.Context, quantity int, version, country string) (out []Service, err error) { + url, err := c.addr("/api/services", c.entry.Type, version, country, quantity) if err != nil { return nil, err } @@ -202,8 +195,7 @@ func (c *HTTPClient) postEntry(ctx context.Context) (Service, error) { return Service{}, err } - // url, err := c.addr("/api/services", "", "", "", 1) //query filtering - url, err := c.addr("/api/services", "", 1) + url, err := c.addr("/api/services", "", "", "", 1) if err != nil { return Service{}, nil } @@ -260,8 +252,7 @@ func (c *HTTPClient) DeleteEntry(ctx context.Context) (err error) { return err } - // url, err := c.addr("/api/services/"+c.entry.Addr.String(), c.entry.Type, "", "", 1) //query filtering - url, err := c.addr("/api/services/"+c.entry.Addr.String(), c.entry.Type, 1) + url, err := c.addr("/api/services/"+c.entry.Addr.String(), c.entry.Type, "", "", 1) if err != nil { return err } diff --git a/pkg/visor/api.go b/pkg/visor/api.go index 6d843b2984..f0a8e771cf 100644 --- a/pkg/visor/api.go +++ b/pkg/visor/api.go @@ -55,8 +55,7 @@ type API interface { GetAppStats(appName string) (appserver.AppStats, error) GetAppError(appName string) (string, error) GetAppConnectionsSummary(appName string) ([]appserver.ConnectionSummary, error) - // VPNServers(version, country string) ([]servicedisc.Service, error) //query filtering - VPNServers() ([]servicedisc.Service, error) + VPNServers(version, country string) ([]servicedisc.Service, error) RemoteVisors() ([]string, error) TransportTypes() ([]string, error) @@ -624,8 +623,7 @@ func (v *Visor) GetAppConnectionsSummary(appName string) ([]appserver.Connection } // VPNServers gets available public VPN server from service discovery URL -func (v *Visor) VPNServers() ([]servicedisc.Service, error) { - //func (v *Visor) VPNServers(version, country string) ([]servicedisc.Service, error) { //query filtering +func (v *Visor) VPNServers(version, country string) ([]servicedisc.Service, error) { log := logging.MustGetLogger("vpnservers") vlog := logging.NewMasterLogger() vlog.SetLevel(logrus.InfoLevel) @@ -636,8 +634,7 @@ func (v *Visor) VPNServers() ([]servicedisc.Service, error) { SK: v.conf.SK, DiscAddr: v.conf.Launcher.ServiceDisc, }, &http.Client{Timeout: time.Duration(1) * time.Second}, "") - // vpnServers, err := sdClient.Services(context.Background(), 0, version, country) //query filtering - vpnServers, err := sdClient.Services(context.Background(), 0) + vpnServers, err := sdClient.Services(context.Background(), 0, version, country) if err != nil { v.log.Error("Error getting public vpn servers: ", err) return nil, err diff --git a/pkg/visor/rpc.go b/pkg/visor/rpc.go index 40dc85348e..b4705e66c9 100644 --- a/pkg/visor/rpc.go +++ b/pkg/visor/rpc.go @@ -556,20 +556,16 @@ func (r *RPC) SetPublicAutoconnect(pAc *bool, _ *struct{}) (err error) { return err } -/* //query filtering // FilterVPNServersIn is input for VPNServers type FilterVPNServersIn struct { Version string Country string } -*/ // VPNServers gets available public VPN server from service discovery URL -func (r *RPC) VPNServers(_ *struct{}, out *[]servicedisc.Service) (err error) { - //func (r *RPC) VPNServers(vc *FilterVPNServersIn, _ *struct{}, out *[]servicedisc.Service) (err error) { //query filtering +func (r *RPC) VPNServers(vc *FilterVPNServersIn, _ *struct{}, out *[]servicedisc.Service) (err error) { defer rpcutil.LogCall(r.log, "VPNServers", nil)(out, &err) - // vpnServers, err := r.visor.VPNServers(vc.Version, vc.Country) //query filtering - vpnServers, err := r.visor.VPNServers() + vpnServers, err := r.visor.VPNServers(vc.Version, vc.Country) if vpnServers != nil { *out = vpnServers } diff --git a/pkg/visor/rpc_client.go b/pkg/visor/rpc_client.go index d32fb774c2..db8a0bc3c4 100644 --- a/pkg/visor/rpc_client.go +++ b/pkg/visor/rpc_client.go @@ -409,16 +409,12 @@ type StatusMessage struct { } // VPNServers calls VPNServers. -func (rc *rpcClient) VPNServers() ([]servicedisc.Service, error) { - //func (rc *rpcClient) VPNServers(version, country string) ([]servicedisc.Service, error) { //query filtering +func (rc *rpcClient) VPNServers(version, country string) ([]servicedisc.Service, error) { output := []servicedisc.Service{} - /* //query filtering - rc.Call("VPNServers", &FilterVPNServersIn{ + rc.Call("VPNServers", &FilterVPNServersIn{ // nolint Version: version, Country: country, - }, &output) // nolint - */ - rc.Call("VPNServers", &struct{}{}, &output) // nolint + }, &output) return output, nil } @@ -982,8 +978,7 @@ func (mc *mockRPCClient) GetPersistentTransports() ([]transport.PersistentTransp } // VPNServers implements API -func (mc *mockRPCClient) VPNServers() ([]servicedisc.Service, error) { - //func (mc *mockRPCClient) VPNServers(_, _ string) ([]servicedisc.Service, error) { //query filtering +func (mc *mockRPCClient) VPNServers(_, _ string) ([]servicedisc.Service, error) { return []servicedisc.Service{}, nil } From 265997cfe75328959bbfa5408b426f8fde4a50ff Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Mon, 15 Aug 2022 17:23:17 +0430 Subject: [PATCH 2/5] fix VPNServer rpc request issue --- cmd/skywire-cli/commands/vpn/vvpn.go | 2 +- pkg/visor/rpc.go | 2 +- pkg/visor/rpc_client.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/skywire-cli/commands/vpn/vvpn.go b/cmd/skywire-cli/commands/vpn/vvpn.go index 80a2b52b79..768c18c240 100644 --- a/cmd/skywire-cli/commands/vpn/vvpn.go +++ b/cmd/skywire-cli/commands/vpn/vvpn.go @@ -142,7 +142,7 @@ var vpnStartCmd = &cobra.Command{ Short: "start the vpn for ", Args: cobra.MinimumNArgs(1), Run: func(_ *cobra.Command, args []string) { - fmt.Println("%s", args[0]) + fmt.Println(args[0]) internal.Catch(clirpc.Client().StartVPNClient(args[0])) fmt.Println("OK") }, diff --git a/pkg/visor/rpc.go b/pkg/visor/rpc.go index b4705e66c9..37a12e69b2 100644 --- a/pkg/visor/rpc.go +++ b/pkg/visor/rpc.go @@ -563,7 +563,7 @@ type FilterVPNServersIn struct { } // VPNServers gets available public VPN server from service discovery URL -func (r *RPC) VPNServers(vc *FilterVPNServersIn, _ *struct{}, out *[]servicedisc.Service) (err error) { +func (r *RPC) VPNServers(vc *FilterVPNServersIn, out *[]servicedisc.Service) (err error) { defer rpcutil.LogCall(r.log, "VPNServers", nil)(out, &err) vpnServers, err := r.visor.VPNServers(vc.Version, vc.Country) if vpnServers != nil { diff --git a/pkg/visor/rpc_client.go b/pkg/visor/rpc_client.go index db8a0bc3c4..9670456f40 100644 --- a/pkg/visor/rpc_client.go +++ b/pkg/visor/rpc_client.go @@ -411,11 +411,11 @@ type StatusMessage struct { // VPNServers calls VPNServers. func (rc *rpcClient) VPNServers(version, country string) ([]servicedisc.Service, error) { output := []servicedisc.Service{} - rc.Call("VPNServers", &FilterVPNServersIn{ // nolint + err := rc.Call("VPNServers", &FilterVPNServersIn{ // nolint Version: version, Country: country, }, &output) - return output, nil + return output, err } // RemoteVisors calls RemoteVisors. From a49cad0c1c6696526fab726c04bf563826e1cc2f Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Mon, 15 Aug 2022 17:25:19 +0430 Subject: [PATCH 3/5] apply new changes to gui --- internal/gui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/gui/gui.go b/internal/gui/gui.go index fe876588e7..0364aa5ab2 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -303,7 +303,7 @@ func getAvailPublicVPNServers(conf *visorconfig.V1, httpC *http.Client, logger * DiscAddr: conf.Launcher.ServiceDisc, } sdClient := servicedisc.NewClient(log, log, svrConfig, httpC, "") - vpnServers, err := sdClient.Services(context.Background(), 0) + vpnServers, err := sdClient.Services(context.Background(), 0, "", "") if err != nil { logger.Error("Error getting vpn servers: ", err) return nil From 7ffba8e124167aa2f5c29d4e352ccf395f725577 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Mon, 15 Aug 2022 17:30:52 +0430 Subject: [PATCH 4/5] fix error message --- cmd/skywire-cli/commands/vpn/vvpn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/skywire-cli/commands/vpn/vvpn.go b/cmd/skywire-cli/commands/vpn/vvpn.go index 768c18c240..28392325cf 100644 --- a/cmd/skywire-cli/commands/vpn/vvpn.go +++ b/cmd/skywire-cli/commands/vpn/vvpn.go @@ -105,7 +105,7 @@ var vpnListCmd = &cobra.Command{ } servers, err := client.VPNServers(ver, country) if err != nil { - logger.Fatal("Failed to connect; is skywire running?\n", err) + logger.Fatal(err) } if len(servers) == 0 { fmt.Printf("No VPN Servers found\n") From cd809308f324ae55f905c859b0a18597b253f1cb Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 16 Aug 2022 10:55:06 +0430 Subject: [PATCH 5/5] fix AppVeyor issue --- .appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index e2c41a0f04..36b1d87630 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -12,7 +12,7 @@ environment: appveyor_build_worker_image: macos-bigsur GOARCH: amd64 - job_name: Windows - appveyor_build_worker_image: Visual Studio 2019 + appveyor_build_worker_image: Previous Visual Studio 2019 GOARCH: amd64 # For release, by pushing tag @@ -23,7 +23,7 @@ environment: appveyor_build_worker_image: macos-bigsur GOARCH: amd64 - job_name: make-release-windows - appveyor_build_worker_image: Visual Studio 2019 + appveyor_build_worker_image: Previous Visual Studio 2019 GOARCH: amd64 - job_name: DockerDeployMaster