headers.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package protocol
  2. import (
  3. v2net "v2ray.com/core/common/net"
  4. "v2ray.com/core/common/uuid"
  5. )
  6. type RequestCommand byte
  7. const (
  8. RequestCommandTCP = RequestCommand(0x01)
  9. RequestCommandUDP = RequestCommand(0x02)
  10. )
  11. type RequestOption byte
  12. const (
  13. RequestOptionChunkStream = RequestOption(0x01)
  14. RequestOptionConnectionReuse = RequestOption(0x02)
  15. )
  16. func (v RequestOption) Has(option RequestOption) bool {
  17. return (v & option) == option
  18. }
  19. func (v *RequestOption) Set(option RequestOption) {
  20. *v = (*v | option)
  21. }
  22. func (v *RequestOption) Clear(option RequestOption) {
  23. *v = (*v & (^option))
  24. }
  25. type Security byte
  26. func (v Security) Is(t SecurityType) bool {
  27. return v == Security(t)
  28. }
  29. type RequestHeader struct {
  30. Version byte
  31. User *User
  32. Command RequestCommand
  33. Option RequestOption
  34. Security Security
  35. Address v2net.Address
  36. Port v2net.Port
  37. }
  38. func (v *RequestHeader) Destination() v2net.Destination {
  39. if v.Command == RequestCommandUDP {
  40. return v2net.UDPDestination(v.Address, v.Port)
  41. }
  42. return v2net.TCPDestination(v.Address, v.Port)
  43. }
  44. type ResponseOption byte
  45. const (
  46. ResponseOptionConnectionReuse = ResponseOption(1)
  47. )
  48. func (v *ResponseOption) Set(option ResponseOption) {
  49. *v = (*v | option)
  50. }
  51. func (v ResponseOption) Has(option ResponseOption) bool {
  52. return (v | option) == option
  53. }
  54. func (v *ResponseOption) Clear(option ResponseOption) {
  55. *v = (*v & (^option))
  56. }
  57. type ResponseCommand interface{}
  58. type ResponseHeader struct {
  59. Option ResponseOption
  60. Command ResponseCommand
  61. }
  62. type CommandSwitchAccount struct {
  63. Host v2net.Address
  64. Port v2net.Port
  65. ID *uuid.UUID
  66. AlterIds uint16
  67. Level uint32
  68. ValidMin byte
  69. }