Procházet zdrojové kódy

Fixed h2c enable crash bug

Toby Chui před 4 týdny
rodič
revize
fe83f9b94c
7 změnil soubory, kde provedl 503 přidání a 407 odebrání
  1. 1 1
      def.go
  2. 1 1
      go.mod
  3. 7 12
      mod/dynamicproxy/dpcore/dpcore.go
  4. 45 0
      mod/dynamicproxy/modh2c/modh2c.go
  5. 203 223
      mod/geodb/geoipv4.csv
  6. 238 170
      mod/geodb/geoipv6.csv
  7. 8 0
      reverseproxy.go

+ 1 - 1
def.go

@@ -43,7 +43,7 @@ const (
 	/* Build Constants */
 	SYSTEM_NAME       = "Zoraxy"
 	SYSTEM_VERSION    = "3.1.7"
-	DEVELOPMENT_BUILD = true /* Development: Set to false to use embedded web fs */
+	DEVELOPMENT_BUILD = false /* Development: Set to false to use embedded web fs */
 
 	/* System Constants */
 	TMP_FOLDER                 = "./tmp"

+ 1 - 1
go.mod

@@ -16,6 +16,7 @@ require (
 	github.com/grandcat/zeroconf v1.0.0
 	github.com/likexian/whois v1.15.1
 	github.com/microcosm-cc/bluemonday v1.0.26
+	github.com/syndtr/goleveldb v1.0.0
 	golang.org/x/net v0.29.0
 	golang.org/x/sys v0.25.0
 	golang.org/x/text v0.18.0
@@ -32,7 +33,6 @@ require (
 	github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.114 // indirect
 	github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
 	github.com/shopspring/decimal v1.3.1 // indirect
-	github.com/syndtr/goleveldb v1.0.0 // indirect
 	github.com/tidwall/btree v0.0.0-20191029221954-400434d76274 // indirect
 	github.com/tidwall/buntdb v1.1.2 // indirect
 	github.com/tidwall/gjson v1.12.1 // indirect

+ 7 - 12
mod/dynamicproxy/dpcore/dpcore.go

@@ -2,7 +2,6 @@ package dpcore
 
 import (
 	"context"
-	"crypto/tls"
 	"errors"
 	"io"
 	"log"
@@ -12,8 +11,8 @@ import (
 	"strings"
 	"time"
 
-	"golang.org/x/net/http2"
 	"imuslab.com/zoraxy/mod/dynamicproxy/domainsniff"
+	"imuslab.com/zoraxy/mod/dynamicproxy/modh2c"
 	"imuslab.com/zoraxy/mod/dynamicproxy/permissionpolicy"
 )
 
@@ -104,14 +103,6 @@ func NewDynamicProxyCore(target *url.URL, prepender string, dpcOptions *DpcoreOp
 	}
 
 	thisTransporter := http.DefaultTransport
-	if dpcOptions.UseH2CRoundTripper {
-		thisTransporter = &http2.Transport{
-			DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
-				return net.Dial(network, addr)
-			},
-			AllowHTTP: true,
-		}
-	}
 
 	//Hack the default transporter to handle more connections
 	optimalConcurrentConnection := 32
@@ -121,13 +112,17 @@ func NewDynamicProxyCore(target *url.URL, prepender string, dpcOptions *DpcoreOp
 	thisTransporter.(*http.Transport).MaxConnsPerHost = optimalConcurrentConnection * 2
 	thisTransporter.(*http.Transport).DisableCompression = true
 
-	//TODO: Add user adjustable timeout option here
-
 	if dpcOptions.IgnoreTLSVerification {
 		//Ignore TLS certificate validation error
 		thisTransporter.(*http.Transport).TLSClientConfig.InsecureSkipVerify = true
 	}
 
+	//TODO: Add user adjustable timeout option here
+	if dpcOptions.UseH2CRoundTripper {
+		//Use H2C RoundTripper for HTTP/2.0 connection
+		thisTransporter = modh2c.NewH2CRoundTripper()
+	}
+
 	return &ReverseProxy{
 		Director:      director,
 		Prepender:     prepender,

+ 45 - 0
mod/dynamicproxy/modh2c/modh2c.go

@@ -0,0 +1,45 @@
+package modh2c
+
+/*
+	modh2c.go
+
+	This module is a simple h2c roundtripper for dpcore
+*/
+
+import (
+	"context"
+	"crypto/tls"
+	"net"
+	"net/http"
+	"time"
+
+	"golang.org/x/net/http2"
+)
+
+type H2CRoundTripper struct {
+}
+
+func NewH2CRoundTripper() *H2CRoundTripper {
+	return &H2CRoundTripper{}
+}
+
+// Example from https://github.com/thrawn01/h2c-golang-example/blob/master/cmd/client/main.go
+func (h2c *H2CRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
+	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
+	defer cancel()
+
+	req, err := http.NewRequestWithContext(ctx, req.Method, req.RequestURI, nil)
+	if err != nil {
+		return nil, err
+	}
+
+	tr := &http2.Transport{
+		AllowHTTP: true,
+		DialTLSContext: func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) {
+			var d net.Dialer
+			return d.DialContext(ctx, network, addr)
+		},
+	}
+
+	return tr.RoundTrip(req)
+}

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 203 - 223
mod/geodb/geoipv4.csv


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 238 - 170
mod/geodb/geoipv6.csv


+ 8 - 0
reverseproxy.go

@@ -313,6 +313,14 @@ func ReverseProxyHandleAddEndpoint(w http.ResponseWriter, r *http.Request) {
 			tags[i] = strings.TrimSpace(tags[i])
 		}
 	}
+	// Remove empty tags
+	filteredTags := []string{}
+	for _, tag := range tags {
+		if tag != "" {
+			filteredTags = append(filteredTags, tag)
+		}
+	}
+	tags = filteredTags
 
 	var proxyEndpointCreated *dynamicproxy.ProxyEndpoint
 	if eptype == "host" {

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů