mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
remove duplicated address type def
This commit is contained in:
parent
f1a15e92f5
commit
24089bfad0
@ -4,6 +4,7 @@ import (
|
||||
"v2ray.com/core/common/bitmask"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
)
|
||||
|
||||
@ -27,14 +28,6 @@ const (
|
||||
TargetNetworkUDP TargetNetwork = 0x02
|
||||
)
|
||||
|
||||
type AddressType byte
|
||||
|
||||
const (
|
||||
AddressTypeIPv4 AddressType = 0x01
|
||||
AddressTypeDomain AddressType = 0x02
|
||||
AddressTypeIPv6 AddressType = 0x03
|
||||
)
|
||||
|
||||
/*
|
||||
Frame format
|
||||
2 bytes - length
|
||||
@ -79,16 +72,16 @@ func (f FrameMetadata) AsSupplier() buf.Supplier {
|
||||
addr := f.Target.Address
|
||||
switch addr.Family() {
|
||||
case net.AddressFamilyIPv4:
|
||||
b = append(b, byte(AddressTypeIPv4))
|
||||
b = append(b, byte(protocol.AddressTypeIPv4))
|
||||
b = append(b, addr.IP()...)
|
||||
length += 5
|
||||
case net.AddressFamilyIPv6:
|
||||
b = append(b, byte(AddressTypeIPv6))
|
||||
b = append(b, byte(protocol.AddressTypeIPv6))
|
||||
b = append(b, addr.IP()...)
|
||||
length += 17
|
||||
case net.AddressFamilyDomain:
|
||||
nDomain := len(addr.Domain())
|
||||
b = append(b, byte(AddressTypeDomain), byte(nDomain))
|
||||
b = append(b, byte(protocol.AddressTypeDomain), byte(nDomain))
|
||||
b = append(b, addr.Domain()...)
|
||||
length += nDomain + 2
|
||||
}
|
||||
@ -115,18 +108,18 @@ func ReadFrameFrom(b []byte) (*FrameMetadata, error) {
|
||||
if f.SessionStatus == SessionStatusNew {
|
||||
network := TargetNetwork(b[0])
|
||||
port := net.PortFromBytes(b[1:3])
|
||||
addrType := AddressType(b[3])
|
||||
addrType := protocol.AddressType(b[3])
|
||||
b = b[4:]
|
||||
|
||||
var addr net.Address
|
||||
switch addrType {
|
||||
case AddressTypeIPv4:
|
||||
case protocol.AddressTypeIPv4:
|
||||
addr = net.IPAddress(b[0:4])
|
||||
b = b[4:]
|
||||
case AddressTypeIPv6:
|
||||
case protocol.AddressTypeIPv6:
|
||||
addr = net.IPAddress(b[0:16])
|
||||
b = b[16:]
|
||||
case AddressTypeDomain:
|
||||
case protocol.AddressTypeDomain:
|
||||
nDomain := int(b[0])
|
||||
addr = net.DomainAddress(string(b[1 : 1+nDomain]))
|
||||
b = b[nDomain+1:]
|
||||
|
@ -6,3 +6,11 @@ const (
|
||||
TransferTypeStream TransferType = 0
|
||||
TransferTypePacket TransferType = 1
|
||||
)
|
||||
|
||||
type AddressType byte
|
||||
|
||||
const (
|
||||
AddressTypeIPv4 AddressType = 1
|
||||
AddressTypeDomain AddressType = 2
|
||||
AddressTypeIPv6 AddressType = 3
|
||||
)
|
||||
|
@ -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()...)
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,4 @@ package encoding
|
||||
|
||||
const (
|
||||
Version = byte(1)
|
||||
|
||||
AddrTypeIPv4 = byte(0x01)
|
||||
AddrTypeIPv6 = byte(0x03)
|
||||
AddrTypeDomain = byte(0x02)
|
||||
)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user