Bladeren bron

fix: ensure network.Dial and MakeHTTPClient use socks5 proxy

The package `network/v2/proxy_network.go` does not wrap `network.Dial`
and `network.MakeHTTPClient`, which causes them to bypass the SOCKS5
proxy and initiate TCP connections directly from the local machine.
tags/v2.2.1^2^2
saleacy 1 maand geleden
bovenliggende
commit
3bc1e415f9
No account linked to committer's email address
1 gewijzigde bestanden met toevoegingen van 15 en 0 verwijderingen
  1. 15
    0
      network/v2/proxy_network.go

+ 15
- 0
network/v2/proxy_network.go Bestand weergeven

@@ -3,6 +3,7 @@ package network
3 3
 import (
4 4
 	"context"
5 5
 	"fmt"
6
+	"net/http"
6 7
 	"net/url"
7 8
 
8 9
 	"github.com/9seconds/mtg/v2/essentials"
@@ -15,6 +16,10 @@ type proxyNetwork struct {
15 16
 	client proxy.ContextDialer
16 17
 }
17 18
 
19
+func (p proxyNetwork) Dial(network, address string) (essentials.Conn, error) {
20
+	return p.DialContext(context.Background(), network, address)
21
+}
22
+
18 23
 func (p proxyNetwork) DialContext(ctx context.Context, network, address string) (essentials.Conn, error) {
19 24
 	conn, err := p.client.DialContext(ctx, network, address)
20 25
 	if err != nil {
@@ -24,6 +29,16 @@ func (p proxyNetwork) DialContext(ctx context.Context, network, address string)
24 29
 	return essentials.WrapNetConn(conn), nil
25 30
 }
26 31
 
32
+func (p proxyNetwork) MakeHTTPClient(
33
+	dialFunc func(context.Context, string, string) (essentials.Conn, error),
34
+) *http.Client {
35
+	if dialFunc == nil {
36
+		dialFunc = p.DialContext
37
+	}
38
+
39
+	return p.Network.MakeHTTPClient(dialFunc)
40
+}
41
+
27 42
 func NewProxyNetwork(base mtglib.Network, proxyURL *url.URL) (*proxyNetwork, error) {
28 43
 	socks, err := proxy.FromURL(proxyURL, base.NativeDialer())
29 44
 	if err != nil {

Laden…
Annuleren
Opslaan