mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-04-22 21:49:10 -04:00
send reuse option in header
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||
vmessio "github.com/v2ray/v2ray-core/proxy/vmess/io"
|
||||
"github.com/v2ray/v2ray-core/transport"
|
||||
"github.com/v2ray/v2ray-core/transport/hub"
|
||||
)
|
||||
|
||||
@@ -145,7 +146,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
|
||||
log.Access(connection.RemoteAddr(), request.Destination(), log.AccessAccepted, "")
|
||||
log.Debug("VMessIn: Received request for ", request.Destination())
|
||||
|
||||
if request.Option.IsChunkStream() {
|
||||
if request.Option.Has(protocol.RequestOptionConnectionReuse) {
|
||||
connection.SetReusable(true)
|
||||
}
|
||||
|
||||
@@ -161,10 +162,11 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
|
||||
userSettings := protocol.GetUserSettings(request.User.Level)
|
||||
connReader.SetTimeOut(userSettings.PayloadReadTimeout)
|
||||
reader.SetCached(false)
|
||||
|
||||
go func() {
|
||||
bodyReader := session.DecodeRequestBody(reader)
|
||||
var requestReader v2io.Reader
|
||||
if request.Option.IsChunkStream() {
|
||||
if request.Option.Has(protocol.RequestOptionChunkStream) {
|
||||
requestReader = vmessio.NewAuthChunkReader(bodyReader)
|
||||
} else {
|
||||
requestReader = v2io.NewAdaptiveReader(bodyReader)
|
||||
@@ -186,6 +188,10 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
|
||||
Command: this.generateCommand(request),
|
||||
}
|
||||
|
||||
if request.Option.Has(protocol.RequestOptionConnectionReuse) && transport.IsConnectionReusable() {
|
||||
response.Option.Set(protocol.ResponseOptionConnectionReuse)
|
||||
}
|
||||
|
||||
session.EncodeResponseHeader(response, writer)
|
||||
|
||||
bodyWriter := session.EncodeResponseBody(writer)
|
||||
@@ -193,7 +199,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
|
||||
// Optimize for small response packet
|
||||
if data, err := output.Read(); err == nil {
|
||||
var v2writer v2io.Writer = v2io.NewAdaptiveWriter(bodyWriter)
|
||||
if request.Option.IsChunkStream() {
|
||||
if request.Option.Has(protocol.RequestOptionChunkStream) {
|
||||
v2writer = vmessio.NewAuthChunkWriter(v2writer)
|
||||
}
|
||||
|
||||
@@ -207,7 +213,7 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
|
||||
}
|
||||
|
||||
output.Release()
|
||||
if request.Option.IsChunkStream() {
|
||||
if request.Option.Has(protocol.RequestOptionChunkStream) {
|
||||
v2writer.Write(alloc.NewSmallBuffer().Clear())
|
||||
}
|
||||
v2writer.Release()
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||
vmessio "github.com/v2ray/v2ray-core/proxy/vmess/io"
|
||||
"github.com/v2ray/v2ray-core/transport"
|
||||
"github.com/v2ray/v2ray-core/transport/hub"
|
||||
"github.com/v2ray/v2ray-core/transport/ray"
|
||||
)
|
||||
@@ -49,7 +50,9 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
|
||||
log.Info("VMessOut: Tunneling request to ", request.Address, " via ", destination)
|
||||
|
||||
defer conn.Close()
|
||||
if request.Option.IsChunkStream() {
|
||||
|
||||
if transport.IsConnectionReusable() {
|
||||
request.Option.Set(protocol.RequestOptionConnectionReuse)
|
||||
conn.SetReusable(true)
|
||||
}
|
||||
|
||||
@@ -79,7 +82,7 @@ func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn
|
||||
|
||||
bodyWriter := session.EncodeRequestBody(writer)
|
||||
var streamWriter v2io.Writer = v2io.NewAdaptiveWriter(bodyWriter)
|
||||
if request.Option.IsChunkStream() {
|
||||
if request.Option.Has(protocol.RequestOptionChunkStream) {
|
||||
streamWriter = vmessio.NewAuthChunkWriter(streamWriter)
|
||||
}
|
||||
streamWriter.Write(payload)
|
||||
@@ -90,8 +93,11 @@ func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn
|
||||
conn.SetReusable(false)
|
||||
}
|
||||
|
||||
if request.Option.IsChunkStream() {
|
||||
streamWriter.Write(alloc.NewSmallBuffer().Clear())
|
||||
if request.Option.Has(protocol.RequestOptionChunkStream) {
|
||||
err := streamWriter.Write(alloc.NewSmallBuffer().Clear())
|
||||
if err != nil {
|
||||
conn.SetReusable(false)
|
||||
}
|
||||
}
|
||||
streamWriter.Release()
|
||||
return
|
||||
@@ -110,11 +116,15 @@ func (this *VMessOutboundHandler) handleResponse(session *raw.ClientSession, con
|
||||
}
|
||||
go this.handleCommand(dest, header.Command)
|
||||
|
||||
if !header.Option.Has(protocol.ResponseOptionConnectionReuse) {
|
||||
conn.SetReusable(false)
|
||||
}
|
||||
|
||||
reader.SetCached(false)
|
||||
decryptReader := session.DecodeResponseBody(reader)
|
||||
|
||||
var bodyReader v2io.Reader
|
||||
if request.Option.IsChunkStream() {
|
||||
if request.Option.Has(protocol.RequestOptionChunkStream) {
|
||||
bodyReader = vmessio.NewAuthChunkReader(decryptReader)
|
||||
} else {
|
||||
bodyReader = v2io.NewAdaptiveReader(decryptReader)
|
||||
|
||||
Reference in New Issue
Block a user