headers.go 1.6 KB

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