1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-26 20:15:26 -05:00

unify all address reading and writing

This commit is contained in:
Darien Raymond
2018-02-23 23:42:01 +01:00
parent a059ee2c00
commit af1abf687c
10 changed files with 333 additions and 267 deletions

View File

@@ -15,7 +15,6 @@ import (
"v2ray.com/core/common/buf"
"v2ray.com/core/common/crypto"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/serial"
"v2ray.com/core/proxy/vmess"
@@ -82,23 +81,8 @@ func (c *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
buffer.AppendBytes(security, byte(0), byte(header.Command))
if header.Command != protocol.RequestCommandMux {
common.Must(buffer.AppendSupplier(serial.WriteUint16(header.Port.Value())))
switch header.Address.Family() {
case net.AddressFamilyIPv4:
buffer.AppendBytes(byte(protocol.AddressTypeIPv4))
buffer.Append(header.Address.IP())
case net.AddressFamilyIPv6:
buffer.AppendBytes(byte(protocol.AddressTypeIPv6))
buffer.Append(header.Address.IP())
case net.AddressFamilyDomain:
domain := header.Address.Domain()
if protocol.IsDomainTooLong(domain) {
return newError("long domain not supported: ", domain)
}
nDomain := len(domain)
buffer.AppendBytes(byte(protocol.AddressTypeDomain), byte(nDomain))
common.Must(buffer.AppendSupplier(serial.WriteString(domain)))
if err := addrParser.WriteAddressPort(buffer, header.Address, header.Port); err != nil {
return newError("failed to writer address and port").Base(err)
}
}