diff --git a/proxy/vmess/protocol/udp.go b/proxy/vmess/protocol/udp.go index b05689de..00d4669e 100644 --- a/proxy/vmess/protocol/udp.go +++ b/proxy/vmess/protocol/udp.go @@ -16,7 +16,6 @@ import ( type VMessUDP struct { user user.ID version byte - token uint16 address v2net.Address data []byte } @@ -51,26 +50,25 @@ func ReadVMessUDP(buffer []byte, userset user.UserSet) (*VMessUDP, error) { vmess := &VMessUDP{ user: *userId, version: buffer[0], - token: binary.BigEndian.Uint16(buffer[1:3]), } - // buffer[3] is reserved + // buffer[1] is reserved - port := binary.BigEndian.Uint16(buffer[4:6]) - addrType := buffer[6] + port := binary.BigEndian.Uint16(buffer[2:4]) + addrType := buffer[4] var address v2net.Address switch addrType { case addrTypeIPv4: - address = v2net.IPAddress(buffer[7:11], port) - buffer = buffer[11:] + address = v2net.IPAddress(buffer[5:9], port) + buffer = buffer[9:] case addrTypeIPv6: - address = v2net.IPAddress(buffer[7:23], port) - buffer = buffer[23:] + address = v2net.IPAddress(buffer[5:21], port) + buffer = buffer[21:] case addrTypeDomain: - domainLength := buffer[7] - domain := string(buffer[8 : 8+domainLength]) + domainLength := buffer[5] + domain := string(buffer[6 : 6+domainLength]) address = v2net.DomainAddress(domain, port) - buffer = buffer[8+domainLength:] + buffer = buffer[6+domainLength:] default: log.Warning("Unexpected address type %d", addrType) return nil, errors.NewCorruptedPacketError() @@ -99,7 +97,6 @@ func (vmess *VMessUDP) ToBytes(idHash user.CounterHash, randomRangeInt64 user.Ra fnvHashBegin := 20 buffer = append(buffer, vmess.version) - buffer = append(buffer, byte(vmess.token>>8), byte(vmess.token)) buffer = append(buffer, byte(0x00)) buffer = append(buffer, vmess.address.PortBytes()...) switch { diff --git a/proxy/vmess/protocol/udp_test.go b/proxy/vmess/protocol/udp_test.go index 9244f6bb..6cb9cec6 100644 --- a/proxy/vmess/protocol/udp_test.go +++ b/proxy/vmess/protocol/udp_test.go @@ -21,7 +21,6 @@ func TestVMessUDPReadWrite(t *testing.T) { message := &VMessUDP{ user: userId, version: byte(0x01), - token: 1234, address: v2net.DomainAddress("v2ray.com", 8372), data: []byte("An UDP message."), } @@ -37,7 +36,6 @@ func TestVMessUDPReadWrite(t *testing.T) { assert.String(messageRestored.user.String).Equals(message.user.String) assert.Byte(messageRestored.version).Equals(message.version) - assert.Uint16(messageRestored.token).Equals(message.token) assert.String(messageRestored.address.String()).Equals(message.address.String()) assert.Bytes(messageRestored.data).Equals(message.data) } diff --git a/spec/vmess.md b/spec/vmess.md index e5055632..2b9beada 100644 --- a/spec/vmess.md +++ b/spec/vmess.md @@ -49,7 +49,6 @@ UDP 数据包为对称设计,即请求和响应的格式一样 * 16 字节:基于时间的 hash(用户 [ID](https://github.com/V2Ray/v2ray-core/blob/master/spec/id.md)),见下文 * 4 字节:余下所有内容的 FNV1a hash * 1 字节:版本号,目前为 0x1 -* 2 字节:Token,用于区分数据包 * 1 字节:保留,暂为 0x00 * 2 字节:目标端口 * 1 字节:目标类型