|
|
@ -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 {
|
|
|
|