1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 14:26:11 -04: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

View File

@ -49,7 +49,7 @@ func (this *Router) ResolveIP(dest v2net.Destination) []v2net.Destination {
} }
dests := make([]v2net.Destination, len(ips)) dests := make([]v2net.Destination, len(ips))
for idx, ip := range ips { for idx, ip := range ips {
if dest.IsTCP() { if dest.Network() == v2net.TCPNetwork {
dests[idx] = v2net.TCPDestination(v2net.IPAddress(ip), dest.Port()) dests[idx] = v2net.TCPDestination(v2net.IPAddress(ip), dest.Port())
} else { } else {
dests[idx] = v2net.UDPDestination(v2net.IPAddress(ip), dest.Port()) 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 { if dest == nil || another == nil {
return false return false
} }
if !another.IsTCP() { if another.Network() != TCPNetwork {
return false return false
} }
return dest.Port() == another.Port() && dest.Address().Equals(another.Address()) 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 { if dest == nil || another == nil {
return false return false
} }
if !another.IsUDP() { if another.Network() != UDPNetwork {
return false return false
} }
return dest.Port() == another.Port() && dest.Address().Equals(another.Address()) 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))] ip := ips[dice.Roll(len(ips))]
var newDest v2net.Destination var newDest v2net.Destination
if destination.IsTCP() { if destination.Network() == v2net.TCPNetwork {
newDest = v2net.TCPDestination(v2net.IPAddress(ip), destination.Port()) newDest = v2net.TCPDestination(v2net.IPAddress(ip), destination.Port())
} else { } else {
newDest = v2net.UDPDestination(v2net.IPAddress(ip), destination.Port()) 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 var reader io.Reader = conn
timeout := this.timeout timeout := this.timeout
if destination.IsUDP() { if destination.Network() == v2net.UDPNetwork {
timeout = 16 timeout = 16
} }
if timeout > 0 { 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()) log.Info("VMess|Outbound: Tunneling request to ", target, " via ", rec.Destination())
command := protocol.RequestCommandTCP command := protocol.RequestCommandTCP
if target.IsUDP() { if target.Network() == v2net.UDPNetwork {
command = protocol.RequestCommandUDP command = protocol.RequestCommandUDP
} }
request := &protocol.RequestHeader{ request := &protocol.RequestHeader{

View File

@ -20,25 +20,25 @@ type DestinationSubject struct {
} }
func (this *DestinationSubject) IsTCP() { func (this *DestinationSubject) IsTCP() {
if !this.value.IsTCP() { if this.value.Network() != v2net.TCPNetwork {
this.Fail("is", "a TCP destination") this.Fail("is", "a TCP destination")
} }
} }
func (this *DestinationSubject) IsNotTCP() { func (this *DestinationSubject) IsNotTCP() {
if this.value.IsTCP() { if this.value.Network() == v2net.TCPNetwork {
this.Fail("is not", "a TCP destination") this.Fail("is not", "a TCP destination")
} }
} }
func (this *DestinationSubject) IsUDP() { func (this *DestinationSubject) IsUDP() {
if !this.value.IsUDP() { if this.value.Network() != v2net.UDPNetwork {
this.Fail("is", "a UDP destination") this.Fail("is", "a UDP destination")
} }
} }
func (this *DestinationSubject) IsNotUDP() { func (this *DestinationSubject) IsNotUDP() {
if this.value.IsUDP() { if this.value.Network() == v2net.UDPNetwork {
this.Fail("is not", "a UDP destination") 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 connection Connection
var err error var err error
if dest.IsTCP() { if dest.Network() == v2net.TCPNetwork {
switch { switch {
case settings.IsCapableOf(StreamConnectionTypeTCP): case settings.IsCapableOf(StreamConnectionTypeTCP):
connection, err = TCPDialer(src, dest) connection, err = TCPDialer(src, dest)
@ -36,12 +36,7 @@ func Dial(src v2net.Address, dest v2net.Destination, settings *StreamSettings) (
case settings.IsCapableOf(StreamConnectionTypeWebSocket): case settings.IsCapableOf(StreamConnectionTypeWebSocket):
connection, err = WSDialer(src, dest) connection, err = WSDialer(src, dest)
/*Warning: Hours wasted: the following item must be last one // This check has to be the last one.
internet.StreamConnectionType have a default value of 1,
so the following attempt will catch all.
*/
case settings.IsCapableOf(StreamConnectionTypeRawTCP): case settings.IsCapableOf(StreamConnectionTypeRawTCP):
connection, err = RawTCPDialer(src, dest) connection, err = RawTCPDialer(src, dest)
default: default:

View File

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

View File

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