From ef896bf59a8d38a8e267d1f42e331430200c6476 Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Mon, 22 Jul 2024 21:59:33 -0400 Subject: [PATCH] fix sth --- engine/engine.go | 2 +- engine/parse.go | 5 ----- proxy/direct/direct.go | 2 +- proxy/http/http.go | 2 +- proxy/protocol.go | 3 ++- proxy/relay/relay.go | 2 +- proxy/shadowsocks/shadowsocks.go | 2 +- proxy/socks5/socks5.go | 2 +- 8 files changed, 8 insertions(+), 12 deletions(-) diff --git a/engine/engine.go b/engine/engine.go index 8563fd30..2eced55e 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -189,7 +189,7 @@ func netstack(k *Key) (err error) { } }() - if _defaultProxy, err = parseProxy(k.Proxy); err != nil { + if _defaultProxy, err = proxy.ParseFromURL(k.Proxy); err != nil { return } proxy.DefaultProxy = _defaultProxy diff --git a/engine/parse.go b/engine/parse.go index cd6cf3d3..32923eae 100644 --- a/engine/parse.go +++ b/engine/parse.go @@ -9,7 +9,6 @@ import ( "github.com/xjasonlyu/tun2socks/v2/core/device" "github.com/xjasonlyu/tun2socks/v2/core/device/fdbased" "github.com/xjasonlyu/tun2socks/v2/core/device/tun" - "github.com/xjasonlyu/tun2socks/v2/proxy" ) func parseRestAPI(s string) (*url.URL, error) { @@ -65,10 +64,6 @@ func parseFD(u *url.URL, mtu uint32) (device.Device, error) { return fdbased.Open(u.Host, mtu, 0) } -func parseProxy(s string) (proxy.Proxy, error) { - return proxy.ParseFromURL(s) -} - func parseMulticastGroups(s string) (multicastGroups []net.IP, _ error) { ipStrings := strings.Split(s, ",") for _, ipString := range ipStrings { diff --git a/proxy/direct/direct.go b/proxy/direct/direct.go index abfdec45..5dc1e6e2 100644 --- a/proxy/direct/direct.go +++ b/proxy/direct/direct.go @@ -18,7 +18,7 @@ const protocol = "direct" type Direct struct{ *base.Base } -func New() *Direct { return &Direct{base.New(protocol, "")} } +func New() *Direct { return &Direct{base.New("", protocol)} } func Parse(*url.URL) (proxy.Proxy, error) { return New(), nil } diff --git a/proxy/http/http.go b/proxy/http/http.go index b20dd38a..a99274b7 100644 --- a/proxy/http/http.go +++ b/proxy/http/http.go @@ -31,7 +31,7 @@ type HTTP struct { func New(addr, user, pass string) (*HTTP, error) { return &HTTP{ - Base: base.New(protocol, addr), + Base: base.New(addr, protocol), user: user, pass: pass, }, nil diff --git a/proxy/protocol.go b/proxy/protocol.go index a2fca7ae..1cf83cae 100644 --- a/proxy/protocol.go +++ b/proxy/protocol.go @@ -2,6 +2,7 @@ package proxy import ( "errors" + "fmt" "net/url" "sync" @@ -56,7 +57,7 @@ func Parse(proxyURL *url.URL) (Proxy, error) { } p := pick(proxyURL.Scheme) if p.parse == nil { - return nil, ErrProtocol + return nil, fmt.Errorf("%w: %s", ErrProtocol, proxyURL.Scheme) } return p.parse(proxyURL) } diff --git a/proxy/relay/relay.go b/proxy/relay/relay.go index 8ef113c1..335df29d 100644 --- a/proxy/relay/relay.go +++ b/proxy/relay/relay.go @@ -38,7 +38,7 @@ type Relay struct { func New(addr, user, pass string, noDelay bool) (*Relay, error) { return &Relay{ - Base: base.New(protocol, addr), + Base: base.New(addr, protocol), user: user, pass: pass, noDelay: noDelay, diff --git a/proxy/shadowsocks/shadowsocks.go b/proxy/shadowsocks/shadowsocks.go index 91ba998e..90d5a016 100644 --- a/proxy/shadowsocks/shadowsocks.go +++ b/proxy/shadowsocks/shadowsocks.go @@ -39,7 +39,7 @@ func New(addr, method, password, obfsMode, obfsHost string) (*Shadowsocks, error } return &Shadowsocks{ - Base: base.New(protocol, addr), + Base: base.New(addr, protocol), cipher: cipher, obfsMode: obfsMode, obfsHost: obfsHost, diff --git a/proxy/socks5/socks5.go b/proxy/socks5/socks5.go index c78f42f8..cf2cfb18 100644 --- a/proxy/socks5/socks5.go +++ b/proxy/socks5/socks5.go @@ -32,7 +32,7 @@ type Socks5 struct { func New(addr, user, pass string) (*Socks5, error) { return &Socks5{ - Base: base.New(protocol, addr), + Base: base.New(addr, protocol), user: user, pass: pass, unix: len(addr) > 0 && addr[0] == '/',