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

improve skywire-cli vpn subcommand #1389

Merged
merged 5 commits into from
Oct 17, 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
28 changes: 27 additions & 1 deletion cmd/skywire-cli/commands/vpn/vvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"
"text/tabwriter"
"time"

"github.com/spf13/cobra"
"github.com/toqueteos/webbrowser"
Expand Down Expand Up @@ -144,7 +145,32 @@ 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(), "OK", fmt.Sprintln("OK"))
internal.PrintOutput(cmd.Flags(), "Starting.", "Starting.")
startProcess := true
for startProcess {
time.Sleep(time.Second * 1)
internal.PrintOutput(cmd.Flags(), ".", ".")
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)
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!"))
}
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))
}
}
}
}
},
}

Expand Down
12 changes: 0 additions & 12 deletions dmsghttp-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
"server":{
"address":"139.162.45.141:8083"
}
},
{
"static":"02c5c21778c510f9bd29a54565db1ab20b9248804dce3d3fed171ae45a096f4037",
"server":{
"address":"194.147.142.202:30052"
}
}
],
"dmsg_discovery": "dmsg://03cd2336e5de74bdab2bbdb44b06b0c8c713a5ee9029615f5526f8c99a6afe87b8:80",
Expand Down Expand Up @@ -70,12 +64,6 @@
"server":{
"address":"dmsg.server02a4.skywire.skycoin.com:30089"
}
},
{
"static":"02113579604c79b704e169a4fd94fd78167b86fe40da1016f8146935babcc9abcb",
"server":{
"address":"194.147.142.202:30050"
}
}
],
"dmsg_discovery": "dmsg://022e607e0914d6e7ccda7587f95790c09e126bbd506cc476a1eda852325aadd1aa:80",
Expand Down
2 changes: 1 addition & 1 deletion pkg/visor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func (v *Visor) VPNServers(version, country string) ([]servicedisc.Service, erro
PK: v.conf.PK,
SK: v.conf.SK,
DiscAddr: v.conf.Launcher.ServiceDisc,
}, &http.Client{Timeout: time.Duration(1) * time.Second}, "")
}, &http.Client{Timeout: time.Duration(20) * time.Second}, "")
vpnServers, err := sdClient.Services(context.Background(), 0, version, country)
if err != nil {
v.log.Error("Error getting public vpn servers: ", err)
Expand Down
18 changes: 12 additions & 6 deletions pkg/visor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ func initTransportSetup(ctx context.Context, v *Visor, log *logging.Logger) erro
return nil
}

// getRouteSetupHooks aka autotransport
func getRouteSetupHooks(ctx context.Context, v *Visor, log *logging.Logger) []router.RouteSetupHook {
retrier := netutil.NewRetrier(log, time.Second, time.Second*20, 3, 1.3)
return []router.RouteSetupHook{
Expand All @@ -575,6 +576,9 @@ func getRouteSetupHooks(ctx context.Context, v *Visor, log *logging.Logger) []ro
dmsgFallback := func() error {
return retrier.Do(ctx, func() error {
_, err := tm.SaveTransport(ctx, rPK, network.DMSG, transport.LabelAutomatic)
if err != nil {
log.Debugf("Establishing automatic DMSG transport failed.")
}
return err
})
}
Expand All @@ -589,10 +593,6 @@ func getRouteSetupHooks(ctx context.Context, v *Visor, log *logging.Logger) []ro
log.WithField("pk", rPK.String()).Warn("pk not found in the transports")
// check if automatic transport is available, if it does,
// continue with route creation
if v.conf.Transport.PublicAutoconnect {
// we return nil here, router will use multi-hop STCPR rather than one hop DMSG
return nil
}
return dmsgFallback()
}
// try to establish direct connection to rPK (single hop) using SUDPH or STCPR
Expand Down Expand Up @@ -623,15 +623,21 @@ func getRouteSetupHooks(ctx context.Context, v *Visor, log *logging.Logger) []ro
_, err := tm.SaveTransport(ctx, rPK, network.STCPR, transport.LabelAutomatic)
return err
})
return err
if err == nil {
return nil
}
log.Debugf("Establishing automatic STCPR transport failed.")
}
// trying to establish direct connection to rPK using SUDPH
if trySUDPH {
err := retrier.Do(ctx, func() error {
_, err := tm.SaveTransport(ctx, rPK, network.SUDPH, transport.LabelAutomatic)
return err
})
return err
if err == nil {
return nil
}
log.Debugf("Establishing automatic SUDPH transport failed.")
}

return dmsgFallback()
Expand Down