Skip to content

Commit

Permalink
Merge pull request #1780 from mrpalide/fix/some-little-issues-on-v1.3.20
Browse files Browse the repository at this point in the history
Fix some little issues before v1.3.20-rc1
  • Loading branch information
mrpalide authored Mar 21, 2024
2 parents 11dfbbb + dc625f1 commit c07e455
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 69 deletions.
11 changes: 1 addition & 10 deletions .goreleaser-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,11 @@ builds:
goarch:
- amd64
- 386
- arm64
env:
- CGO_ENABLED=1
main: ./cmd/skywire/
ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} -X github.com/skycoin/skywire/pkg/visor.BuildTag={{.Os}}
binary: apps/skysocks
goos:
- windows
goarch:
- amd64
- 386
env:
- CGO_ENABLED=0
main: ./cmd/apps/skysocks
ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}}


archives:
Expand Down
73 changes: 48 additions & 25 deletions cmd/apps/skysocks-client/commands/skysocks-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import (
"context"
"errors"
"fmt"
"io"
"log"
"net"
"net/http"
"net/url"
"os"
"os/signal"
"runtime"
"time"

"github.com/elazarl/goproxy"
ipc "github.com/james-barrow/golang-ipc"
"github.com/spf13/cobra"

"github.com/skycoin/skywire-utilities/pkg/buildinfo"
Expand Down Expand Up @@ -43,7 +45,6 @@ func init() {
RootCmd.Flags().StringVar(&addr, "addr", visorconfig.SkysocksClientAddr, "Client address to listen on")
RootCmd.Flags().StringVar(&serverPK, "srv", "", "PubKey of the server to connect to")
RootCmd.Flags().StringVar(&httpAddr, "http", "", "http proxy mode")

}

// RootCmd is the root command for skysocks
Expand Down Expand Up @@ -83,41 +84,63 @@ var RootCmd = &cobra.Command{
setAppErr(appCl, err)
os.Exit(1)
}

defer setAppStatus(appCl, appserver.AppDetailedStatusStopped)
setAppPort(appCl, appCl.Config().RoutingPort)
for {
conn, err := dialServer(ctx, appCl, pk)
if err != nil {
print(fmt.Sprintf("Failed to dial to a server: %v\n", err))
setAppErr(appCl, err)
os.Exit(1)
}

fmt.Printf("Connected to %v\n", pk)
client, err := skysocks.NewClient(conn, appCl)
conn, err := dialServer(ctx, appCl, pk)
if err != nil {
print(fmt.Sprintf("Failed to dial to a server: %v\n", err))
setAppErr(appCl, err)
os.Exit(1)
}

fmt.Printf("Connected to %v\n", pk)
client, err := skysocks.NewClient(conn, appCl)
if err != nil {
print(fmt.Sprintf("Failed to create a new client: %v\n", err))
setAppErr(appCl, err)
os.Exit(1)
}
var closeSignal bool
if runtime.GOOS == "windows" {
ipcClient, err := ipc.StartClient(visorconfig.SkysocksName, nil)
if err != nil {
print(fmt.Sprintf("Failed to create a new client: %v\n", err))
setAppErr(appCl, err)
print(fmt.Sprintf("Error creating ipc server for skysocks: %v\n", err))
os.Exit(1)
}
go func() {
client.ListenIPC(ipcClient)
closeSignal = true
}()
} else {
termCh := make(chan os.Signal, 1)
signal.Notify(termCh, os.Interrupt)
go func() {
<-termCh
if err := client.Close(); err != nil {
print(fmt.Sprintf("%v\n", err))
os.Exit(1)
}
closeSignal = true
}()
}

fmt.Printf("Serving proxy client %v\n", addr)
setAppStatus(appCl, appserver.AppDetailedStatusRunning)
httpCtx, httpCancel := context.WithCancel(ctx)
if httpAddr != "" {
go httpProxy(httpCtx, httpAddr, addr)
}
fmt.Printf("Serving proxy client %v\n", addr)
setAppStatus(appCl, appserver.AppDetailedStatusRunning)
httpCtx, httpCancel := context.WithCancel(ctx)
if httpAddr != "" {
go httpProxy(httpCtx, httpAddr, addr)
}
defer httpCancel()
for {
if err := client.ListenAndServe(addr); err != nil {
print(fmt.Sprintf("Error serving proxy client: %v\n", err))
}
httpCancel()
// need to filter this out, cause usually client failure means app conn is already closed
if err := conn.Close(); err != nil && err != io.ErrClosedPipe {
print(fmt.Sprintf("Error closing app conn: %v\n", err))
if closeSignal {
break
}

fmt.Println("Reconnecting to skysocks server")
setAppStatus(appCl, appserver.AppDetailedStatusReconnecting)
}
},
}
Expand Down
57 changes: 30 additions & 27 deletions cmd/skywire-cli/commands/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var startCmd = &cobra.Command{
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Error occurs during set args to custom skysocks client"))
}
} else {
err = rpcClient.AddApp(clientName, "skysocks-client")
err = rpcClient.AddApp(clientName, "skywire")
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Error during add new app"))
}
Expand Down Expand Up @@ -109,8 +109,9 @@ var startCmd = &cobra.Command{
clientName = "skysocks-client"
// change defaul skysocks-proxy app -srv arg and run it
} else {
// error
return
internal.Catch(cmd.Flags(), rpcClient.StartApp("skysocks-client"))
internal.PrintOutput(cmd.Flags(), nil, "Starting.")
clientName = "skysocks-client"
}

ctx, cancel := cmdutil.SignalContext(context.Background(), &logrus.Logger{})
Expand Down Expand Up @@ -201,33 +202,35 @@ var statusCmd = &cobra.Command{
var jsonAppStatus []appState
fmt.Fprintf(w, "---- All Proxy List -----------------------------------------------------\n\n")
for _, state := range states {
if state.AppConfig.Binary == binaryName {
status := "stopped"
if state.Status == appserver.AppStatusRunning {
status = "running"
}
if state.Status == appserver.AppStatusErrored {
status = "errored"
}
jsonAppStatus = append(jsonAppStatus, appState{
Name: state.Name,
Status: status,
AutoStart: state.AutoStart,
Args: state.Args,
AppPort: state.Port,
})
var tmpAddr string
var tmpSrv string
for idx, arg := range state.Args {
if arg == "-srv" {
tmpSrv = state.Args[idx+1]
for _, v := range state.AppConfig.Args {
if v == binaryName {
status := "stopped"
if state.Status == appserver.AppStatusRunning {
status = "running"
}
if state.Status == appserver.AppStatusErrored {
status = "errored"
}
if arg == "-addr" {
tmpAddr = "127.0.0.1" + state.Args[idx+1]
jsonAppStatus = append(jsonAppStatus, appState{
Name: state.Name,
Status: status,
AutoStart: state.AutoStart,
Args: state.Args,
AppPort: state.Port,
})
var tmpAddr string
var tmpSrv string
for idx, arg := range state.Args {
if arg == "--srv" {
tmpSrv = state.Args[idx+1]
}
if arg == "--addr" {
tmpAddr = "127.0.0.1" + state.Args[idx+1]
}
}
_, err = fmt.Fprintf(w, "Name: %s\nStatus: %s\nServer: %s\nAddress: %s\nAppPort: %d\nAutoStart: %t\n\n", state.Name, status, tmpSrv, tmpAddr, state.Port, state.AutoStart)
internal.Catch(cmd.Flags(), err)
}
_, err = fmt.Fprintf(w, "Name: %s\nStatus: %s\nServer: %s\nAddress: %s\nAppPort: %d\nAutoStart: %t\n\n", state.Name, status, tmpSrv, tmpAddr, state.Port, state.AutoStart)
internal.Catch(cmd.Flags(), err)
}
}
fmt.Fprintf(w, "-------------------------------------------------------------------------\n")
Expand Down
2 changes: 1 addition & 1 deletion pkg/skyenv/skyenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const (

AppSrvAddr = "localhost:5505" // AppSrvAddr ...
ServiceDiscUpdateInterval = time.Minute // ServiceDiscUpdateInterval ...
AppBinPath = "./build" // AppBinPath ...
AppBinPath = "./" // AppBinPath ...
LogLevel = "info" // LogLevel ...

// Routing constants
Expand Down
2 changes: 1 addition & 1 deletion pkg/skyenv/skyenv_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
// PackageConfig contains installation paths (for mac)
func PackageConfig() PkgConfig {
pkgConfig := PkgConfig{
LauncherBinPath: "/Applications/Skywire.app/Contents/MacOS/bin", //apps are now subcommands of the skywire binary "/Applications/Skywire.app/Contents/MacOS/apps",
LauncherBinPath: "/Applications/Skywire.app/Contents/MacOS", //apps are now subcommands of the skywire binary "/Applications/Skywire.app/Contents/MacOS/apps",
LocalPath: "/Library/Application Support/Skywire/local",
Hypervisor: Hypervisor{
DbPath: "/Library/Application Support/Skywire/users.db",
Expand Down
2 changes: 1 addition & 1 deletion pkg/skyenv/skyenv_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
// PackageConfig contains installation paths (for windows)
func PackageConfig() PkgConfig {
pkgConfig := PkgConfig{
LauncherBinPath: "C:/Program Files/Skywire/bin", //apps are now subcommands of the skywire binary "C:/Program Files/Skywire/apps",
LauncherBinPath: "C:/Program Files/Skywire",
LocalPath: "C:/Program Files/Skywire/local",
Hypervisor: Hypervisor{
DbPath: "C:/Program Files/Skywire/users.db",
Expand Down
6 changes: 4 additions & 2 deletions pkg/visor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,10 @@ func (v *Visor) StopSkysocksClients() error {
}
if v.procM != nil {
for _, app := range v.conf.Launcher.Apps {
if app.Binary == visorconfig.SkysocksClientName {
v.appL.StopApp(app.Name) //nolint
for _, args := range app.Args {
if args == visorconfig.SkysocksClientName {
v.appL.StopApp(app.Name) //nolint
}
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/visor/visorconfig/values_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// UserConfig contains installation paths for running skywire as the user
func UserConfig() skyenv.PkgConfig {
usrConfig := skyenv.PkgConfig{
LauncherBinPath: "/Applications/Skywire.app/Contents/MacOS/apps",
LauncherBinPath: "/Applications/Skywire.app/Contents/MacOS",
LocalPath: HomePath() + "/.skywire/local",
Hypervisor: skyenv.Hypervisor{
DbPath: HomePath() + "/.skywire/users.db",
Expand Down
2 changes: 1 addition & 1 deletion pkg/visor/visorconfig/values_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// UserConfig contains installation paths for running skywire as the user
func UserConfig() skyenv.PkgConfig {
usrConfig := skyenv.PkgConfig{
LauncherBinPath: "C:/Program Files/Skywire/apps",
LauncherBinPath: "C:/Program Files/Skywire",
LocalPath: HomePath() + "/.skywire/local",
Hypervisor: skyenv.Hypervisor{
DbPath: HomePath() + "/.skywire/users.db",
Expand Down

0 comments on commit c07e455

Please sign in to comment.