constants.go 4.1 KB

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