From 58530e692061b117b8f68a028362d4f67c50d326 Mon Sep 17 00:00:00 2001 From: v2ray Date: Thu, 28 Apr 2016 21:14:00 +0200 Subject: [PATCH] force chunked stream --- proxy/vmess/inbound/inbound.go | 6 +++++- proxy/vmess/io/reader.go | 3 +++ proxy/vmess/outbound/outbound.go | 11 ++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index 6ac3c8d6..b4359b50 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -6,6 +6,7 @@ import ( "github.com/v2ray/v2ray-core/app" "github.com/v2ray/v2ray-core/app/dispatcher" "github.com/v2ray/v2ray-core/app/proxyman" + "github.com/v2ray/v2ray-core/common/alloc" v2io "github.com/v2ray/v2ray-core/common/io" "github.com/v2ray/v2ray-core/common/log" v2net "github.com/v2ray/v2ray-core/common/net" @@ -185,6 +186,9 @@ func (this *VMessInboundHandler) HandleConnection(connection hub.Connection) { writer = vmessio.NewAuthChunkWriter(writer) } v2io.Pipe(output, writer) + if request.Option.IsChunkStream() { + writer.Write(alloc.NewSmallBuffer().Clear()) + } output.Release() writer.Release() finish.Unlock() @@ -192,8 +196,8 @@ func (this *VMessInboundHandler) HandleConnection(connection hub.Connection) { writeFinish.Lock() } - connection.CloseWrite() readFinish.Lock() + writeFinish.Lock() } func init() { diff --git a/proxy/vmess/io/reader.go b/proxy/vmess/io/reader.go index 188b8bf8..5f67edc2 100644 --- a/proxy/vmess/io/reader.go +++ b/proxy/vmess/io/reader.go @@ -27,6 +27,9 @@ func (this *AuthChunkReader) Read() (*alloc.Buffer, error) { } length := serial.BytesLiteral(buffer.Value[:2]).Uint16Value() + if length == 4 { // Length of authentication bytes. + return nil, io.EOF + } if _, err := io.ReadFull(this.reader, buffer.Value[:length]); err != nil { buffer.Release() return nil, err diff --git a/proxy/vmess/outbound/outbound.go b/proxy/vmess/outbound/outbound.go index 1c470a9c..5343271e 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/proxy/vmess/outbound/outbound.go @@ -35,9 +35,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al Command: command, Address: target.Address(), Port: target.Port(), - } - if command == proto.RequestCommandUDP { - request.Option |= proto.RequestOptionChunkStream + Option: proto.RequestOptionChunkStream, } conn, err := dialer.Dial(destination) @@ -65,10 +63,6 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al go this.handleResponse(session, conn, request, destination, output, &responseFinish) requestFinish.Lock() - if tcpConn, ok := conn.(*net.TCPConn); ok { - tcpConn.CloseWrite() - } - responseFinish.Lock() output.Close() input.Release() @@ -97,6 +91,9 @@ func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn streamWriter = vmessio.NewAuthChunkWriter(streamWriter) } v2io.Pipe(input, streamWriter) + if request.Option.IsChunkStream() { + streamWriter.Write(alloc.NewSmallBuffer().Clear()) + } streamWriter.Release() return }