Remove token field in VMess UDP

pull/40/head
V2Ray 9 years ago
parent 76563cb7c7
commit 6f433f5206

@ -16,7 +16,6 @@ import (
type VMessUDP struct { type VMessUDP struct {
user user.ID user user.ID
version byte version byte
token uint16
address v2net.Address address v2net.Address
data []byte data []byte
} }
@ -51,26 +50,25 @@ func ReadVMessUDP(buffer []byte, userset user.UserSet) (*VMessUDP, error) {
vmess := &VMessUDP{ vmess := &VMessUDP{
user: *userId, user: *userId,
version: buffer[0], 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]) port := binary.BigEndian.Uint16(buffer[2:4])
addrType := buffer[6] addrType := buffer[4]
var address v2net.Address var address v2net.Address
switch addrType { switch addrType {
case addrTypeIPv4: case addrTypeIPv4:
address = v2net.IPAddress(buffer[7:11], port) address = v2net.IPAddress(buffer[5:9], port)
buffer = buffer[11:] buffer = buffer[9:]
case addrTypeIPv6: case addrTypeIPv6:
address = v2net.IPAddress(buffer[7:23], port) address = v2net.IPAddress(buffer[5:21], port)
buffer = buffer[23:] buffer = buffer[21:]
case addrTypeDomain: case addrTypeDomain:
domainLength := buffer[7] domainLength := buffer[5]
domain := string(buffer[8 : 8+domainLength]) domain := string(buffer[6 : 6+domainLength])
address = v2net.DomainAddress(domain, port) address = v2net.DomainAddress(domain, port)
buffer = buffer[8+domainLength:] buffer = buffer[6+domainLength:]
default: default:
log.Warning("Unexpected address type %d", addrType) log.Warning("Unexpected address type %d", addrType)
return nil, errors.NewCorruptedPacketError() return nil, errors.NewCorruptedPacketError()
@ -99,7 +97,6 @@ func (vmess *VMessUDP) ToBytes(idHash user.CounterHash, randomRangeInt64 user.Ra
fnvHashBegin := 20 fnvHashBegin := 20
buffer = append(buffer, vmess.version) buffer = append(buffer, vmess.version)
buffer = append(buffer, byte(vmess.token>>8), byte(vmess.token))
buffer = append(buffer, byte(0x00)) buffer = append(buffer, byte(0x00))
buffer = append(buffer, vmess.address.PortBytes()...) buffer = append(buffer, vmess.address.PortBytes()...)
switch { switch {

@ -21,7 +21,6 @@ func TestVMessUDPReadWrite(t *testing.T) {
message := &VMessUDP{ message := &VMessUDP{
user: userId, user: userId,
version: byte(0x01), version: byte(0x01),
token: 1234,
address: v2net.DomainAddress("v2ray.com", 8372), address: v2net.DomainAddress("v2ray.com", 8372),
data: []byte("An UDP message."), data: []byte("An UDP message."),
} }
@ -37,7 +36,6 @@ func TestVMessUDPReadWrite(t *testing.T) {
assert.String(messageRestored.user.String).Equals(message.user.String) assert.String(messageRestored.user.String).Equals(message.user.String)
assert.Byte(messageRestored.version).Equals(message.version) assert.Byte(messageRestored.version).Equals(message.version)
assert.Uint16(messageRestored.token).Equals(message.token)
assert.String(messageRestored.address.String()).Equals(message.address.String()) assert.String(messageRestored.address.String()).Equals(message.address.String())
assert.Bytes(messageRestored.data).Equals(message.data) assert.Bytes(messageRestored.data).Equals(message.data)
} }

@ -49,7 +49,6 @@ UDP 数据包为对称设计,即请求和响应的格式一样
* 16 字节:基于时间的 hash(用户 [ID](https://github.com/V2Ray/v2ray-core/blob/master/spec/id.md)),见下文 * 16 字节:基于时间的 hash(用户 [ID](https://github.com/V2Ray/v2ray-core/blob/master/spec/id.md)),见下文
* 4 字节:余下所有内容的 FNV1a hash * 4 字节:余下所有内容的 FNV1a hash
* 1 字节:版本号,目前为 0x1 * 1 字节:版本号,目前为 0x1
* 2 字节Token用于区分数据包
* 1 字节:保留,暂为 0x00 * 1 字节:保留,暂为 0x00
* 2 字节:目标端口 * 2 字节:目标端口
* 1 字节:目标类型 * 1 字节:目标类型

Loading…
Cancel
Save