Skip to content

Commit

Permalink
socks5: implement proxy through remote peer
Browse files Browse the repository at this point in the history
  • Loading branch information
pymq committed Aug 17, 2024
1 parent 3c44446 commit 9e15252
Show file tree
Hide file tree
Showing 16 changed files with 666 additions and 58 deletions.
10 changes: 10 additions & 0 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Application struct {
Api *api.Handler
AuthStatus *service.AuthStatus
Tunnel *service.Tunnel
SOCKS5 *service.SOCKS5
Dns *DNSService
}

Expand Down Expand Up @@ -116,10 +117,15 @@ func (a *Application) Init(ctx context.Context, tunDevice tun.Device) error {
a.Dns = NewDNSService(a.Conf, a.Eventbus, a.ctx, a.logger)
a.AuthStatus = service.NewAuthStatus(a.P2p, a.Conf, a.Eventbus)
a.Tunnel = service.NewTunnel(a.P2p, vpnDevice, a.Conf)
a.SOCKS5, err = service.NewSOCKS5(a.P2p, a.Conf)
if err != nil {
return fmt.Errorf("failed to init socks5: %v", err)
}

p2pHost.SetStreamHandler(protocol.GetStatusMethod, a.AuthStatus.StatusStreamHandler)
p2pHost.SetStreamHandler(protocol.AuthMethod, a.AuthStatus.AuthStreamHandler)
p2pHost.SetStreamHandler(protocol.TunnelPacketMethod, a.Tunnel.StreamHandler)
p2pHost.SetStreamHandler(protocol.Socks5PacketMethod, a.SOCKS5.ProxyStreamHandler)

awlevent.WrapSubscriptionToCallback(a.ctx, func(_ interface{}) {
a.Tunnel.RefreshPeersList()
Expand All @@ -135,6 +141,7 @@ func (a *Application) Init(ctx context.Context, tunDevice tun.Device) error {
go a.P2p.MaintainBackgroundConnections(a.ctx, a.Conf.P2pNode.ReconnectionIntervalSec*time.Second, a.Conf.KnownPeersIds)
go a.AuthStatus.BackgroundRetryAuthRequests(a.ctx)
go a.AuthStatus.BackgroundExchangeStatusInfo(a.ctx)
go a.SOCKS5.ServeConns(a.ctx)

if useAwldns {
interfaceName, err := a.vpnDevice.InterfaceName()
Expand Down Expand Up @@ -231,6 +238,9 @@ func (a *Application) Close() {
if a.Tunnel != nil {
a.Tunnel.Close()
}
if a.SOCKS5 != nil {
a.SOCKS5.Close()
}
if a.vpnDevice != nil {
err := a.vpnDevice.Close()
if err != nil {
Expand Down
78 changes: 78 additions & 0 deletions application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"encoding/hex"
"errors"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
"runtime"
"sync"
Expand All @@ -27,6 +31,7 @@ import (
"github.com/quic-go/quic-go/integrationtests/tools/israce"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"golang.org/x/net/proxy"
"golang.zx2c4.com/wireguard/tun"

"github.com/anywherelan/awl/api"
Expand Down Expand Up @@ -211,6 +216,8 @@ func TestUpdateUseAsExitNodeConfig(t *testing.T) {
return peer2Config.AllowedUsingAsExitNode
}, 15*time.Second, 100*time.Millisecond)

ts.Equal(peer2.PeerID(), peer1.app.Conf.SOCKS5.UsingPeerID)

// allow from peer1, check that peer2 got our config
err = peer1.api.UpdatePeerSettings(entity.UpdatePeerSettingsRequest{
PeerID: peer2.PeerID(),
Expand All @@ -227,6 +234,8 @@ func TestUpdateUseAsExitNodeConfig(t *testing.T) {
return peer1Config.AllowedUsingAsExitNode && peer1Config.WeAllowUsingAsExitNode
}, 15*time.Second, 100*time.Millisecond)

ts.Equal(peer1.PeerID(), peer2.app.Conf.SOCKS5.UsingPeerID)

// disallow from peer2, check that peer1 got our new config
err = peer2.api.UpdatePeerSettings(entity.UpdatePeerSettingsRequest{
PeerID: peer1.PeerID(),
Expand All @@ -242,6 +251,59 @@ func TestUpdateUseAsExitNodeConfig(t *testing.T) {

return !peer2Config.AllowedUsingAsExitNode && peer2Config.WeAllowUsingAsExitNode
}, 15*time.Second, 100*time.Millisecond)

ts.Equal("", peer1.app.Conf.SOCKS5.UsingPeerID)
testProxy(ts, peer1.app.Conf.SOCKS5.ListenAddress, true)

testProxy(ts, peer2.app.Conf.SOCKS5.ListenAddress, false)
}

func testProxy(ts *TestSuite, proxyAddr string, expectSocksErr bool) {
// setup mock server
addr := pickFreeAddr(ts.t)
mux := http.NewServeMux()
mux.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintf(w, "test text")
})
httpServer := &http.Server{Addr: addr, Handler: mux}
go func() {
_ = httpServer.ListenAndServe()
}()
defer func() {
httpServer.Shutdown(context.Background())
}()

// client
dialer, err := proxy.SOCKS5("tcp", proxyAddr, nil, nil)
ts.NoError(err)
httpTransport := &http.Transport{DialContext: dialer.(proxy.ContextDialer).DialContext}
httpClient := http.Client{Transport: httpTransport}

// test
for range 5 {
response, err := httpClient.Get(fmt.Sprintf("http://%s/test", addr))
if expectSocksErr {
ts.Error(err)

var urlErr *url.Error
ts.ErrorAs(err, &urlErr)
var netErr *net.OpError
ts.ErrorAs(urlErr.Err, &netErr)

ts.Equal("socks connect", netErr.Op)
ts.EqualError(netErr.Err, "unknown error general SOCKS server failure")

continue
}

ts.NoError(err)
body, err := io.ReadAll(response.Body)
ts.NoError(err)
err = response.Body.Close()
ts.NoError(err)

ts.Equal("test text", string(body))
}
}

func TestTunnelPackets(t *testing.T) {
Expand Down Expand Up @@ -412,6 +474,12 @@ func (ts *TestSuite) newTestPeer(disableLogging bool) testPeer {
multiaddr.StringCast("/ip4/127.0.0.1/udp/0/quic-v1"),
})
app.Conf.P2pNode.BootstrapPeers = ts.bootstrapAddrsStr
app.Conf.SOCKS5 = config.SOCKS5Config{
ListenerEnabled: true,
ProxyingEnabled: true,
ListenAddress: pickFreeAddr(ts.t),
UsingPeerID: "",
}

testTUN := NewTestTUN()
err := app.Init(context.Background(), testTUN.TUN())
Expand Down Expand Up @@ -601,3 +669,13 @@ func (t *testTun) Close() error {
close(t.t.events)
return nil
}

func pickFreeAddr(t testing.TB) string {
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
defer l.Close()

return l.Addr().String()
}
17 changes: 9 additions & 8 deletions cmd/awl-tray/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/haxii/socks5 v1.0.0 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/illarion/gonotify v1.0.1 // indirect
github.com/ipfs/boxo v0.10.0 // indirect
Expand Down Expand Up @@ -169,17 +170,17 @@ require (
go.uber.org/zap v1.27.0 // indirect
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/image v0.14.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard v0.0.0-20230325221338-052af4a8072b // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
Expand Down
34 changes: 18 additions & 16 deletions cmd/awl-tray/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/haxii/socks5 v1.0.0 h1:78BIzd4lHibdRNOKdMwKCnnsgYLW9SeotqU+nMhWSSo=
github.com/haxii/socks5 v1.0.0/go.mod h1:6O9Ba2yrLlvuSe/L1e84eZI8cPw6H+q1Ilr4hjgm4uY=
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
github.com/illarion/gonotify v1.0.1 h1:F1d+0Fgbq/sDWjj/r66ekjDG+IDeecQKUFH4wNwsoio=
Expand Down Expand Up @@ -552,8 +554,8 @@ golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98y
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
Expand All @@ -571,8 +573,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -598,8 +600,8 @@ golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand All @@ -615,8 +617,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -647,8 +649,8 @@ golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
Expand All @@ -659,8 +661,8 @@ golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand All @@ -670,8 +672,8 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
Expand All @@ -694,8 +696,8 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
AdminHttpServerIP = "127.0.0.66"
AdminHttpServerListenAddress = "127.0.0.66:80"

defaultSOCKS5ListenAddress = "127.0.0.66:8080"

DefaultPeerAlias = "peer"
)

Expand All @@ -49,6 +51,7 @@ type (
HttpListenOnAdminHost bool `json:"httpListenOnAdminHost"`
P2pNode P2pNodeConfig `json:"p2pNode"`
VPNConfig VPNConfig `json:"vpn"`
SOCKS5 SOCKS5Config `json:"socks5"`
KnownPeers map[string]KnownPeer `json:"knownPeers"`
BlockedPeers map[string]BlockedPeer `json:"blockedPeers"`
Update UpdateConfig `json:"update"`
Expand All @@ -70,6 +73,14 @@ type (
InterfaceName string `json:"interfaceName"`
IPNet string `json:"ipNet"`
}
SOCKS5Config struct {
ListenerEnabled bool `json:"listenerEnabled"`
// allow using my host as proxy
ProxyingEnabled bool `json:"proxyingEnabled"`
ListenAddress string `json:"listenAddress"`
// peer that is set as proxy
UsingPeerID string `json:"usingPeerID"`
}
KnownPeer struct {
// Hex-encoded multihash representing a peer ID
PeerID string `json:"peerId"`
Expand Down
8 changes: 8 additions & 0 deletions config/other.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ func setDefaults(conf *Config, bus awlevent.Bus) {
}
}

if conf.SOCKS5 == (SOCKS5Config{}) {
conf.SOCKS5.ListenerEnabled = true
conf.SOCKS5.ProxyingEnabled = true
}
if conf.SOCKS5.ListenAddress == "" {
conf.SOCKS5.ListenAddress = defaultSOCKS5ListenAddress
}

uniqAliases := make(map[string]struct{}, len(conf.KnownPeers))
if conf.KnownPeers == nil {
conf.KnownPeers = make(map[string]KnownPeer)
Expand Down
19 changes: 10 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ require (
github.com/anywherelan/ts-dns v0.0.0-20240721135326-6d6b7b811853
github.com/go-playground/validator/v10 v10.22.0
github.com/google/go-querystring v1.1.0
github.com/haxii/socks5 v1.0.0
github.com/ipfs/go-datastore v0.6.0
github.com/ipfs/go-log/v2 v2.5.1
github.com/labstack/echo/v4 v4.12.0
github.com/libp2p/go-buffer-pool v0.1.0
github.com/libp2p/go-libp2p v0.35.1
github.com/libp2p/go-libp2p-kad-dht v0.25.2
github.com/libp2p/go-libp2p-kbucket v0.6.3
Expand All @@ -27,8 +29,8 @@ require (
github.com/urfave/cli/v2 v2.27.2
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/net v0.26.0
golang.org/x/sys v0.21.0
golang.org/x/net v0.28.0
golang.org/x/sys v0.23.0
golang.zx2c4.com/wireguard v0.0.0-20230325221338-052af4a8072b
golang.zx2c4.com/wireguard/windows v0.5.3
)
Expand Down Expand Up @@ -83,7 +85,6 @@ require (
github.com/koron/go-ssdp v0.0.4 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect
Expand Down Expand Up @@ -154,14 +155,14 @@ require (
go.uber.org/mock v0.4.0 // indirect
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
gonum.org/v1/gonum v0.13.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
Expand Down
Loading

0 comments on commit 9e15252

Please sign in to comment.