github.com/EagleQL/Xray-core@v1.4.3/common/protocol/headers.go (about) 1 package protocol 2 3 import ( 4 "runtime" 5 6 "github.com/xtls/xray-core/common/bitmask" 7 "github.com/xtls/xray-core/common/net" 8 "github.com/xtls/xray-core/common/uuid" 9 ) 10 11 // RequestCommand is a custom command in a proxy request. 12 type RequestCommand byte 13 14 const ( 15 RequestCommandTCP = RequestCommand(0x01) 16 RequestCommandUDP = RequestCommand(0x02) 17 RequestCommandMux = RequestCommand(0x03) 18 ) 19 20 func (c RequestCommand) TransferType() TransferType { 21 switch c { 22 case RequestCommandTCP, RequestCommandMux: 23 return TransferTypeStream 24 case RequestCommandUDP: 25 return TransferTypePacket 26 default: 27 return TransferTypeStream 28 } 29 } 30 31 const ( 32 // RequestOptionChunkStream indicates request payload is chunked. Each chunk consists of length, authentication and payload. 33 RequestOptionChunkStream bitmask.Byte = 0x01 34 35 // RequestOptionConnectionReuse indicates client side expects to reuse the connection. 36 RequestOptionConnectionReuse bitmask.Byte = 0x02 37 38 RequestOptionChunkMasking bitmask.Byte = 0x04 39 40 RequestOptionGlobalPadding bitmask.Byte = 0x08 41 ) 42 43 type RequestHeader struct { 44 Version byte 45 Command RequestCommand 46 Option bitmask.Byte 47 Security SecurityType 48 Port net.Port 49 Address net.Address 50 User *MemoryUser 51 } 52 53 func (h *RequestHeader) Destination() net.Destination { 54 if h.Command == RequestCommandUDP { 55 return net.UDPDestination(h.Address, h.Port) 56 } 57 return net.TCPDestination(h.Address, h.Port) 58 } 59 60 const ( 61 ResponseOptionConnectionReuse bitmask.Byte = 0x01 62 ) 63 64 type ResponseCommand interface{} 65 66 type ResponseHeader struct { 67 Option bitmask.Byte 68 Command ResponseCommand 69 } 70 71 type CommandSwitchAccount struct { 72 Host net.Address 73 Port net.Port 74 ID uuid.UUID 75 Level uint32 76 AlterIds uint16 77 ValidMin byte 78 } 79 80 func (sc *SecurityConfig) GetSecurityType() SecurityType { 81 if sc == nil || sc.Type == SecurityType_AUTO { 82 if runtime.GOARCH == "amd64" || runtime.GOARCH == "s390x" || runtime.GOARCH == "arm64" { 83 return SecurityType_AES128_GCM 84 } 85 return SecurityType_CHACHA20_POLY1305 86 } 87 return sc.Type 88 } 89 90 func isDomainTooLong(domain string) bool { 91 return len(domain) > 256 92 }