Skip to content

Commit 65d3a69

Browse files
committed
add wg proxy
1 parent d1174fa commit 65d3a69

4 files changed

Lines changed: 436 additions & 396 deletions

File tree

http/client_proxy.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (p *ProxyStats) bytesReceived(n uint64) {
5454
type ClientProxy struct {
5555
connectionInfo *connprovider.ConnectionInfo
5656
generator *connect.ApiMultiClientGenerator
57-
dev proxy.Device
57+
dev *proxy.Tun
5858
nc *connect.RemoteUserNatMultiClient
5959
proxyServer *goproxy.ProxyHttpServer
6060
http.Handler
@@ -101,11 +101,10 @@ func NewClientProxy(ctx context.Context, cc ConnectionConfig) (*ClientProxy, err
101101
connect.DefaultApiMultiClientGeneratorSettings(),
102102
)
103103

104-
tnet, err := proxy.CreateNetTun(ctx, 1440)
104+
dev, err := proxy.CreateTunWithDefaults(ctx)
105105
if err != nil {
106106
return nil, fmt.Errorf("create net tun failed: %w", err)
107107
}
108-
dev := proxy.Device(tnet)
109108

110109
mc := connect.NewRemoteUserNatMultiClientWithDefaults(
111110
ctx,
@@ -145,20 +144,20 @@ func NewClientProxy(ctx context.Context, cc ConnectionConfig) (*ClientProxy, err
145144

146145
proxy.Tr = &http.Transport{
147146
Dial: func(network, addr string) (net.Conn, error) {
148-
return tnet.DialContext(context.Background(), network, addr)
147+
return dev.DialContext(context.Background(), network, addr)
149148
},
150149
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
151150
// ap, err := netip.ParseAddrPort(addr)
152151
// if err != nil {
153152
// return nil, err
154153
// }
155154

156-
return tnet.DialContext(ctx, network, addr)
155+
return dev.DialContext(ctx, network, addr)
157156
},
158157
}
159158

160159
proxy.ConnectDialWithReq = func(req *http.Request, network string, addr string) (net.Conn, error) {
161-
return tnet.DialContext(req.Context(), network, addr)
160+
return dev.DialContext(req.Context(), network, addr)
162161
}
163162

164163
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

socks/main.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,10 @@ func main() {
184184
connect.DefaultApiMultiClientGeneratorSettings(),
185185
)
186186

187-
tnet, err := proxy.CreateNetTun(
188-
ctx,
189-
1440,
190-
)
187+
dev, err := proxy.CreateTunWithDefaults(ctx)
191188
if err != nil {
192189
return fmt.Errorf("create net tun failed: %w", err)
193190
}
194-
dev := proxy.Device(tnet)
195191

196192
mc := connect.NewRemoteUserNatMultiClientWithDefaults(
197193
ctx,
@@ -236,7 +232,7 @@ func main() {
236232
// return nil, err
237233
// }
238234

239-
return tnet.DialContext(ctx, "tcp", addr)
235+
return dev.DialContext(ctx, "tcp", addr)
240236
}),
241237
)
242238

0 commit comments

Comments
 (0)