1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-05-07 21:19:07 -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

@@ -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:]