From 31d6e744827ceb62f400a55bf61104cba0096270 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Tue, 3 Jan 2017 14:53:59 +0100 Subject: [PATCH] remove rawtcp --- app/proxy/proxy_test.go | 4 +-- common/net/network.go | 4 +-- common/net/network.proto | 2 +- proxy/blackhole/blackhole.go | 2 +- proxy/dokodemo/dokodemo.go | 3 +- proxy/dokodemo/dokodemo_test.go | 8 ++--- proxy/freedom/freedom.go | 4 ++- proxy/freedom/freedom_test.go | 4 +-- proxy/http/server.go | 4 ++- proxy/http/server_test.go | 2 +- proxy/shadowsocks/client.go | 2 +- proxy/shadowsocks/server.go | 2 +- proxy/shadowsocks/shadowsocks.go | 4 ++- proxy/socks/server.go | 4 ++- tools/conf/transport_internet.go | 2 +- transport/internet/dialer.go | 16 ++++----- transport/internet/tcp/connection.go | 14 -------- transport/internet/tcp/connection_test.go | 19 ---------- transport/internet/tcp/dialer.go | 13 ------- transport/internet/tcp/hub.go | 42 +---------------------- transport/internet/tcp_hub.go | 10 +++--- 21 files changed, 41 insertions(+), 124 deletions(-) delete mode 100644 transport/internet/tcp/connection_test.go diff --git a/app/proxy/proxy_test.go b/app/proxy/proxy_test.go index 902cefb38..0500f44a1 100644 --- a/app/proxy/proxy_test.go +++ b/app/proxy/proxy_test.go @@ -25,7 +25,7 @@ func TestProxyDial(t *testing.T) { common.Must(outboundManager.SetHandler("tag", freedom.New(&freedom.Config{}, space, &proxy.OutboundHandlerMeta{ Tag: "tag", StreamSettings: &internet.StreamConfig{ - Network: v2net.Network_RawTCP, + Network: v2net.Network_TCP, }, }))) space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outboundManager) @@ -49,7 +49,7 @@ func TestProxyDial(t *testing.T) { conn, err := proxy.Dial(v2net.LocalHostIP, dest, internet.DialerOptions{ Stream: &internet.StreamConfig{ - Network: v2net.Network_RawTCP, + Network: v2net.Network_TCP, }, Proxy: &internet.ProxyConfig{ Tag: "tag", diff --git a/common/net/network.go b/common/net/network.go index f2f65b368..4a4b770f7 100644 --- a/common/net/network.go +++ b/common/net/network.go @@ -30,7 +30,7 @@ func (v Network) AsList() *NetworkList { func (v Network) SystemString() string { switch v { - case Network_TCP, Network_RawTCP: + case Network_TCP: return "tcp" case Network_UDP, Network_KCP: return "udp" @@ -41,7 +41,7 @@ func (v Network) SystemString() string { func (v Network) URLPrefix() string { switch v { - case Network_TCP, Network_RawTCP: + case Network_TCP: return "tcp" case Network_UDP: return "udp" diff --git a/common/net/network.proto b/common/net/network.proto index 6c14a74f7..db3cc7252 100644 --- a/common/net/network.proto +++ b/common/net/network.proto @@ -10,7 +10,7 @@ enum Network { Unknown = 0; // Native TCP provided by system. - RawTCP = 1; + RawTCP = 1 [deprecated=true]; // V2Ray specific TCP. TCP = 2; diff --git a/proxy/blackhole/blackhole.go b/proxy/blackhole/blackhole.go index 2243fbb23..320ee95db 100644 --- a/proxy/blackhole/blackhole.go +++ b/proxy/blackhole/blackhole.go @@ -43,7 +43,7 @@ type Factory struct{} // StreamCapability implements OutboundHandlerFactory.StreamCapability(). func (v *Factory) StreamCapability() v2net.NetworkList { return v2net.NetworkList{ - Network: []v2net.Network{v2net.Network_RawTCP}, + Network: []v2net.Network{v2net.Network_TCP}, } } diff --git a/proxy/dokodemo/dokodemo.go b/proxy/dokodemo/dokodemo.go index 09918120e..235b5bacd 100644 --- a/proxy/dokodemo/dokodemo.go +++ b/proxy/dokodemo/dokodemo.go @@ -143,6 +143,7 @@ func (v *DokodemoDoor) ListenTCP() error { func (v *DokodemoDoor) HandleTCPConnection(conn internet.Connection) { defer conn.Close() + conn.SetReusable(false) var dest v2net.Destination if v.config.FollowRedirect { @@ -209,7 +210,7 @@ type Factory struct{} func (v *Factory) StreamCapability() v2net.NetworkList { return v2net.NetworkList{ - Network: []v2net.Network{v2net.Network_RawTCP}, + Network: []v2net.Network{v2net.Network_TCP}, } } diff --git a/proxy/dokodemo/dokodemo_test.go b/proxy/dokodemo/dokodemo_test.go index 2608cbb99..cad2adca8 100644 --- a/proxy/dokodemo/dokodemo_test.go +++ b/proxy/dokodemo/dokodemo_test.go @@ -47,7 +47,7 @@ func TestDokodemoTCP(t *testing.T) { &proxy.OutboundHandlerMeta{ Address: v2net.LocalHostIP, StreamSettings: &internet.StreamConfig{ - Network: v2net.Network_RawTCP, + Network: v2net.Network_TCP, }, })) space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, ohm) @@ -64,7 +64,7 @@ func TestDokodemoTCP(t *testing.T) { Address: v2net.LocalHostIP, Port: port, StreamSettings: &internet.StreamConfig{ - Network: v2net.Network_RawTCP, + Network: v2net.Network_TCP, }}) defer dokodemo.Close() @@ -118,7 +118,7 @@ func TestDokodemoUDP(t *testing.T) { &proxy.OutboundHandlerMeta{ Address: v2net.AnyIP, StreamSettings: &internet.StreamConfig{ - Network: v2net.Network_RawTCP, + Network: v2net.Network_TCP, }})) space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, ohm) @@ -134,7 +134,7 @@ func TestDokodemoUDP(t *testing.T) { Address: v2net.LocalHostIP, Port: port, StreamSettings: &internet.StreamConfig{ - Network: v2net.Network_RawTCP, + Network: v2net.Network_TCP, }}) defer dokodemo.Close() diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 8fe0e471e..9b5827d7e 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -94,6 +94,8 @@ func (v *Handler) Dispatch(destination v2net.Destination, payload *buf.Buffer, r } defer conn.Close() + conn.SetReusable(false) + if !payload.IsEmpty() { if _, err := conn.Write(payload.Bytes()); err != nil { log.Warning("Freedom: Failed to write to destination: ", destination, ": ", err) @@ -144,7 +146,7 @@ type Factory struct{} func (v *Factory) StreamCapability() v2net.NetworkList { return v2net.NetworkList{ - Network: []v2net.Network{v2net.Network_RawTCP}, + Network: []v2net.Network{v2net.Network_TCP}, } } diff --git a/proxy/freedom/freedom_test.go b/proxy/freedom/freedom_test.go index 1bf8e473e..093555af3 100644 --- a/proxy/freedom/freedom_test.go +++ b/proxy/freedom/freedom_test.go @@ -44,7 +44,7 @@ func TestSinglePacket(t *testing.T) { &proxy.OutboundHandlerMeta{ Address: v2net.AnyIP, StreamSettings: &internet.StreamConfig{ - Network: v2net.Network_RawTCP, + Network: v2net.Network_TCP, }, }) assert.Error(space.Initialize()).IsNil() @@ -86,7 +86,7 @@ func TestIPResolution(t *testing.T) { &proxy.OutboundHandlerMeta{ Address: v2net.AnyIP, StreamSettings: &internet.StreamConfig{ - Network: v2net.Network_RawTCP, + Network: v2net.Network_TCP, }, }) diff --git a/proxy/http/server.go b/proxy/http/server.go index a17936f89..7ce2132b5 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -100,6 +100,8 @@ func parseHost(rawHost string, defaultPort v2net.Port) (v2net.Destination, error func (v *Server) handleConnection(conn internet.Connection) { defer conn.Close() + conn.SetReusable(false) + timedReader := v2net.NewTimeOutReader(v.config.Timeout, conn) reader := bufio.OriginalReaderSize(timedReader, 2048) @@ -289,7 +291,7 @@ type ServerFactory struct{} // StreamCapability implements InboundHandlerFactory.StreamCapability(). func (v *ServerFactory) StreamCapability() v2net.NetworkList { return v2net.NetworkList{ - Network: []v2net.Network{v2net.Network_RawTCP}, + Network: []v2net.Network{v2net.Network_TCP}, } } diff --git a/proxy/http/server_test.go b/proxy/http/server_test.go index d7fcd1fa1..93bdc7088 100644 --- a/proxy/http/server_test.go +++ b/proxy/http/server_test.go @@ -64,7 +64,7 @@ func TestNormalGetRequest(t *testing.T) { Address: v2net.LocalHostIP, Port: port, StreamSettings: &internet.StreamConfig{ - Network: v2net.Network_RawTCP, + Network: v2net.Network_TCP, }}) defer httpProxy.Close() diff --git a/proxy/shadowsocks/client.go b/proxy/shadowsocks/client.go index a53fb006e..404299eea 100644 --- a/proxy/shadowsocks/client.go +++ b/proxy/shadowsocks/client.go @@ -187,7 +187,7 @@ type ClientFactory struct{} // StreamCapability implements OutboundHandlerFactory.StreamCapability(). func (v *ClientFactory) StreamCapability() v2net.NetworkList { return v2net.NetworkList{ - Network: []v2net.Network{v2net.Network_TCP, v2net.Network_RawTCP}, + Network: []v2net.Network{v2net.Network_TCP}, } } diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index 9f1761f51..710786fc4 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -225,7 +225,7 @@ type ServerFactory struct{} func (v *ServerFactory) StreamCapability() v2net.NetworkList { return v2net.NetworkList{ - Network: []v2net.Network{v2net.Network_TCP, v2net.Network_RawTCP}, + Network: []v2net.Network{v2net.Network_TCP}, } } diff --git a/proxy/shadowsocks/shadowsocks.go b/proxy/shadowsocks/shadowsocks.go index cac631e89..2289662a1 100644 --- a/proxy/shadowsocks/shadowsocks.go +++ b/proxy/shadowsocks/shadowsocks.go @@ -1,7 +1,9 @@ // Package shadowsocks provides compatible functionality to Shadowsocks. // // Shadowsocks client and server are implemented as outbound and inbound respectively in V2Ray's term. -// Shadowsocks OTA is fully supported. +// +// Shadowsocks OTA is fully supported. By default both client and server enable OTA, but it can be optionally disabled. +// // Supperted Ciphers: // * AES-256-CFB // * AES-128-CFB diff --git a/proxy/socks/server.go b/proxy/socks/server.go index e13b2d8ec..41f89ba46 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -107,6 +107,8 @@ func (v *Server) Start() error { func (v *Server) handleConnection(connection internet.Connection) { defer connection.Close() + connection.SetReusable(false) + timedReader := v2net.NewTimeOutReader(v.config.Timeout, connection) reader := bufio.NewReader(timedReader) defer reader.Release() @@ -336,7 +338,7 @@ type ServerFactory struct{} func (v *ServerFactory) StreamCapability() v2net.NetworkList { return v2net.NetworkList{ - Network: []v2net.Network{v2net.Network_RawTCP}, + Network: []v2net.Network{v2net.Network_TCP}, } } diff --git a/tools/conf/transport_internet.go b/tools/conf/transport_internet.go index b34f469ab..1323840f3 100644 --- a/tools/conf/transport_internet.go +++ b/tools/conf/transport_internet.go @@ -185,7 +185,7 @@ type StreamConfig struct { func (v *StreamConfig) Build() (*internet.StreamConfig, error) { config := &internet.StreamConfig{ - Network: v2net.Network_RawTCP, + Network: v2net.Network_TCP, } if v.Network != nil { config.Network = (*v.Network).Build() diff --git a/transport/internet/dialer.go b/transport/internet/dialer.go index 20b5c5283..7ffff0ad1 100644 --- a/transport/internet/dialer.go +++ b/transport/internet/dialer.go @@ -2,6 +2,7 @@ package internet import ( "net" + "v2ray.com/core/common/errors" "v2ray.com/core/common/log" v2net "v2ray.com/core/common/net" @@ -19,12 +20,11 @@ type DialerOptions struct { type Dialer func(src v2net.Address, dest v2net.Destination, options DialerOptions) (Connection, error) var ( - TCPDialer Dialer - KCPDialer Dialer - RawTCPDialer Dialer - UDPDialer Dialer - WSDialer Dialer - ProxyDialer Dialer + TCPDialer Dialer + KCPDialer Dialer + UDPDialer Dialer + WSDialer Dialer + ProxyDialer Dialer ) func Dial(src v2net.Address, dest v2net.Destination, options DialerOptions) (Connection, error) { @@ -43,10 +43,6 @@ func Dial(src v2net.Address, dest v2net.Destination, options DialerOptions) (Con connection, err = KCPDialer(src, dest, options) case v2net.Network_WebSocket: connection, err = WSDialer(src, dest, options) - - // This check has to be the last one. - case v2net.Network_RawTCP: - connection, err = RawTCPDialer(src, dest, options) default: return nil, ErrUnsupportedStreamType } diff --git a/transport/internet/tcp/connection.go b/transport/internet/tcp/connection.go index 5806d51ba..58ec92d60 100644 --- a/transport/internet/tcp/connection.go +++ b/transport/internet/tcp/connection.go @@ -9,20 +9,6 @@ import ( "v2ray.com/core/transport/internet/internal" ) -type RawConnection struct { - net.TCPConn -} - -func (v *RawConnection) Reusable() bool { - return false -} - -func (v *RawConnection) SetReusable(b bool) {} - -func (v *RawConnection) SysFd() (int, error) { - return internal.GetSysFd(&v.TCPConn) -} - type Connection struct { sync.RWMutex id internal.ConnectionID diff --git a/transport/internet/tcp/connection_test.go b/transport/internet/tcp/connection_test.go deleted file mode 100644 index fdce1f5a4..000000000 --- a/transport/internet/tcp/connection_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package tcp_test - -import ( - "net" - "testing" - - "v2ray.com/core/testing/assert" - . "v2ray.com/core/transport/internet/tcp" -) - -func TestRawConnection(t *testing.T) { - assert := assert.On(t) - - rawConn := RawConnection{net.TCPConn{}} - assert.Bool(rawConn.Reusable()).IsFalse() - - rawConn.SetReusable(true) - assert.Bool(rawConn.Reusable()).IsFalse() -} diff --git a/transport/internet/tcp/dialer.go b/transport/internet/tcp/dialer.go index 3cf4df13e..095312f36 100644 --- a/transport/internet/tcp/dialer.go +++ b/transport/internet/tcp/dialer.go @@ -68,19 +68,6 @@ func Dial(src v2net.Address, dest v2net.Destination, options internet.DialerOpti return NewConnection(id, conn, globalCache, tcpSettings), nil } -func DialRaw(src v2net.Address, dest v2net.Destination, options internet.DialerOptions) (internet.Connection, error) { - log.Info("Internet|TCP: Dailing Raw TCP to ", dest) - conn, err := internet.DialToDest(src, dest) - if err != nil { - return nil, err - } - // TODO: handle dialer options - return &RawConnection{ - TCPConn: *conn.(*net.TCPConn), - }, nil -} - func init() { internet.TCPDialer = Dial - internet.RawTCPDialer = DialRaw } diff --git a/transport/internet/tcp/hub.go b/transport/internet/tcp/hub.go index 834919b2e..6acba11e3 100644 --- a/transport/internet/tcp/hub.go +++ b/transport/internet/tcp/hub.go @@ -5,6 +5,7 @@ import ( "net" "sync" "time" + "v2ray.com/core/common/errors" "v2ray.com/core/common/log" v2net "v2ray.com/core/common/net" @@ -156,47 +157,6 @@ func (v *TCPListener) Close() error { return nil } -type RawTCPListener struct { - accepting bool - listener *net.TCPListener -} - -func (v *RawTCPListener) Accept() (internet.Connection, error) { - conn, err := v.listener.AcceptTCP() - if err != nil { - return nil, err - } - return &RawConnection{ - TCPConn: *conn, - }, nil -} - -func (v *RawTCPListener) Addr() net.Addr { - return v.listener.Addr() -} - -func (v *RawTCPListener) Close() error { - v.accepting = false - v.listener.Close() - return nil -} - -func ListenRawTCP(address v2net.Address, port v2net.Port, options internet.ListenOptions) (internet.Listener, error) { - listener, err := net.ListenTCP("tcp", &net.TCPAddr{ - IP: address.IP(), - Port: int(port), - }) - if err != nil { - return nil, err - } - // TODO: handle listen options - return &RawTCPListener{ - accepting: true, - listener: listener, - }, nil -} - func init() { internet.TCPListenFunc = ListenTCP - internet.RawTCPListenFunc = ListenRawTCP } diff --git a/transport/internet/tcp_hub.go b/transport/internet/tcp_hub.go index 5ad802ca7..8d3a76362 100644 --- a/transport/internet/tcp_hub.go +++ b/transport/internet/tcp_hub.go @@ -3,6 +3,7 @@ package internet import ( "net" "sync" + "v2ray.com/core/common/errors" "v2ray.com/core/common/log" v2net "v2ray.com/core/common/net" @@ -12,10 +13,9 @@ import ( var ( ErrClosedConnection = errors.New("Connection already closed.") - KCPListenFunc ListenFunc - TCPListenFunc ListenFunc - RawTCPListenFunc ListenFunc - WSListenFunc ListenFunc + KCPListenFunc ListenFunc + TCPListenFunc ListenFunc + WSListenFunc ListenFunc ) type ListenFunc func(address v2net.Address, port v2net.Port, options ListenOptions) (Listener, error) @@ -49,8 +49,6 @@ func ListenTCP(address v2net.Address, port v2net.Port, callback ConnectionHandle listener, err = KCPListenFunc(address, port, options) case v2net.Network_WebSocket: listener, err = WSListenFunc(address, port, options) - case v2net.Network_RawTCP: - listener, err = RawTCPListenFunc(address, port, options) default: log.Error("Internet|Listener: Unknown stream type: ", settings.Network) err = ErrUnsupportedStreamType