From 7bc98503a82a68a1b2c12acffe565c0b23783ef5 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Thu, 29 Dec 2016 00:56:17 +0100 Subject: [PATCH] remove buggy CloseWrite() --- app/proxy/proxy_test.go | 1 + proxy/dokodemo/dokodemo_test.go | 1 + proxy/freedom/freedom.go | 4 ---- proxy/freedom/freedom_test.go | 7 +++++-- testing/scenarios/dynamic_vmess_test.go | 27 +++++++++++++++++++------ 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/app/proxy/proxy_test.go b/app/proxy/proxy_test.go index 6a8c95f9f..14bd0d7ef 100644 --- a/app/proxy/proxy_test.go +++ b/app/proxy/proxy_test.go @@ -13,6 +13,7 @@ import ( "v2ray.com/core/testing/assert" "v2ray.com/core/testing/servers/tcp" "v2ray.com/core/transport/internet" + _ "v2ray.com/core/transport/internet/tcp" ) func TestProxyDial(t *testing.T) { diff --git a/proxy/dokodemo/dokodemo_test.go b/proxy/dokodemo/dokodemo_test.go index 9e90f2f02..2608cbb99 100644 --- a/proxy/dokodemo/dokodemo_test.go +++ b/proxy/dokodemo/dokodemo_test.go @@ -18,6 +18,7 @@ import ( "v2ray.com/core/testing/servers/tcp" "v2ray.com/core/testing/servers/udp" "v2ray.com/core/transport/internet" + _ "v2ray.com/core/transport/internet/tcp" ) func TestDokodemoTCP(t *testing.T) { diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index cacbea328..28ca93d4e 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -15,7 +15,6 @@ import ( "v2ray.com/core/common/serial" "v2ray.com/core/proxy" "v2ray.com/core/transport/internet" - "v2ray.com/core/transport/internet/tcp" "v2ray.com/core/transport/ray" ) @@ -109,9 +108,6 @@ func (v *Handler) Dispatch(destination v2net.Destination, payload *buf.Buffer, r if err := buf.PipeUntilEOF(input, v2writer); err != nil { log.Info("Freedom: Failed to transport all TCP request: ", err) } - if tcpConn, ok := conn.(*tcp.RawConnection); ok { - tcpConn.CloseWrite() - } }() var reader io.Reader = conn diff --git a/proxy/freedom/freedom_test.go b/proxy/freedom/freedom_test.go index 980fb1c1e..1bf8e473e 100644 --- a/proxy/freedom/freedom_test.go +++ b/proxy/freedom/freedom_test.go @@ -1,6 +1,7 @@ package freedom_test import ( + "fmt" "testing" "v2ray.com/core/app" @@ -18,6 +19,7 @@ import ( "v2ray.com/core/testing/assert" "v2ray.com/core/testing/servers/tcp" "v2ray.com/core/transport/internet" + _ "v2ray.com/core/transport/internet/tcp" "v2ray.com/core/transport/ray" ) @@ -32,7 +34,7 @@ func TestSinglePacket(t *testing.T) { return buffer }, } - _, err := tcpServer.Start() + tcpServerAddr, err := tcpServer.Start() assert.Error(err).IsNil() space := app.NewSpace() @@ -52,7 +54,8 @@ func TestSinglePacket(t *testing.T) { payload := buf.NewLocal(2048) payload.Append([]byte(data2Send)) - go freedom.Dispatch(v2net.TCPDestination(v2net.LocalHostIP, tcpServer.Port), payload, traffic) + fmt.Println(tcpServerAddr.Network, tcpServerAddr.Address, tcpServerAddr.Port) + go freedom.Dispatch(tcpServerAddr, payload, traffic) traffic.InboundInput().Close() respPayload, err := traffic.InboundOutput().Read() diff --git a/testing/scenarios/dynamic_vmess_test.go b/testing/scenarios/dynamic_vmess_test.go index 472cf3f76..e6e016931 100644 --- a/testing/scenarios/dynamic_vmess_test.go +++ b/testing/scenarios/dynamic_vmess_test.go @@ -1,11 +1,11 @@ package scenarios import ( - "bytes" - "io" + "fmt" "net" "testing" + "v2ray.com/core/common/buf" v2net "v2ray.com/core/common/net" "v2ray.com/core/testing/assert" "v2ray.com/core/testing/servers/tcp" @@ -43,10 +43,25 @@ func TestDynamicVMess(t *testing.T) { conn.CloseWrite() - response := bytes.NewBuffer(nil) - _, err = io.Copy(response, conn) - assert.Error(err).IsNil() - assert.String("Processed: " + payload).Equals(string(response.Bytes())) + expectedResponse := "Processed: " + payload + finished := false + response := buf.New() + for { + err := response.AppendSupplier(buf.ReadFrom(conn)) + assert.Error(err).IsNil() + if err != nil { + break + } + if response.String() == expectedResponse { + finished = true + break + } + if response.Len() > len(expectedResponse) { + fmt.Printf("Unexpected response: %v\n", response.Bytes()) + break + } + } + assert.Bool(finished).IsTrue() conn.Close() }