constants.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 OptionLegacyDNSTransport = Note{
  53. Name: "legacy-dns-transport",
  54. Description: "legacy DNS servers",
  55. DeprecatedVersion: "1.12.0",
  56. ScheduledVersion: "1.14.0",
  57. EnvName: "LEGACY_DNS_SERVERS",
  58. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-to-new-dns-server-formats",
  59. }
  60. var OptionLegacyDNSFakeIPOptions = Note{
  61. Name: "legacy-dns-fakeip-options",
  62. Description: "legacy DNS fakeip options",
  63. DeprecatedVersion: "1.12.0",
  64. ScheduledVersion: "1.14.0",
  65. EnvName: "LEGACY_DNS_FAKEIP_OPTIONS",
  66. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-to-new-dns-server-formats",
  67. }
  68. var OptionOutboundDNSRuleItem = Note{
  69. Name: "outbound-dns-rule-item",
  70. Description: "outbound DNS rule item",
  71. DeprecatedVersion: "1.12.0",
  72. ScheduledVersion: "1.14.0",
  73. EnvName: "OUTBOUND_DNS_RULE_ITEM",
  74. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-outbound-dns-rule-items-to-domain-resolver",
  75. }
  76. var OptionMissingDomainResolver = Note{
  77. Name: "missing-domain-resolver",
  78. Description: "missing `route.default_domain_resolver` or `domain_resolver` in dial fields",
  79. DeprecatedVersion: "1.12.0",
  80. ScheduledVersion: "1.14.0",
  81. EnvName: "MISSING_DOMAIN_RESOLVER",
  82. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-outbound-dns-rule-items-to-domain-resolver",
  83. }
  84. var OptionLegacyDomainStrategyOptions = Note{
  85. Name: "legacy-domain-strategy-options",
  86. Description: "legacy domain strategy options",
  87. DeprecatedVersion: "1.12.0",
  88. ScheduledVersion: "1.14.0",
  89. EnvName: "LEGACY_DOMAIN_STRATEGY_OPTIONS",
  90. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-domain-strategy-options",
  91. }
  92. var Options = []Note{
  93. OptionLegacyDNSTransport,
  94. OptionLegacyDNSFakeIPOptions,
  95. OptionOutboundDNSRuleItem,
  96. OptionMissingDomainResolver,
  97. OptionLegacyDomainStrategyOptions,
  98. }