constants.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. if n.MigrationLink != "" {
  41. return F.ToString(
  42. n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
  43. " and will be removed in sing-box ", n.ScheduledVersion, ", checkout documentation for migration: ", n.MigrationLink,
  44. )
  45. } else {
  46. return F.ToString(
  47. n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
  48. " and will be removed in sing-box ", n.ScheduledVersion, ".",
  49. )
  50. }
  51. }
  52. var OptionOutboundDNSRuleItem = Note{
  53. Name: "outbound-dns-rule-item",
  54. Description: "outbound DNS rule item",
  55. DeprecatedVersion: "1.12.0",
  56. ScheduledVersion: "1.14.0",
  57. EnvName: "OUTBOUND_DNS_RULE_ITEM",
  58. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-outbound-dns-rule-items-to-domain-resolver",
  59. }
  60. var OptionMissingDomainResolver = Note{
  61. Name: "missing-domain-resolver",
  62. Description: "missing `route.default_domain_resolver` or `domain_resolver` in dial fields",
  63. DeprecatedVersion: "1.12.0",
  64. ScheduledVersion: "1.14.0",
  65. EnvName: "MISSING_DOMAIN_RESOLVER",
  66. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-outbound-dns-rule-items-to-domain-resolver",
  67. }
  68. var OptionLegacyDomainStrategyOptions = Note{
  69. Name: "legacy-domain-strategy-options",
  70. Description: "legacy domain strategy options",
  71. DeprecatedVersion: "1.12.0",
  72. ScheduledVersion: "1.14.0",
  73. EnvName: "LEGACY_DOMAIN_STRATEGY_OPTIONS",
  74. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-domain-strategy-options",
  75. }
  76. var OptionInlineACME = Note{
  77. Name: "inline-acme-options",
  78. Description: "inline ACME options in TLS",
  79. DeprecatedVersion: "1.14.0",
  80. ScheduledVersion: "1.16.0",
  81. EnvName: "INLINE_ACME_OPTIONS",
  82. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-inline-acme-to-certificate-provider",
  83. }
  84. var OptionLegacyRuleSetDownloadDetour = Note{
  85. Name: "legacy-rule-set-download-detour",
  86. Description: "legacy `download_detour` remote rule-set option",
  87. DeprecatedVersion: "1.14.0",
  88. ScheduledVersion: "1.16.0",
  89. EnvName: "LEGACY_RULE_SET_DOWNLOAD_DETOUR",
  90. }
  91. var OptionLegacyTailscaleEndpointDialer = Note{
  92. Name: "legacy-tailscale-endpoint-dialer",
  93. Description: "legacy dialer options in Tailscale endpoint",
  94. DeprecatedVersion: "1.14.0",
  95. ScheduledVersion: "1.16.0",
  96. EnvName: "LEGACY_TAILSCALE_ENDPOINT_DIALER",
  97. }
  98. var OptionRuleSetIPCIDRAcceptEmpty = Note{
  99. Name: "dns-rule-rule-set-ip-cidr-accept-empty",
  100. Description: "Legacy `rule_set_ip_cidr_accept_empty` DNS rule item",
  101. DeprecatedVersion: "1.14.0",
  102. ScheduledVersion: "1.16.0",
  103. EnvName: "DNS_RULE_RULE_SET_IP_CIDR_ACCEPT_EMPTY",
  104. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-address-filter-fields-to-response-matching",
  105. }
  106. var OptionLegacyDNSAddressFilter = Note{
  107. Name: "legacy-dns-address-filter",
  108. Description: "Legacy Address Filter Fields in DNS rules",
  109. DeprecatedVersion: "1.14.0",
  110. ScheduledVersion: "1.16.0",
  111. EnvName: "LEGACY_DNS_ADDRESS_FILTER",
  112. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-address-filter-fields-to-response-matching",
  113. }
  114. var OptionLegacyDNSRuleStrategy = Note{
  115. Name: "legacy-dns-rule-strategy",
  116. Description: "Legacy `strategy` DNS rule action option",
  117. DeprecatedVersion: "1.14.0",
  118. ScheduledVersion: "1.16.0",
  119. EnvName: "LEGACY_DNS_RULE_STRATEGY",
  120. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-dns-rule-action-strategy-to-rule-items",
  121. }
  122. var OptionIndependentDNSCache = Note{
  123. Name: "independent-dns-cache",
  124. Description: "`independent_cache` DNS option",
  125. DeprecatedVersion: "1.14.0",
  126. ScheduledVersion: "1.16.0",
  127. EnvName: "INDEPENDENT_DNS_CACHE",
  128. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-independent-dns-cache",
  129. }
  130. var OptionStoreRDRC = Note{
  131. Name: "store-rdrc",
  132. Description: "`store_rdrc` cache file option",
  133. DeprecatedVersion: "1.14.0",
  134. ScheduledVersion: "1.16.0",
  135. EnvName: "STORE_RDRC",
  136. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-store-rdrc",
  137. }
  138. var OptionImplicitDefaultHTTPClient = Note{
  139. Name: "implicit-default-http-client",
  140. Description: "implicit default HTTP client using default outbound for remote rule-sets",
  141. DeprecatedVersion: "1.14.0",
  142. ScheduledVersion: "1.16.0",
  143. EnvName: "IMPLICIT_DEFAULT_HTTP_CLIENT",
  144. }
  145. var Options = []Note{
  146. OptionOutboundDNSRuleItem,
  147. OptionMissingDomainResolver,
  148. OptionLegacyDomainStrategyOptions,
  149. OptionInlineACME,
  150. OptionLegacyRuleSetDownloadDetour,
  151. OptionLegacyTailscaleEndpointDialer,
  152. OptionRuleSetIPCIDRAcceptEmpty,
  153. OptionLegacyDNSAddressFilter,
  154. OptionLegacyDNSRuleStrategy,
  155. OptionIndependentDNSCache,
  156. OptionStoreRDRC,
  157. OptionImplicitDefaultHTTPClient,
  158. }