headers.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. )
  14. type RequestOption byte
  15. func (this RequestOption) IsChunkStream() bool {
  16. return (this & RequestOptionChunkStream) == RequestOptionChunkStream
  17. }
  18. type RequestHeader struct {
  19. Version byte
  20. User *User
  21. Command RequestCommand
  22. Option RequestOption
  23. Address v2net.Address
  24. Port v2net.Port
  25. }
  26. func (this *RequestHeader) Destination() v2net.Destination {
  27. if this.Command == RequestCommandUDP {
  28. return v2net.UDPDestination(this.Address, this.Port)
  29. }
  30. return v2net.TCPDestination(this.Address, this.Port)
  31. }
  32. type ResponseCommand interface{}
  33. type ResponseHeader struct {
  34. Command ResponseCommand
  35. }
  36. type CommandSwitchAccount struct {
  37. Host v2net.Address
  38. Port v2net.Port
  39. ID *uuid.UUID
  40. AlterIds uint16
  41. Level UserLevel
  42. ValidMin byte
  43. }