diff --git a/core/src/foss/golang/clash b/core/src/foss/golang/clash index 150bf7fc..e4abecd4 160000 --- a/core/src/foss/golang/clash +++ b/core/src/foss/golang/clash @@ -1 +1 @@ -Subproject commit 150bf7fc65c7736d7c56e2ce7866f03a620d9014 +Subproject commit e4abecd4e25514ec0266e6d855de328a449dbfd1 diff --git a/core/src/main/golang/native/config/fetch.go b/core/src/main/golang/native/config/fetch.go index 8d2d4367..7ead8f12 100644 --- a/core/src/main/golang/native/config/fetch.go +++ b/core/src/main/golang/native/config/fetch.go @@ -1,6 +1,7 @@ package config import ( + "context" "encoding/json" "fmt" "io" @@ -12,7 +13,8 @@ import ( "time" "cfa/native/app" - "github.com/Dreamacro/clash/component/dialer" + + clashHttp "github.com/Dreamacro/clash/component/http" ) type Status struct { @@ -22,30 +24,15 @@ type Status struct { MaxProgress int `json:"max"` } -var client = &http.Client{ - Transport: &http.Transport{ - DisableKeepAlives: true, - TLSHandshakeTimeout: 10 * time.Second, - ExpectContinueTimeout: 1 * time.Second, - DialContext: dialer.DialTunnelContext, - }, - Timeout: 60 * time.Second, -} - func openUrl(url string) (io.ReadCloser, error) { - request, err := http.NewRequest(http.MethodGet, url, nil) + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel() + response, err := clashHttp.HttpRequest(ctx, url, http.MethodGet, http.Header{"User-Agent": {"ClashMetaForAndroid/" + app.VersionName()}}, nil) if err != nil { return nil, err } - request.Header.Set("User-Agent", "ClashMetaForAndroid/"+app.VersionName()) - - response, err := client.Do(request) - if err != nil { - return nil, err - } - return response.Body, nil } diff --git a/core/src/main/golang/native/tunnel/init.go b/core/src/main/golang/native/tunnel/init.go deleted file mode 100644 index 9f57b859..00000000 --- a/core/src/main/golang/native/tunnel/init.go +++ /dev/null @@ -1,43 +0,0 @@ -package tunnel - -import ( - "context" - "net" - "strconv" - "strings" - - "github.com/Dreamacro/clash/component/dialer" - C "github.com/Dreamacro/clash/constant" - "github.com/Dreamacro/clash/tunnel" -) - -func init() { - dialer.DefaultTunnelDialer = func(context context.Context, network, address string) (net.Conn, error) { - if !strings.HasPrefix(network, "tcp") { - return nil, net.UnknownNetworkError("unsupported network") - } - - host, port, err := net.SplitHostPort(address) - dstPort, _ := strconv.Atoi(port) - if err != nil { - return nil, err - } - - left, right := net.Pipe() - - metadata := &C.Metadata{ - NetWork: C.TCP, - Type: C.HTTPS, - SrcIP: loopback, - SrcPort: 65535, - DstPort: uint16(dstPort), - Host: host, - RawSrcAddr: left.RemoteAddr(), - RawDstAddr: left.LocalAddr(), - } - - go tunnel.Tunnel.HandleTCPConn(right, metadata) - - return left, nil - } -}