discard bad connections

pull/168/head
v2ray 9 years ago
parent 4ec96efe84
commit 43f6998d31

@ -169,7 +169,11 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
} else { } else {
requestReader = v2io.NewAdaptiveReader(bodyReader) requestReader = v2io.NewAdaptiveReader(bodyReader)
} }
v2io.Pipe(requestReader, input) err := v2io.Pipe(requestReader, input)
if err != vmessio.ErrorStreamCompleted {
connection.SetReusable(false)
}
requestReader.Release() requestReader.Release()
input.Close() input.Close()
readFinish.Unlock() readFinish.Unlock()
@ -197,7 +201,11 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) {
writer.SetCached(false) writer.SetCached(false)
v2io.Pipe(output, v2writer) err = v2io.Pipe(output, v2writer)
if err != vmessio.ErrorStreamCompleted {
connection.SetReusable(false)
}
output.Release() output.Release()
if request.Option.IsChunkStream() { if request.Option.IsChunkStream() {
v2writer.Write(alloc.NewSmallBuffer().Clear()) v2writer.Write(alloc.NewSmallBuffer().Clear())

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

@ -1,7 +1,6 @@
package outbound package outbound
import ( import (
"net"
"sync" "sync"
"github.com/v2ray/v2ray-core/app" "github.com/v2ray/v2ray-core/app"
@ -70,7 +69,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
return nil return nil
} }
func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn net.Conn, request *protocol.RequestHeader, payload *alloc.Buffer, input v2io.Reader, finish *sync.Mutex) { func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn *hub.Connection, request *protocol.RequestHeader, payload *alloc.Buffer, input v2io.Reader, finish *sync.Mutex) {
defer finish.Unlock() defer finish.Unlock()
writer := v2io.NewBufferedWriter(conn) writer := v2io.NewBufferedWriter(conn)
@ -85,7 +84,11 @@ func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn
streamWriter.Write(payload) streamWriter.Write(payload)
writer.SetCached(false) writer.SetCached(false)
v2io.Pipe(input, streamWriter) err := v2io.Pipe(input, streamWriter)
if err != vmessio.ErrorStreamCompleted {
conn.SetReusable(false)
}
if request.Option.IsChunkStream() { if request.Option.IsChunkStream() {
streamWriter.Write(alloc.NewSmallBuffer().Clear()) streamWriter.Write(alloc.NewSmallBuffer().Clear())
} }
@ -93,7 +96,7 @@ func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn
return return
} }
func (this *VMessOutboundHandler) handleResponse(session *raw.ClientSession, conn net.Conn, request *protocol.RequestHeader, dest v2net.Destination, output v2io.Writer, finish *sync.Mutex) { func (this *VMessOutboundHandler) handleResponse(session *raw.ClientSession, conn *hub.Connection, request *protocol.RequestHeader, dest v2net.Destination, output v2io.Writer, finish *sync.Mutex) {
defer finish.Unlock() defer finish.Unlock()
reader := v2io.NewBufferedReader(conn) reader := v2io.NewBufferedReader(conn)
@ -116,7 +119,11 @@ func (this *VMessOutboundHandler) handleResponse(session *raw.ClientSession, con
bodyReader = v2io.NewAdaptiveReader(decryptReader) bodyReader = v2io.NewAdaptiveReader(decryptReader)
} }
v2io.Pipe(bodyReader, output) err = v2io.Pipe(bodyReader, output)
if err != vmessio.ErrorStreamCompleted {
conn.SetReusable(false)
}
bodyReader.Release() bodyReader.Release()
return return

Loading…
Cancel
Save