v2ray 9 роки тому
батько
коміт
dfe1ac1f2b

+ 2 - 2
proxy/vmess/inbound/inbound.go

@@ -170,7 +170,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
 			requestReader = v2io.NewAdaptiveReader(bodyReader)
 		}
 		err := v2io.Pipe(requestReader, input)
-		if err != vmessio.ErrorStreamCompleted {
+		if err != io.EOF {
 			connection.SetReusable(false)
 		}
 
@@ -202,7 +202,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
 		writer.SetCached(false)
 
 		err = v2io.Pipe(output, v2writer)
-		if err != vmessio.ErrorStreamCompleted {
+		if err != io.EOF {
 			connection.SetReusable(false)
 		}
 

+ 1 - 6
proxy/vmess/io/reader.go

@@ -1,7 +1,6 @@
 package io
 
 import (
-	"errors"
 	"hash"
 	"hash/fnv"
 	"io"
@@ -11,10 +10,6 @@ import (
 	"github.com/v2ray/v2ray-core/transport"
 )
 
-var (
-	ErrorStreamCompleted = errors.New("Stream completed.")
-)
-
 // @Private
 type Validator struct {
 	actualAuth   hash.Hash32
@@ -81,7 +76,7 @@ func (this *AuthChunkReader) Read() (*alloc.Buffer, error) {
 
 	if this.chunkLength == 0 {
 		buffer.Release()
-		return nil, ErrorStreamCompleted
+		return nil, io.EOF
 	}
 
 	if buffer.Len() < this.chunkLength {

+ 3 - 2
proxy/vmess/outbound/outbound.go

@@ -1,6 +1,7 @@
 package outbound
 
 import (
+	"io"
 	"sync"
 
 	"github.com/v2ray/v2ray-core/app"
@@ -85,7 +86,7 @@ func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn
 	writer.SetCached(false)
 
 	err := v2io.Pipe(input, streamWriter)
-	if err != vmessio.ErrorStreamCompleted {
+	if err != io.EOF {
 		conn.SetReusable(false)
 	}
 
@@ -120,7 +121,7 @@ func (this *VMessOutboundHandler) handleResponse(session *raw.ClientSession, con
 	}
 
 	err = v2io.Pipe(bodyReader, output)
-	if err != vmessio.ErrorStreamCompleted {
+	if err != io.EOF {
 		conn.SetReusable(false)
 	}
 

+ 6 - 0
testing/scenarios/data/test_4_client.json

@@ -29,5 +29,11 @@
         }
       ]
     }
+  },
+  "transport": {
+    "streamType": "tcp",
+    "settings": {
+      "connectionReuse": true
+    }
   }
 }

+ 7 - 1
testing/scenarios/data/test_4_server.json

@@ -38,5 +38,11 @@
         "refresh": 5
       }
     }
-  ]
+  ],
+  "transport": {
+    "streamType": "tcp",
+    "settings": {
+      "connectionReuse": true
+    }
+  }
 }

+ 3 - 1
transport/config_json.go

@@ -21,10 +21,12 @@ func (this *Config) UnmarshalJSON(data []byte) error {
 		return err
 	}
 
+	this.StreamType = StreamTypeTCP
+
 	streamType := strings.ToLower(typeConfig.StreamType)
 	if streamType == "tcp" {
 		jsonTCPConfig := new(JsonTCPConfig)
-		if err := json.Unmarshal(data, jsonTCPConfig); err != nil {
+		if err := json.Unmarshal(typeConfig.Settings, jsonTCPConfig); err != nil {
 			return err
 		}
 		this.TCPConfig = &TCPConfig{

+ 3 - 3
transport/transport.go

@@ -3,7 +3,7 @@ package transport
 import "github.com/v2ray/v2ray-core/common/log"
 
 var (
-	TCPStreamConfig = &TCPConfig{
+	TCPStreamConfig = TCPConfig{
 		ConnectionReuse: false,
 	}
 )
@@ -11,8 +11,8 @@ var (
 func ApplyConfig(config *Config) error {
 	if config.StreamType == StreamTypeTCP {
 		if config.TCPConfig != nil {
-			TCPStreamConfig = config.TCPConfig
-			if config.TCPConfig.ConnectionReuse {
+			TCPStreamConfig.ConnectionReuse = config.TCPConfig.ConnectionReuse
+			if TCPStreamConfig.ConnectionReuse {
 				log.Info("Transport: TCP connection reuse enabled.")
 			}
 		}