1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-05-27 14:29:08 -04:00

remove duplicated address type def

This commit is contained in:
Darien Raymond
2017-10-21 21:59:46 +02:00
parent f1a15e92f5
commit 24089bfad0
5 changed files with 23 additions and 26 deletions

View File

@@ -89,13 +89,13 @@ func (c *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
switch header.Address.Family() {
case net.AddressFamilyIPv4:
buffer = append(buffer, AddrTypeIPv4)
buffer = append(buffer, byte(protocol.AddressTypeIPv4))
buffer = append(buffer, header.Address.IP()...)
case net.AddressFamilyIPv6:
buffer = append(buffer, AddrTypeIPv6)
buffer = append(buffer, byte(protocol.AddressTypeIPv6))
buffer = append(buffer, header.Address.IP()...)
case net.AddressFamilyDomain:
buffer = append(buffer, AddrTypeDomain, byte(len(header.Address.Domain())))
buffer = append(buffer, byte(protocol.AddressTypeDomain), byte(len(header.Address.Domain())))
buffer = append(buffer, header.Address.Domain()...)
}
}

View File

@@ -2,8 +2,4 @@ package encoding
const (
Version = byte(1)
AddrTypeIPv4 = byte(0x01)
AddrTypeIPv6 = byte(0x03)
AddrTypeDomain = byte(0x02)
)

View File

@@ -175,22 +175,22 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
if request.Command != protocol.RequestCommandMux {
request.Port = net.PortFromBytes(buffer[38:40])
switch buffer[40] {
case AddrTypeIPv4:
switch protocol.AddressType(buffer[40]) {
case protocol.AddressTypeIPv4:
_, err = io.ReadFull(decryptor, buffer[41:45]) // 4 bytes
bufferLen += 4
if err != nil {
return nil, newError("failed to read IPv4 address").Base(err)
}
request.Address = net.IPAddress(buffer[41:45])
case AddrTypeIPv6:
case protocol.AddressTypeIPv6:
_, err = io.ReadFull(decryptor, buffer[41:57]) // 16 bytes
bufferLen += 16
if err != nil {
return nil, newError("failed to read IPv6 address").Base(err)
}
request.Address = net.IPAddress(buffer[41:57])
case AddrTypeDomain:
case protocol.AddressTypeDomain:
_, err = io.ReadFull(decryptor, buffer[41:42])
if err != nil {
return nil, newError("failed to read domain address").Base(err)