mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 13:04:02 +03:00
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.
This commit is contained in:
@@ -3,6 +3,7 @@ package network
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/9seconds/mtg/v2/essentials"
|
"github.com/9seconds/mtg/v2/essentials"
|
||||||
@@ -15,6 +16,10 @@ type proxyNetwork struct {
|
|||||||
client proxy.ContextDialer
|
client proxy.ContextDialer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p proxyNetwork) Dial(network, address string) (essentials.Conn, error) {
|
||||||
|
return p.DialContext(context.Background(), network, address)
|
||||||
|
}
|
||||||
|
|
||||||
func (p proxyNetwork) DialContext(ctx context.Context, network, address string) (essentials.Conn, error) {
|
func (p proxyNetwork) DialContext(ctx context.Context, network, address string) (essentials.Conn, error) {
|
||||||
conn, err := p.client.DialContext(ctx, network, address)
|
conn, err := p.client.DialContext(ctx, network, address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -24,6 +29,16 @@ func (p proxyNetwork) DialContext(ctx context.Context, network, address string)
|
|||||||
return essentials.WrapNetConn(conn), nil
|
return essentials.WrapNetConn(conn), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p proxyNetwork) MakeHTTPClient(
|
||||||
|
dialFunc func(context.Context, string, string) (essentials.Conn, error),
|
||||||
|
) *http.Client {
|
||||||
|
if dialFunc == nil {
|
||||||
|
dialFunc = p.DialContext
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.Network.MakeHTTPClient(dialFunc)
|
||||||
|
}
|
||||||
|
|
||||||
func NewProxyNetwork(base mtglib.Network, proxyURL *url.URL) (*proxyNetwork, error) {
|
func NewProxyNetwork(base mtglib.Network, proxyURL *url.URL) (*proxyNetwork, error) {
|
||||||
socks, err := proxy.FromURL(proxyURL, base.NativeDialer())
|
socks, err := proxy.FromURL(proxyURL, base.NativeDialer())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user