Skip to content

Commit

Permalink
Merge pull request #1728 from mrpalide/feat/http-proxy-to-skysocks-cl…
Browse files Browse the repository at this point in the history
…ient

Feature | http-proxy on skysocks-client
  • Loading branch information
mrpalide authored Feb 6, 2024
2 parents f00c68a + 5ee1979 commit e4f31dc
Show file tree
Hide file tree
Showing 30 changed files with 2,133 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Install Requirements
shell: pwsh
run: |
Invoke-WebRequest "https://github.com/goreleaser/goreleaser/releases/download/v1.8.3/goreleaser_Windows_x86_64.zip" -o goreleaser.zip
Invoke-WebRequest "https://github.com/goreleaser/goreleaser/releases/download/v1.8.3/goreleaser_Windows_x86_64.zip" -OutFile goreleaser.zip
Expand-Archive goreleaser.zip
choco install make
- name: Releasing
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

updates may be generated with `scripts/changelog.sh <PR#lowest> <PR#highest>`

## 1.3.17
- Add http-proxy on skysocks-client [#1728](https://github.com/skycoin/skywire/pull/1728)
- Little Improve on skywire and setup-node [#1723](https://github.com/skycoin/skywire/pull/1723)
- Improve VPN and Proxy cli command [#1722](https://github.com/skycoin/skywire/pull/1722)
- Improve Survey and Log Collection [#1721](https://github.com/skycoin/skywire/pull/1721)
- Server list optimization [#1720](https://github.com/skycoin/skywire/pull/1720)
- Fix reward calc [#1719](https://github.com/skycoin/skywire/pull/1719)
- Fix reward calculation [#1716](https://github.com/skycoin/skywire/pull/1716)
- Fix log collection panic [#1711](https://github.com/skycoin/skywire/pull/1711)
- Fix win installer script [#1706](https://github.com/skycoin/skywire/pull/1706)

## 1.3.16

- fix VPN issues on CI and Windows [#1703](https://github.com/skycoin/skywire/pull/1703)
Expand Down
37 changes: 35 additions & 2 deletions cmd/apps/skysocks-client/skysocks-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import (
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
"time"

"github.com/elazarl/goproxy"

"github.com/skycoin/skywire-utilities/pkg/buildinfo"
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/netutil"
Expand Down Expand Up @@ -64,6 +68,7 @@ func main() {

var addr = flag.String("addr", visorconfig.SkysocksClientAddr, "Client address to listen on")
var serverPK = flag.String("srv", "", "PubKey of the server to connect to")
var httpAddr = flag.String("http", "", "Starting http proxy or not")
flag.Parse()

if *serverPK == "" {
Expand Down Expand Up @@ -99,11 +104,14 @@ func main() {

fmt.Printf("Serving proxy client %v\n", *addr)
setAppStatus(appCl, appserver.AppDetailedStatusRunning)

httpCtx, httpCancel := context.WithCancel(ctx)
if *httpAddr != "" {
go httpProxy(httpCtx, httpAddr, addr)
}
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))
Expand Down Expand Up @@ -131,3 +139,28 @@ func setAppPort(appCl *app.Client, port routing.Port) {
print(fmt.Sprintf("Failed to set port %v: %v\n", port, err))
}
}

func httpProxy(ctx context.Context, httpAddr, sockscAddr *string) {
proxy := goproxy.NewProxyHttpServer()

proxyURL, err := url.Parse(fmt.Sprintf("socks5://127.0.0.1%s", *sockscAddr)) //nolint
if err != nil {
print(fmt.Sprintf("Failed to parse socks address: %v\n", err))
return
}

proxy.Tr.Proxy = http.ProxyURL(proxyURL)

fmt.Printf("Serving http proxy %v\n", *httpAddr)
httpProxySrv := &http.Server{Addr: *httpAddr, Handler: proxy} //nolint

go func() {
<-ctx.Done()
httpProxySrv.Close() //nolint
print("Stopping http proxy")
}()

if err := httpProxySrv.ListenAndServe(); err != nil { //nolint
print(fmt.Sprintf("Error serving http proxy: %v\n", err))
}
}
26 changes: 21 additions & 5 deletions cmd/skywire-cli/commands/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func init() {
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")
}

var startCmd = &cobra.Command{
Expand All @@ -48,6 +49,17 @@ 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 @@ -62,10 +74,6 @@ 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 @@ -85,6 +93,10 @@ 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 @@ -99,7 +111,11 @@ var startCmd = &cobra.Command{
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("Invalid or missing public key"))
}
}
internal.Catch(cmd.Flags(), rpcClient.StartSkysocksClient(pubkey.String()))
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.PrintOutput(cmd.Flags(), nil, "Starting.")
clientName = "skysocks-client"
// change defaul skysocks-proxy app -srv arg and run it
Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-cli/commands/proxy/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
clientName string
addr string
startingTimeout int
httpProxy string
)

// RootCmd contains commands that interact with the skywire-visor
Expand Down
2 changes: 1 addition & 1 deletion dmsghttp-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
{
"static": "0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7",
"server": {
"address": "173.172.1.120:9083"
"address": "70.121.23.42:9083"
}
},
{
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/bitfield/script v0.22.0
github.com/blang/semver/v4 v4.0.0
github.com/ccding/go-stun/stun v0.0.0-20200514191101-4dc67bcdb029
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5
github.com/gen2brain/dlgs v0.0.0-20220603100644-40c77870fa8d
github.com/gin-gonic/gin v1.9.1
github.com/go-chi/chi/v5 v5.0.11
Expand All @@ -27,11 +28,11 @@ require (
github.com/orandin/lumberjackrus v1.0.1
github.com/pterm/pterm v0.12.66
github.com/sirupsen/logrus v1.9.3
github.com/skycoin/dmsg v1.3.15-0.20240201143600-b1d1d1012348
github.com/skycoin/dmsg v1.3.17
github.com/skycoin/skycoin v0.27.1
github.com/skycoin/skycoin-service-discovery v0.0.0-20231221001759-d1af6ec27db1
github.com/skycoin/skywire-services v0.0.0-20231221001820-3212895ddf12
github.com/skycoin/skywire-utilities v1.3.14
github.com/skycoin/skywire-utilities v1.3.17
github.com/skycoin/systray v1.10.0
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
github.com/spf13/cobra v1.7.0
Expand Down
13 changes: 9 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5 h1:m62nsMU279qRD9PQSWD1l66kmkXzuYcnVJqL4XLeV2M=
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 h1:dWB6v3RcOy03t/bUadywsbyrQwCqZeNIEX6M1OtSZOM=
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down Expand Up @@ -406,6 +410,7 @@ github.com/quic-go/quic-go v0.38.1/go.mod h1:ijnZM7JsFIkp4cRyjxJNIzdSfCLmUMg9wdy
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
Expand All @@ -429,8 +434,8 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skycoin/dmsg v1.3.15-0.20240201143600-b1d1d1012348 h1:UYKHYIcwI/cHcdctJFkMXTR94vgRuYvNejU7vecLOi8=
github.com/skycoin/dmsg v1.3.15-0.20240201143600-b1d1d1012348/go.mod h1:I4Bgha3DPNOoimvUtQmAjGUSknw4o/jaBVMY+KNz9vY=
github.com/skycoin/dmsg v1.3.17 h1:CUq8u4ABDKFkE4ppscJ/R09hMtfPUE72Rleq078vQ28=
github.com/skycoin/dmsg v1.3.17/go.mod h1:INEDx+ECwCGQWw/Kd0QcLmSWMhbeRRcfkxj+xATQGFg=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 h1:1Nc5EBY6pjfw1kwW0duwyG+7WliWz5u9kgk1h5MnLuA=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:UXghlricA7J3aRD/k7p/zBObQfmBawwCxIVPVjz2Q3o=
github.com/skycoin/skycoin v0.27.1 h1:HatxsRwVSPaV4qxH6290xPBmkH/HgiuAoY2qC+e8C9I=
Expand All @@ -439,8 +444,8 @@ github.com/skycoin/skycoin-service-discovery v0.0.0-20231221001759-d1af6ec27db1
github.com/skycoin/skycoin-service-discovery v0.0.0-20231221001759-d1af6ec27db1/go.mod h1:6VwZDwW4aO6fucuZKiJQ4PnnVYi5CfN/eHcK8F0C05M=
github.com/skycoin/skywire-services v0.0.0-20231221001820-3212895ddf12 h1:fic0WKltARs0JnbNFcKesijNgcPOeJh7CsFs/KLZoJw=
github.com/skycoin/skywire-services v0.0.0-20231221001820-3212895ddf12/go.mod h1:HYqBsmgat3wTk1zwGLNj3q5N3iCpJOwYOuLexqKH02k=
github.com/skycoin/skywire-utilities v1.3.14 h1:AzTV3oiij7b2VgpiZHJj/oy4Tojf22I+r50Riza8Xt0=
github.com/skycoin/skywire-utilities v1.3.14/go.mod h1:yFKWpL1bDRPKU3uK+cTF4PnYUMe+eyIj5N2bk4sF5Cw=
github.com/skycoin/skywire-utilities v1.3.17 h1:89aPdViJxhMpjEJbByQ02W8anX6Oxt68OeSxAENBlFI=
github.com/skycoin/skywire-utilities v1.3.17/go.mod h1:yFKWpL1bDRPKU3uK+cTF4PnYUMe+eyIj5N2bk4sF5Cw=
github.com/skycoin/systray v1.10.0 h1:fQZJHMylpVvfmOOTLvUssfyHVDoC8Idx6Ba2BlLEuGg=
github.com/skycoin/systray v1.10.0/go.mod h1:/i17Eni5GxFiboIZceeamY5LktDSFFRCvd3fBMerQ+4=
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 h1:TG/diQgUe0pntT/2D9tmUCz4VNwm9MfrtPr0SU2qSX8=
Expand Down
4 changes: 2 additions & 2 deletions pkg/transport/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func MakeLogEntry(ls LogStore, tpID uuid.UUID, log *logging.Logger) *LogEntry {
oldLogEntry, err := ls.Entry(tpID)
if err != nil {
log.Warn(err)
return &LogEntry{}
log.Warn(fmt.Errorf("new log entry will create for transport %s", tpID.String()))
}
newEntry := NewLogEntry()
if oldLogEntry != nil {
Expand Down Expand Up @@ -155,7 +155,7 @@ func (tls *inMemoryTransportLogStore) Entry(id uuid.UUID) (*LogEntry, error) {
entry, ok := tls.entries[id]
tls.mu.Unlock()
if !ok {
return entry, errors.New("transport log entry not found")
return nil, errors.New("transport log entry not found")
}

return entry, nil
Expand Down
2 changes: 1 addition & 1 deletion scripts/win_installer/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" UpgradeCode="cd7955bc-304e-470f-9c24-eb9f429a8085"
Name="Skywire"
Version="1.3.16"
Version="1.3.17"
Manufacturer="Skycoin"
Language="1033">

Expand Down
8 changes: 4 additions & 4 deletions scripts/win_installer/script.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function CleanStage
function InstallWix
{
Set-Location .\scripts\win_installer
Invoke-WebRequest "https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip" -o wix.zip
Invoke-WebRequest "https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip" -OutFile wix.zip
Expand-Archive wix.zip
Set-Location ../../
}
Expand Down Expand Up @@ -51,12 +51,12 @@ function BuildInstaller($arch)
$fileName = "skywire-v$version-windows-$arch"
$msiName = "skywire-installer-v$version-windows-$arch"
$downloadURL = "https://github.com/skycoin/skywire/releases/download/v$version/$filename.zip"
Invoke-WebRequest $downloadURL -o archive.zip -ErrorAction Stop
Invoke-WebRequest $downloadURL -OutFile archive.zip -ErrorAction Stop
} else {
$fileName = "skywire-$version-windows-$arch"
$msiName = "skywire-installer-$version-windows-$arch"
$downloadURL = "https://github.com/skycoin/skywire/releases/download/$version/$filename.zip"
Invoke-WebRequest $downloadURL -o archive.zip
Invoke-WebRequest $downloadURL -OutFile archive.zip
}

Write-Output "# 3. Extracing Downloaded Archive File... #"
Expand All @@ -74,7 +74,7 @@ function BuildInstaller($arch)
Copy-Item skywire.bat .\build\skywire.bat
New-Item new.update > $null
Move-Item new.update .\build\new.update
Invoke-WebRequest "https://www.wintun.net/builds/wintun-0.14.1.zip" -o wintun.zip
Invoke-WebRequest "https://www.wintun.net/builds/wintun-0.14.1.zip" -OutFile wintun.zip
Expand-Archive wintun.zip
Copy-Item .\wintun\wintun\bin\$wintun_arch\wintun.dll .\build\wintun.dll

Expand Down
2 changes: 2 additions & 0 deletions vendor/github.com/elazarl/goproxy/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/github.com/elazarl/goproxy/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e4f31dc

Please sign in to comment.