constants.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package deprecated
  2. import (
  3. "github.com/sagernet/sing-box/common/badversion"
  4. C "github.com/sagernet/sing-box/constant"
  5. F "github.com/sagernet/sing/common/format"
  6. "golang.org/x/mod/semver"
  7. )
  8. type Note struct {
  9. Name string
  10. Description string
  11. DeprecatedVersion string
  12. ScheduledVersion string
  13. EnvName string
  14. MigrationLink string
  15. }
  16. func (n Note) Impending() bool {
  17. if n.ScheduledVersion == "" {
  18. return false
  19. }
  20. if !semver.IsValid("v" + C.Version) {
  21. return false
  22. }
  23. versionCurrent := badversion.Parse(C.Version)
  24. versionMinor := badversion.Parse(n.ScheduledVersion).Minor - versionCurrent.Minor
  25. if versionCurrent.PreReleaseIdentifier == "" && versionMinor < 0 {
  26. panic("invalid deprecated note: " + n.Name)
  27. }
  28. return versionMinor <= 1
  29. }
  30. func (n Note) Message() string {
  31. return F.ToString(
  32. n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
  33. " and will be removed in sing-box ", n.ScheduledVersion, ", please checkout documentation for migration.",
  34. )
  35. }
  36. func (n Note) MessageWithLink() string {
  37. return F.ToString(
  38. n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
  39. " and will be removed in sing-box ", n.ScheduledVersion, ", checkout documentation for migration: ", n.MigrationLink,
  40. )
  41. }
  42. var OptionBadMatchSource = Note{
  43. Name: "bad-match-source",
  44. Description: "legacy match source rule item",
  45. DeprecatedVersion: "1.10.0",
  46. ScheduledVersion: "1.11.0",
  47. EnvName: "BAD_MATCH_SOURCE",
  48. MigrationLink: "https://sing-box.sagernet.org/deprecated/#match-source-rule-items-are-renamed",
  49. }
  50. var OptionGEOIP = Note{
  51. Name: "geoip",
  52. Description: "geoip database",
  53. DeprecatedVersion: "1.8.0",
  54. ScheduledVersion: "1.12.0",
  55. EnvName: "GEOIP",
  56. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-geoip-to-rule-sets",
  57. }
  58. var OptionGEOSITE = Note{
  59. Name: "geosite",
  60. Description: "geosite database",
  61. DeprecatedVersion: "1.8.0",
  62. ScheduledVersion: "1.12.0",
  63. EnvName: "GEOSITE",
  64. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-geosite-to-rule-sets",
  65. }
  66. var OptionTUNAddressX = Note{
  67. Name: "tun-address-x",
  68. Description: "legacy tun address fields",
  69. DeprecatedVersion: "1.10.0",
  70. ScheduledVersion: "1.12.0",
  71. EnvName: "TUN_ADDRESS_X",
  72. MigrationLink: "https://sing-box.sagernet.org/migration/#tun-address-fields-are-merged",
  73. }
  74. var OptionSpecialOutbounds = Note{
  75. Name: "special-outbounds",
  76. Description: "legacy special outbounds",
  77. DeprecatedVersion: "1.11.0",
  78. ScheduledVersion: "1.13.0",
  79. EnvName: "SPECIAL_OUTBOUNDS",
  80. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-special-outbounds-to-rule-actions",
  81. }
  82. var OptionInboundOptions = Note{
  83. Name: "inbound-options",
  84. Description: "legacy inbound fields",
  85. DeprecatedVersion: "1.11.0",
  86. ScheduledVersion: "1.13.0",
  87. EnvName: "INBOUND_OPTIONS",
  88. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-special-outbounds-to-rule-actions",
  89. }
  90. var OptionDestinationOverrideFields = Note{
  91. Name: "destination-override-fields",
  92. Description: "destination override fields in direct outbound",
  93. DeprecatedVersion: "1.11.0",
  94. ScheduledVersion: "1.13.0",
  95. EnvName: "DESTINATION_OVERRIDE_FIELDS",
  96. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-destination-override-fields-to-route-options",
  97. }
  98. var OptionWireGuardOutbound = Note{
  99. Name: "wireguard-outbound",
  100. Description: "legacy wireguard outbound",
  101. DeprecatedVersion: "1.11.0",
  102. ScheduledVersion: "1.13.0",
  103. EnvName: "WIREGUARD_OUTBOUND",
  104. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-wireguard-outbound-to-endpoint",
  105. }
  106. var Options = []Note{
  107. OptionBadMatchSource,
  108. OptionGEOIP,
  109. OptionGEOSITE,
  110. OptionTUNAddressX,
  111. OptionSpecialOutbounds,
  112. OptionInboundOptions,
  113. OptionDestinationOverrideFields,
  114. OptionWireGuardOutbound,
  115. }