Sfoglia il codice sorgente

remove IsTCP() and IsUDP()

Darien Raymond 9 anni fa
parent
commit
9ade07db03

+ 1 - 1
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())

+ 2 - 2
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())

+ 2 - 2
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 {

+ 1 - 1
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{

+ 4 - 4
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")
 	}
 }

+ 2 - 7
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:

+ 1 - 1
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,

+ 1 - 1
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 {

+ 1 - 1
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)