1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

remove rawtcp

This commit is contained in:
Darien Raymond 2017-01-03 14:53:59 +01:00
parent 3732de18b1
commit 31d6e74482
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
21 changed files with 41 additions and 124 deletions

View File

@ -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",

View File

@ -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"

View File

@ -10,7 +10,7 @@ enum Network {
Unknown = 0;
// Native TCP provided by system.
RawTCP = 1;
RawTCP = 1 [deprecated=true];
// V2Ray specific TCP.
TCP = 2;

View File

@ -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},
}
}

View File

@ -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},
}
}

View File

@ -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()

View File

@ -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},
}
}

View File

@ -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,
},
})

View File

@ -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},
}
}

View File

@ -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()

View File

@ -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},
}
}

View File

@ -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},
}
}

View File

@ -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

View File

@ -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},
}
}

View File

@ -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()

View File

@ -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
}

View File

@ -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

View File

@ -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()
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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