diff --git a/app/router/rules/router.go b/app/router/rules/router.go index 6063eb78e..92833aeb9 100644 --- a/app/router/rules/router.go +++ b/app/router/rules/router.go @@ -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()) diff --git a/common/net/destination.go b/common/net/destination.go index 57510e5d9..687c456e4 100644 --- a/common/net/destination.go +++ b/common/net/destination.go @@ -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()) diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 67ac35b56..3b58a564f 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -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 { diff --git a/proxy/vmess/outbound/outbound.go b/proxy/vmess/outbound/outbound.go index 9b36feba9..e2266728f 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/proxy/vmess/outbound/outbound.go @@ -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{ diff --git a/testing/assert/destination.go b/testing/assert/destination.go index 38cee62cb..4350fdf50 100644 --- a/testing/assert/destination.go +++ b/testing/assert/destination.go @@ -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") } } diff --git a/transport/internet/dialer.go b/transport/internet/dialer.go index a527327f9..c43361512 100644 --- a/transport/internet/dialer.go +++ b/transport/internet/dialer.go @@ -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: diff --git a/transport/internet/system_dialer.go b/transport/internet/system_dialer.go index e6f39d877..bff78b0f4 100644 --- a/transport/internet/system_dialer.go +++ b/transport/internet/system_dialer.go @@ -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, diff --git a/transport/internet/tcp/dialer.go b/transport/internet/tcp/dialer.go index 8ca1bf52f..76cd1d655 100644 --- a/transport/internet/tcp/dialer.go +++ b/transport/internet/tcp/dialer.go @@ -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 { diff --git a/transport/internet/ws/dialer.go b/transport/internet/ws/dialer.go index 4b5e250d8..8a26ce010 100644 --- a/transport/internet/ws/dialer.go +++ b/transport/internet/ws/dialer.go @@ -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)