Darien Raymond 7 rokov pred
rodič
commit
07e2592117

+ 2 - 3
common/protocol/address.go

@@ -3,11 +3,10 @@ package protocol
 import (
 	"io"
 
-	"v2ray.com/core/common/task"
-
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/net"
+	"v2ray.com/core/common/task"
 )
 
 type AddressOption func(*AddressParser)
@@ -110,7 +109,7 @@ func (p *AddressParser) readAddress(b *buf.Buffer, reader io.Reader) (net.Addres
 		domain := string(b.BytesFrom(-domainLength))
 		if maybeIPPrefix(domain[0]) {
 			addr := net.ParseAddress(domain)
-			if addr.Family().IsIPv4() || addrFamily.IsIPv6() {
+			if addr.Family().IsIPv4() || addr.Family().IsIPv6() {
 				return addr, nil
 			}
 		}

+ 7 - 1
common/protocol/address_test.go

@@ -69,6 +69,12 @@ func TestAddressReading(t *testing.T) {
 			Input:   []byte{3, 7, 10, 46, 56, 46, 56, 46, 56, 0, 80},
 			Error:   true,
 		},
+		{
+			Options: []AddressOption{AddressFamilyByte(0x03, net.AddressFamilyDomain)},
+			Input:   append(append([]byte{3, 24}, []byte("2a00:1450:4007:816::200e")...), 0, 80),
+			Address: net.ParseAddress("2a00:1450:4007:816::200e"),
+			Port:    net.Port(80),
+		},
 	}
 
 	for _, tc := range data {
@@ -79,9 +85,9 @@ func TestAddressReading(t *testing.T) {
 		if tc.Error {
 			assert(err, IsNotNil)
 		} else {
+			assert(err, IsNil)
 			assert(addr, Equals, tc.Address)
 			assert(port, Equals, tc.Port)
-			assert(err, IsNil)
 		}
 	}
 }