From e264ec56920d267e515f528bd47eaa2f50a05d50 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Sat, 29 Jan 2022 08:05:12 +0330 Subject: [PATCH] revert deleted function --- internal/gui/gui.go | 23 +++++++++++++++++++++++ internal/gui/gui_test.go | 17 +++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/internal/gui/gui.go b/internal/gui/gui.go index 15a686a39b..111fe2c701 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -4,6 +4,7 @@ package gui import ( + "context" "embed" "fmt" "io" @@ -19,6 +20,7 @@ import ( "github.com/skycoin/skycoin/src/util/logging" "github.com/toqueteos/webbrowser" + "github.com/skycoin/skywire/pkg/servicedisc" "github.com/skycoin/skywire/pkg/skyenv" "github.com/skycoin/skywire/pkg/visor/visorconfig" ) @@ -190,6 +192,27 @@ func handleVPNLinkButton(conf *visorconfig.V1) { } } +// GetAvailPublicVPNServers gets all available public VPN server from service discovery URL +func GetAvailPublicVPNServers(conf *visorconfig.V1) []string { + sdClient := servicedisc.NewClient(log, servicedisc.Config{ + Type: servicedisc.ServiceTypeVPN, + PK: conf.PK, + SK: conf.SK, + DiscAddr: conf.Launcher.ServiceDisc, + }) + //ctx, _ := context.WithTimeout(context.Background(), 7*time.Second) + vpnServers, err := sdClient.Services(context.Background(), 0) + if err != nil { + log.Error("Error getting public vpn servers: ", err) + return nil + } + serverAddrs := make([]string, len(vpnServers)) + for idx, server := range vpnServers { + serverAddrs[idx] = server.Addr.PubKey().String() + } + return serverAddrs +} + func initUninstallBtn() { if !checkIsPackage() { mUninstall.Hide() diff --git a/internal/gui/gui_test.go b/internal/gui/gui_test.go index dc997d546a..f76f10c8bc 100644 --- a/internal/gui/gui_test.go +++ b/internal/gui/gui_test.go @@ -6,9 +6,26 @@ package gui import ( "testing" + "github.com/skycoin/dmsg/cipher" "github.com/stretchr/testify/require" + + "github.com/skycoin/skywire/pkg/visor/visorconfig" ) +func TestGetAvailPublicVPNServers(t *testing.T) { + pk, sk := cipher.GenerateKeyPair() + common := &visorconfig.Common{ + Version: "v1.1.0", + SK: sk, + PK: pk, + } + config := visorconfig.MakeBaseConfig(common) + servers := GetAvailPublicVPNServers(config) + require.NotEqual(t, nil, servers) + require.NotEqual(t, []string{}, servers) + t.Logf("Servers: %v", servers) +} + func TestReadEmbeddedIcon(t *testing.T) { b, err := ReadSysTrayIcon() require.NoError(t, err)