Skip to content

Commit

Permalink
Fix proxy start and proxy stop (#1757)
Browse files Browse the repository at this point in the history
* revert recent changes to proxy start and stop to restore functionality

* fix ci errors ; update check-cg makefile directive
  • Loading branch information
0pcom committed Mar 7, 2024
1 parent 6414c3f commit 9ff15a2
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 82 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,21 @@ commit:
check: lint check-cg test ## Run linters and tests

check-cg: ## Cursory check of the main help menu, offline dmsghttp config gen and offline config gen
@echo "checking help menu for compilation without errors"
@echo
go run cmd/skywire-deployment/skywire.go --help
@echo
@echo "checking dmsghttp offline config gen"
@echo
go run cmd/skywire-deployment/skywire.go cli config gen --nofetch -dnw
@echo
@echo "checking offline config gen"
@echo
go run cmd/skywire-deployment/skywire.go cli config gen --nofetch -nw
@echo
@echo "config gen succeeded without error"
@echo


check-windows: lint-windows test-windows ## Run linters and tests on windows image

Expand Down
50 changes: 16 additions & 34 deletions cmd/skywire-cli/commands/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/spf13/cobra"
"github.com/tidwall/pretty"

"github.com/skycoin/skywire-utilities/pkg/buildinfo"
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire-utilities/pkg/skyenv"
clirpc "github.com/skycoin/skywire/cmd/skywire-cli/commands/rpc"
Expand All @@ -31,11 +32,15 @@ func init() {
statusCmd,
listCmd,
)
version := buildinfo.Version()
if version == "unknown" {
version = "" //nolint
}
startCmd.Flags().StringVarP(&pk, "pk", "k", "", "server public key")
startCmd.Flags().StringVarP(&addr, "addr", "a", "", "address of proxy for use")
startCmd.Flags().StringVarP(&clientName, "name", "n", "", "name of skysocks client")
startCmd.Flags().IntVarP(&startingTimeout, "timeout", "t", 20, "starting timeout value in second")
startCmd.Flags().StringVarP(&httpProxy, "http-proxy", "p", "", "starting http-proxy based on skysocks")
stopCmd.Flags().BoolVar(&allClients, "all", false, "stop all skysocks client")
stopCmd.Flags().StringVar(&clientName, "name", "", "specific skysocks client that want stop")
}

var startCmd = &cobra.Command{
Expand All @@ -48,17 +53,6 @@ var startCmd = &cobra.Command{
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("unable to create RPC client: %w", err))
}

arguments := map[string]string{}
if pk != "" {
arguments["srv"] = pk
}
if addr != "" {
arguments["addr"] = addr
}
if httpProxy != "" {
arguments["http"] = httpProxy
}

if clientName != "" && pk != "" && addr != "" {
// add new app with -srv and -addr args, and if app was there just change -srv and -addr args and run it
err := pubkey.Set(pk)
Expand All @@ -73,6 +67,10 @@ var startCmd = &cobra.Command{
}
}

arguments := map[string]string{}
arguments["srv"] = pubkey.String()
arguments["addr"] = addr

_, err = rpcClient.App(clientName)
if err == nil {
err = rpcClient.DoCustomSetting(clientName, arguments)
Expand All @@ -92,10 +90,6 @@ var startCmd = &cobra.Command{
internal.Catch(cmd.Flags(), rpcClient.StartApp(clientName))
internal.PrintOutput(cmd.Flags(), nil, "Starting.")
} else if clientName != "" && pk == "" && addr == "" {
err = rpcClient.DoCustomSetting(clientName, arguments)
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Error occurs during set args to custom skysocks client"))
}
internal.Catch(cmd.Flags(), rpcClient.StartApp(clientName))
internal.PrintOutput(cmd.Flags(), nil, "Starting.")
} else if pk != "" && clientName == "" && addr == "" {
Expand All @@ -110,11 +104,7 @@ var startCmd = &cobra.Command{
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Invalid or missing public key"))
}
}
err = rpcClient.DoCustomSetting("skysocks-client", arguments)
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Error occurs during set args to custom skysocks client"))
}
internal.Catch(cmd.Flags(), rpcClient.StartApp("skysocks-client"))
internal.Catch(cmd.Flags(), rpcClient.StartSkysocksClient(pubkey.String()))
internal.PrintOutput(cmd.Flags(), nil, "Starting.")
clientName = "skysocks-client"
// change defaul skysocks-proxy app -srv arg and run it
Expand All @@ -123,11 +113,8 @@ var startCmd = &cobra.Command{
return
}

tCtc := context.Background() //nolint
if startingTimeout != 0 {
tCtc, _ = context.WithTimeout(context.Background(), time.Duration(startingTimeout)*time.Second) //nolint
}
ctx, cancel := cmdutil.SignalContext(tCtc, &logrus.Logger{})
ctx, cancel := cmdutil.SignalContext(context.Background(), &logrus.Logger{})
defer cancel()
go func() {
<-ctx.Done()
cancel()
Expand Down Expand Up @@ -165,14 +152,9 @@ var startCmd = &cobra.Command{
},
}

func init() {
stopCmd.Flags().BoolVar(&allClients, "all", false, "stop all skysocks client")
stopCmd.Flags().StringVar(&clientName, "name", "", "specific skysocks client that want stop")
}

var stopCmd = &cobra.Command{
Use: "stop",
Short: "stop the " + serviceType + " client" + "\nstop the default instance with:\n stop --name skysocks-client",
Short: "stop the " + serviceType + " client",
Run: func(cmd *cobra.Command, args []string) {
rpcClient, err := clirpc.Client(cmd.Flags())
if err != nil {
Expand Down Expand Up @@ -258,7 +240,7 @@ var isLabel bool

func init() {
if version == "unknown" {
version = ""
version = "" //nolint
}
version = strings.Split(version, "-")[0]
listCmd.Flags().StringVarP(&utURL, "uturl", "w", skyenv.UptimeTrackerAddr, "uptime tracker url")
Expand Down
45 changes: 23 additions & 22 deletions cmd/skywire-cli/commands/proxy/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,29 @@ import (
)

var (
version = buildinfo.Version()
binaryName = "skysocks-client"
stateName = "skysocks-client"
serviceType = servicedisc.ServiceTypeProxy
isUnFiltered bool
rawData bool
utURL string
sdURL string
cacheFileSD string
cacheFileUT string
cacheFilesAge int
ver string
country string
isStats bool
pubkey cipher.PubKey
pk string
allClients bool
noFilterOnline bool
clientName string
addr string
startingTimeout int
httpProxy string
version = buildinfo.Version()
binaryName = "skysocks-client"
stateName = "skysocks-client"
serviceType = servicedisc.ServiceTypeProxy
isUnFiltered bool
rawData bool
utURL string
sdURL string
cacheFileSD string
cacheFileUT string
cacheFilesAge int
ver string
country string
isStats bool
pubkey cipher.PubKey
pk string
allClients bool
noFilterOnline bool
clientName string
addr string

// startingTimeout int
// httpProxy string
)

// RootCmd contains commands that interact with the skywire-visor
Expand Down
52 changes: 26 additions & 26 deletions cmd/skywire-cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,32 @@ import (
"github.com/skycoin/skywire/cmd/skywire-cli/internal"
)

func init() {
RootCmd.AddCommand(
cliconfig.RootCmd,
clidmsgpty.RootCmd,
clivisor.RootCmd,
clivpn.RootCmd,
cliut.RootCmd,
cliskyfwd.RootCmd,
cliskyrev.RootCmd,
clireward.RootCmd,
clirewards.RootCmd,
clisurvey.RootCmd,
clirtfind.RootCmd,
clirtree.RootCmd,
climdisc.RootCmd,
clicompletion.RootCmd,
clilog.RootCmd,
cliskysocksc.RootCmd,
treeCmd,
docCmd,
)
var jsonOutput bool
RootCmd.PersistentFlags().BoolVar(&jsonOutput, internal.JSONString, false, "print output in json")
RootCmd.PersistentFlags().MarkHidden(internal.JSONString) //nolint
}

// RootCmd is the root command for skywire-cli
var RootCmd = &cobra.Command{
Use: func() string {
Expand Down Expand Up @@ -182,32 +208,6 @@ var docCmd = &cobra.Command{
},
}

func init() {
RootCmd.AddCommand(
cliconfig.RootCmd,
clidmsgpty.RootCmd,
clivisor.RootCmd,
clivpn.RootCmd,
cliut.RootCmd,
cliskyfwd.RootCmd,
cliskyrev.RootCmd,
clireward.RootCmd,
clirewards.RootCmd,
clisurvey.RootCmd,
clirtfind.RootCmd,
clirtree.RootCmd,
climdisc.RootCmd,
clicompletion.RootCmd,
clilog.RootCmd,
cliskysocksc.RootCmd,
treeCmd,
docCmd,
)
var jsonOutput bool
RootCmd.PersistentFlags().BoolVar(&jsonOutput, internal.JSONString, false, "print output in json")
RootCmd.PersistentFlags().MarkHidden(internal.JSONString) //nolint
}

// Execute executes root CLI command.
func Execute() {
if err := RootCmd.Execute(); err != nil {
Expand Down

0 comments on commit 9ff15a2

Please sign in to comment.