Skip to content

Commit f15cf4e

Browse files
author
NullpointerW
committed
feat: add http-proxies-client
1 parent a671272 commit f15cf4e

File tree

8 files changed

+316
-4
lines changed

8 files changed

+316
-4
lines changed

go.mod

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ module github.com/NullpointerW/ethereum-wallet-tool
33
go 1.21
44

55
require (
6+
github.com/Dreamacro/clash v1.18.0
67
github.com/ethereum/go-ethereum v1.13.5
78
github.com/spf13/cobra v1.5.0
9+
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
810
)
911

1012
require (
13+
github.com/Dreamacro/protobytes v0.0.0-20230617041236-6500a9f4f158 // indirect
1114
github.com/Microsoft/go-winio v0.6.1 // indirect
1215
github.com/StackExchange/wmi v1.2.1 // indirect
1316
github.com/bits-and-blooms/bitset v1.7.0 // indirect
@@ -20,20 +23,26 @@ require (
2023
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
2124
github.com/go-ole/go-ole v1.2.5 // indirect
2225
github.com/go-stack/stack v1.8.1 // indirect
23-
github.com/gorilla/websocket v1.4.2 // indirect
26+
github.com/gofrs/uuid/v5 v5.0.0 // indirect
27+
github.com/gorilla/websocket v1.5.0 // indirect
2428
github.com/holiman/uint256 v1.2.3 // indirect
2529
github.com/inconshreveable/mousetrap v1.0.0 // indirect
30+
github.com/miekg/dns v1.1.55 // indirect
2631
github.com/mmcloughlin/addchain v0.4.0 // indirect
32+
github.com/samber/lo v1.38.1 // indirect
2733
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
34+
github.com/sirupsen/logrus v1.9.3 // indirect
2835
github.com/spf13/pflag v1.0.5 // indirect
2936
github.com/supranational/blst v0.3.11 // indirect
3037
github.com/tklauser/go-sysconf v0.3.12 // indirect
3138
github.com/tklauser/numcpus v0.6.1 // indirect
39+
go.uber.org/atomic v1.11.0 // indirect
3240
golang.org/x/crypto v0.14.0 // indirect
33-
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
3441
golang.org/x/mod v0.12.0 // indirect
42+
golang.org/x/net v0.17.0 // indirect
3543
golang.org/x/sync v0.3.0 // indirect
3644
golang.org/x/sys v0.13.0 // indirect
45+
golang.org/x/text v0.13.0 // indirect
3746
golang.org/x/tools v0.13.0 // indirect
3847
rsc.io/tmplfunc v0.0.3 // indirect
3948
)

go.sum

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
22
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
3+
github.com/Dreamacro/clash v1.18.0 h1:tic7ykTOCaT0mxwAkXo6QP3LN3Nps8oZz9atgr6TU8A=
4+
github.com/Dreamacro/clash v1.18.0/go.mod h1:r//xe/2pA3Zl+3fjIiI/o6RjIVd+z87drCD58dpRnFg=
5+
github.com/Dreamacro/protobytes v0.0.0-20230617041236-6500a9f4f158 h1:JFnwKplz9hj8ubqYjm8HkgZS1Rvz9yW+u/XCNNTxr0k=
6+
github.com/Dreamacro/protobytes v0.0.0-20230617041236-6500a9f4f158/go.mod h1:QvmEZ/h6KXszPOr2wUFl7Zn3hfFNYdfbXwPVDTyZs6k=
37
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
48
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
59
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
@@ -36,6 +40,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHH
3640
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
3741
github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA=
3842
github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc=
43+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3944
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4045
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4146
github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI=
@@ -60,6 +65,8 @@ github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
6065
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
6166
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
6267
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
68+
github.com/gofrs/uuid/v5 v5.0.0 h1:p544++a97kEL+svbcFbCQVM9KFu0Yo25UoISXGNNH9M=
69+
github.com/gofrs/uuid/v5 v5.0.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
6370
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
6471
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
6572
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
@@ -71,8 +78,8 @@ github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg
7178
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
7279
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
7380
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
74-
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
75-
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
81+
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
82+
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
7683
github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE=
7784
github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0=
7885
github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw=
@@ -105,6 +112,8 @@ github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4
105112
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
106113
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
107114
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
115+
github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo=
116+
github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY=
108117
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
109118
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
110119
github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A=
@@ -134,14 +143,20 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
134143
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
135144
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
136145
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
146+
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
147+
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
137148
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
138149
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
150+
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
151+
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
139152
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
140153
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
141154
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
142155
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
143156
github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA=
144157
github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg=
158+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
159+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
145160
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
146161
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
147162
github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4=
@@ -158,15 +173,20 @@ github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
158173
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
159174
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
160175
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
176+
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
177+
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
161178
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
162179
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
163180
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
164181
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
165182
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
166183
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
184+
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
185+
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
167186
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
168187
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
169188
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
189+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
170190
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
171191
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
172192
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
@@ -184,6 +204,7 @@ gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXL
184204
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
185205
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
186206
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
207+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
187208
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
188209
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
189210
rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU=

pkg/proxies/dialer.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package proxies
2+
3+
import (
4+
"context"
5+
"errors"
6+
"fmt"
7+
"net"
8+
"strconv"
9+
"strings"
10+
)
11+
12+
type Dialer interface {
13+
NewConn(ctx context.Context, network, addr string) (net.Conn, error)
14+
}
15+
16+
type AddrResolver func(network, addr string) (string, uint16, error)
17+
18+
func StringResolver(_, addr string) (string, uint16, error) {
19+
resolved := strings.Split(addr, ":")
20+
if len(resolved) != 2 {
21+
return "", 0, errors.New(fmt.Sprintf("StringResolver: invalid address: %s", addr))
22+
}
23+
port, err := strconv.Atoi(resolved[1])
24+
if err != nil {
25+
return "", 0, errors.New(fmt.Sprintf("StringResolver: invalid address: %s", addr))
26+
}
27+
28+
return resolved[0], uint16(port), nil
29+
}
30+
31+
func TcpResolver(network, addr string) (string, uint16, error) {
32+
tcpAddr, err := net.ResolveTCPAddr(network, addr)
33+
if err != nil {
34+
return "", 0, err
35+
}
36+
return tcpAddr.IP.String(), uint16(tcpAddr.Port), nil
37+
}

pkg/proxies/http_client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package proxies
2+
3+
import "net/http"
4+
5+
func NewHttpClient(client *http.Client, dialer Dialer) *http.Client {
6+
client.Transport = &http.Transport{
7+
DialContext: dialer.NewConn,
8+
}
9+
return client
10+
}

pkg/proxies/shadowsocks/dialer.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package shadowsocks
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"github.com/Dreamacro/clash/adapter/outbound"
7+
C "github.com/Dreamacro/clash/constant"
8+
"github.com/NullpointerW/ethereum-wallet-tool/pkg/proxies"
9+
"golang.org/x/exp/rand"
10+
"net"
11+
"time"
12+
)
13+
14+
type Dialer struct {
15+
nodes []outbound.ShadowSocksOption
16+
nl int
17+
addrResolver proxies.AddrResolver
18+
}
19+
20+
func NewDialer(addrResolver proxies.AddrResolver, nodes ...outbound.ShadowSocksOption) *Dialer {
21+
dl := new(Dialer)
22+
dl.nodes = nodes
23+
dl.nl = len(nodes)
24+
dl.addrResolver = addrResolver
25+
return dl
26+
}
27+
28+
func (dialer *Dialer) NewConn(ctx context.Context, network, addr string) (net.Conn, error) {
29+
rand.Seed(uint64(time.Now().UnixNano()))
30+
r := rand.Int() % len(dialer.nodes)
31+
fmt.Println("use node::", r)
32+
proxy, err := outbound.NewShadowSocks(dialer.nodes[r])
33+
if err != nil {
34+
return nil, err
35+
}
36+
host, port, err := dialer.addrResolver(network, addr)
37+
if err != nil {
38+
return nil, err
39+
}
40+
conn, err := proxy.DialContext(context.Background(), &C.Metadata{
41+
Host: host,
42+
DstPort: C.Port(port),
43+
})
44+
return conn, err
45+
}

pkg/proxies/shadowsocks/ss_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package shadowsocks
2+
3+
import (
4+
"fmt"
5+
"github.com/Dreamacro/clash/adapter/outbound"
6+
"github.com/NullpointerW/ethereum-wallet-tool/pkg/proxies"
7+
"io"
8+
"net/http"
9+
"testing"
10+
)
11+
12+
func TestSS(t *testing.T) {
13+
dialer := NewDialer(proxies.StringResolver, []outbound.ShadowSocksOption{{
14+
Name: "ss",
15+
Server: "sever_host",
16+
Port: 12001,
17+
Password: "xxx",
18+
Cipher: "aes-128-gcm",
19+
UDP: true,
20+
Plugin: "obfs",
21+
PluginOpts: map[string]any{
22+
"mode": "http",
23+
"host": "xxx.download.windowsupdate.com",
24+
}},
25+
{
26+
Name: "ss",
27+
Server: "sever_host",
28+
Port: 12001,
29+
Password: "xxx",
30+
Cipher: "aes-128-gcm",
31+
UDP: true,
32+
Plugin: "obfs",
33+
PluginOpts: map[string]any{
34+
"mode": "http",
35+
"host": "xxx.download.windowsupdate.com",
36+
}},
37+
{
38+
Name: "ss",
39+
Server: "sever_host",
40+
Port: 12001,
41+
Password: "xxx",
42+
Cipher: "aes-128-gcm",
43+
UDP: true,
44+
Plugin: "obfs",
45+
PluginOpts: map[string]any{
46+
"mode": "http",
47+
"host": "xxx.download.windowsupdate.com",
48+
}},
49+
{
50+
Name: "ss",
51+
Server: "sever_host",
52+
Port: 12001,
53+
Password: "xxx",
54+
Cipher: "aes-128-gcm",
55+
UDP: true,
56+
Plugin: "obfs",
57+
PluginOpts: map[string]any{
58+
"mode": "http",
59+
"host": "xxx.download.windowsupdate.com",
60+
}},
61+
}...)
62+
63+
httpTransport := &http.Transport{
64+
DialContext: dialer.NewConn,
65+
}
66+
httpC := &http.Client{
67+
Transport: httpTransport,
68+
}
69+
resp, err := httpC.Get("https://www.youtube.com/")
70+
if err != nil {
71+
fmt.Println(err)
72+
return
73+
}
74+
b, err := io.ReadAll(resp.Body)
75+
if err != nil {
76+
fmt.Println(err)
77+
return
78+
}
79+
fmt.Println(string(b))
80+
}

pkg/proxies/vmess/dialer.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package vmess
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"github.com/Dreamacro/clash/adapter/outbound"
7+
C "github.com/Dreamacro/clash/constant"
8+
"github.com/NullpointerW/ethereum-wallet-tool/pkg/proxies"
9+
"golang.org/x/exp/rand"
10+
"net"
11+
"time"
12+
)
13+
14+
type Dialer struct {
15+
nodes []outbound.VmessOption
16+
nl int
17+
addrResolver proxies.AddrResolver
18+
}
19+
20+
func NewDialer(addrResolver proxies.AddrResolver, nodes ...outbound.VmessOption) *Dialer {
21+
dl := new(Dialer)
22+
dl.nodes = nodes
23+
dl.nl = len(nodes)
24+
dl.addrResolver = addrResolver
25+
return dl
26+
}
27+
28+
func (dialer *Dialer) NewConn(ctx context.Context, network, addr string) (net.Conn, error) {
29+
rand.Seed(uint64(time.Now().UnixNano()))
30+
r := rand.Int() % len(dialer.nodes)
31+
fmt.Println("use node::", r)
32+
proxy, err := outbound.NewVmess(dialer.nodes[r])
33+
if err != nil {
34+
return nil, err
35+
}
36+
host, port, err := dialer.addrResolver(network, addr)
37+
if err != nil {
38+
return nil, err
39+
}
40+
conn, err := proxy.DialContext(context.Background(), &C.Metadata{
41+
Host: host,
42+
DstPort: C.Port(port),
43+
})
44+
return conn, err
45+
}

0 commit comments

Comments
 (0)