mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-13 22:45:13 +00:00
remove rawtcp
This commit is contained in:
21 files changed
+41
-124
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user