network.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package constant
  2. import (
  3. "github.com/sagernet/sing/common"
  4. F "github.com/sagernet/sing/common/format"
  5. )
  6. type InterfaceType uint8
  7. const (
  8. InterfaceTypeWIFI InterfaceType = iota
  9. InterfaceTypeCellular
  10. InterfaceTypeEthernet
  11. InterfaceTypeOther
  12. )
  13. var (
  14. interfaceTypeToString = map[InterfaceType]string{
  15. InterfaceTypeWIFI: "wifi",
  16. InterfaceTypeCellular: "cellular",
  17. InterfaceTypeEthernet: "ethernet",
  18. InterfaceTypeOther: "other",
  19. }
  20. StringToInterfaceType = common.ReverseMap(interfaceTypeToString)
  21. )
  22. func (t InterfaceType) String() string {
  23. name, loaded := interfaceTypeToString[t]
  24. if !loaded {
  25. return F.ToString(int(t))
  26. }
  27. return name
  28. }
  29. type NetworkStrategy uint8
  30. const (
  31. NetworkStrategyDefault NetworkStrategy = iota
  32. NetworkStrategyFallback
  33. NetworkStrategyHybrid
  34. )
  35. var (
  36. networkStrategyToString = map[NetworkStrategy]string{
  37. NetworkStrategyDefault: "default",
  38. NetworkStrategyFallback: "fallback",
  39. NetworkStrategyHybrid: "hybrid",
  40. }
  41. StringToNetworkStrategy = common.ReverseMap(networkStrategyToString)
  42. )
  43. func (s NetworkStrategy) String() string {
  44. name, loaded := networkStrategyToString[s]
  45. if !loaded {
  46. return F.ToString(int(s))
  47. }
  48. return name
  49. }