1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-29 05:27:02 -05:00

remove IsTCP() and IsUDP()

This commit is contained in:
Darien Raymond 2016-09-19 16:39:11 +02:00
parent 5291624165
commit 9ade07db03
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
9 changed files with 15 additions and 20 deletions
app/router/rules
common/net
proxy
freedom
vmess/outbound
testing/assert
transport/internet

View File

@ -49,7 +49,7 @@ func (this *Router) ResolveIP(dest v2net.Destination) []v2net.Destination {
}
dests := make([]v2net.Destination, len(ips))
for idx, ip := range ips {
if dest.IsTCP() {
if dest.Network() == v2net.TCPNetwork {
dests[idx] = v2net.TCPDestination(v2net.IPAddress(ip), dest.Port())
} else {
dests[idx] = v2net.UDPDestination(v2net.IPAddress(ip), dest.Port())

View File

@ -78,7 +78,7 @@ func (dest *tcpDestination) Equals(another Destination) bool {
if dest == nil || another == nil {
return false
}
if !another.IsTCP() {
if another.Network() != TCPNetwork {
return false
}
return dest.Port() == another.Port() && dest.Address().Equals(another.Address())
@ -124,7 +124,7 @@ func (dest *udpDestination) Equals(another Destination) bool {
if dest == nil || another == nil {
return false
}
if !another.IsUDP() {
if another.Network() != UDPNetwork {
return false
}
return dest.Port() == another.Port() && dest.Address().Equals(another.Address())

View File

@ -58,7 +58,7 @@ func (this *FreedomConnection) ResolveIP(destination v2net.Destination) v2net.De
ip := ips[dice.Roll(len(ips))]
var newDest v2net.Destination
if destination.IsTCP() {
if destination.Network() == v2net.TCPNetwork {
newDest = v2net.TCPDestination(v2net.IPAddress(ip), destination.Port())
} else {
newDest = v2net.UDPDestination(v2net.IPAddress(ip), destination.Port())
@ -112,7 +112,7 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *
var reader io.Reader = conn
timeout := this.timeout
if destination.IsUDP() {
if destination.Network() == v2net.UDPNetwork {
timeout = 16
}
if timeout > 0 {

View File

@ -49,7 +49,7 @@ func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *al
log.Info("VMess|Outbound: Tunneling request to ", target, " via ", rec.Destination())
command := protocol.RequestCommandTCP
if target.IsUDP() {
if target.Network() == v2net.UDPNetwork {
command = protocol.RequestCommandUDP
}
request := &protocol.RequestHeader{

View File

@ -20,25 +20,25 @@ type DestinationSubject struct {
}
func (this *DestinationSubject) IsTCP() {
if !this.value.IsTCP() {
if this.value.Network() != v2net.TCPNetwork {
this.Fail("is", "a TCP destination")
}
}
func (this *DestinationSubject) IsNotTCP() {
if this.value.IsTCP() {
if this.value.Network() == v2net.TCPNetwork {
this.Fail("is not", "a TCP destination")
}
}
func (this *DestinationSubject) IsUDP() {
if !this.value.IsUDP() {
if this.value.Network() != v2net.UDPNetwork {
this.Fail("is", "a UDP destination")
}
}
func (this *DestinationSubject) IsNotUDP() {
if this.value.IsUDP() {
if this.value.Network() == v2net.UDPNetwork {
this.Fail("is not", "a UDP destination")
}
}

View File

@ -27,7 +27,7 @@ func Dial(src v2net.Address, dest v2net.Destination, settings *StreamSettings) (
var connection Connection
var err error
if dest.IsTCP() {
if dest.Network() == v2net.TCPNetwork {
switch {
case settings.IsCapableOf(StreamConnectionTypeTCP):
connection, err = TCPDialer(src, dest)
@ -36,12 +36,7 @@ func Dial(src v2net.Address, dest v2net.Destination, settings *StreamSettings) (
case settings.IsCapableOf(StreamConnectionTypeWebSocket):
connection, err = WSDialer(src, dest)
/*Warning: Hours wasted: the following item must be last one
internet.StreamConnectionType have a default value of 1,
so the following attempt will catch all.
*/
// This check has to be the last one.
case settings.IsCapableOf(StreamConnectionTypeRawTCP):
connection, err = RawTCPDialer(src, dest)
default:

View File

@ -25,7 +25,7 @@ func (this *DefaultSystemDialer) Dial(src v2net.Address, dest v2net.Destination)
}
if src != nil && src != v2net.AnyIP {
var addr net.Addr
if dest.IsTCP() {
if dest.Network() == v2net.TCPNetwork {
addr = &net.TCPAddr{
IP: src.IP(),
Port: 0,

View File

@ -19,7 +19,7 @@ func Dial(src v2net.Address, dest v2net.Destination) (internet.Connection, error
}
id := src.String() + "-" + dest.NetAddr()
var conn net.Conn
if dest.IsTCP() && effectiveConfig.ConnectionReuse {
if dest.Network() == v2net.TCPNetwork && effectiveConfig.ConnectionReuse {
conn = globalCache.Get(id)
}
if conn == nil {

View File

@ -23,7 +23,7 @@ func Dial(src v2net.Address, dest v2net.Destination) (internet.Connection, error
}
id := src.String() + "-" + dest.NetAddr()
var conn *wsconn
if dest.IsTCP() && effectiveConfig.ConnectionReuse {
if dest.Network() == v2net.TCPNetwork && effectiveConfig.ConnectionReuse {
connt := globalCache.Get(id)
if connt != nil {
conn = connt.(*wsconn)