headers.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package protocol
  2. import (
  3. v2net "github.com/v2ray/v2ray-core/common/net"
  4. "github.com/v2ray/v2ray-core/common/serial"
  5. "github.com/v2ray/v2ray-core/common/uuid"
  6. )
  7. type RequestCommand byte
  8. const (
  9. RequestCommandTCP = RequestCommand(0x01)
  10. RequestCommandUDP = RequestCommand(0x02)
  11. )
  12. const (
  13. RequestOptionChunkStream = RequestOption(0x01)
  14. )
  15. type RequestOption byte
  16. func (this RequestOption) IsChunkStream() bool {
  17. return (this & RequestOptionChunkStream) == RequestOptionChunkStream
  18. }
  19. type RequestHeader struct {
  20. Version byte
  21. User *User
  22. Command RequestCommand
  23. Option RequestOption
  24. Address v2net.Address
  25. Port v2net.Port
  26. }
  27. func (this *RequestHeader) Destination() v2net.Destination {
  28. if this.Command == RequestCommandUDP {
  29. return v2net.UDPDestination(this.Address, this.Port)
  30. }
  31. return v2net.TCPDestination(this.Address, this.Port)
  32. }
  33. type ResponseCommand interface{}
  34. type ResponseHeader struct {
  35. Command ResponseCommand
  36. }
  37. type CommandSwitchAccount struct {
  38. Host v2net.Address
  39. Port v2net.Port
  40. ID *uuid.UUID
  41. AlterIds serial.Uint16Literal
  42. Level UserLevel
  43. ValidMin byte
  44. }