1
0

vless_route.go 729 B

12345678910111213141516171819202122232425262728293031323334
  1. package sub
  2. import (
  3. "strconv"
  4. "strings"
  5. "github.com/google/uuid"
  6. )
  7. // xray reads the route from UUID bytes 6-7 (net.PortFromBytes) and masks them to
  8. // zero before auth, so baking a 0-65535 value into the 3rd group routes without
  9. // breaking the user match. Empty/invalid/non-UUID input is returned unchanged.
  10. func applyVlessRoute(id, route string) string {
  11. route = strings.TrimSpace(route)
  12. if route == "" {
  13. return id
  14. }
  15. n, err := strconv.Atoi(route)
  16. if err != nil || n < 0 || n > 65535 {
  17. return id
  18. }
  19. u, err := uuid.Parse(id)
  20. if err != nil {
  21. return id
  22. }
  23. u[6] = byte(n >> 8)
  24. u[7] = byte(n)
  25. return u.String()
  26. }
  27. func hostVlessRoute(ep map[string]any) string {
  28. v, _ := ep["vlessRoute"].(string)
  29. return v
  30. }