constants.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. if n.MigrationLink != "" {
  32. return F.ToString(
  33. n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
  34. " and will be removed in sing-box ", n.ScheduledVersion, ", please checkout documentation for migration.",
  35. )
  36. } else {
  37. return F.ToString(
  38. n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
  39. " and will be removed in sing-box ", n.ScheduledVersion, ".",
  40. )
  41. }
  42. }
  43. func (n Note) MessageWithLink() string {
  44. if n.MigrationLink != "" {
  45. return F.ToString(
  46. n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
  47. " and will be removed in sing-box ", n.ScheduledVersion, ", checkout documentation for migration: ", n.MigrationLink,
  48. )
  49. } else {
  50. return F.ToString(
  51. n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
  52. " and will be removed in sing-box ", n.ScheduledVersion, ".",
  53. )
  54. }
  55. }
  56. var OptionBadMatchSource = Note{
  57. Name: "bad-match-source",
  58. Description: "legacy match source rule item",
  59. DeprecatedVersion: "1.10.0",
  60. ScheduledVersion: "1.11.0",
  61. EnvName: "BAD_MATCH_SOURCE",
  62. MigrationLink: "https://sing-box.sagernet.org/deprecated/#match-source-rule-items-are-renamed",
  63. }
  64. var OptionGEOIP = Note{
  65. Name: "geoip",
  66. Description: "geoip database",
  67. DeprecatedVersion: "1.8.0",
  68. ScheduledVersion: "1.12.0",
  69. EnvName: "GEOIP",
  70. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-geoip-to-rule-sets",
  71. }
  72. var OptionGEOSITE = Note{
  73. Name: "geosite",
  74. Description: "geosite database",
  75. DeprecatedVersion: "1.8.0",
  76. ScheduledVersion: "1.12.0",
  77. EnvName: "GEOSITE",
  78. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-geosite-to-rule-sets",
  79. }
  80. var OptionTUNAddressX = Note{
  81. Name: "tun-address-x",
  82. Description: "legacy tun address fields",
  83. DeprecatedVersion: "1.10.0",
  84. ScheduledVersion: "1.12.0",
  85. EnvName: "TUN_ADDRESS_X",
  86. MigrationLink: "https://sing-box.sagernet.org/migration/#tun-address-fields-are-merged",
  87. }
  88. var OptionSpecialOutbounds = Note{
  89. Name: "special-outbounds",
  90. Description: "legacy special outbounds",
  91. DeprecatedVersion: "1.11.0",
  92. ScheduledVersion: "1.13.0",
  93. EnvName: "SPECIAL_OUTBOUNDS",
  94. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-special-outbounds-to-rule-actions",
  95. }
  96. var OptionInboundOptions = Note{
  97. Name: "inbound-options",
  98. Description: "legacy inbound fields",
  99. DeprecatedVersion: "1.11.0",
  100. ScheduledVersion: "1.13.0",
  101. EnvName: "INBOUND_OPTIONS",
  102. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-special-outbounds-to-rule-actions",
  103. }
  104. var OptionDestinationOverrideFields = Note{
  105. Name: "destination-override-fields",
  106. Description: "destination override fields in direct outbound",
  107. DeprecatedVersion: "1.11.0",
  108. ScheduledVersion: "1.13.0",
  109. EnvName: "DESTINATION_OVERRIDE_FIELDS",
  110. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-destination-override-fields-to-route-options",
  111. }
  112. var OptionWireGuardOutbound = Note{
  113. Name: "wireguard-outbound",
  114. Description: "legacy wireguard outbound",
  115. DeprecatedVersion: "1.11.0",
  116. ScheduledVersion: "1.13.0",
  117. EnvName: "WIREGUARD_OUTBOUND",
  118. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-wireguard-outbound-to-endpoint",
  119. }
  120. var OptionWireGuardGSO = Note{
  121. Name: "wireguard-gso",
  122. Description: "GSO option in wireguard outbound",
  123. DeprecatedVersion: "1.11.0",
  124. ScheduledVersion: "1.13.0",
  125. EnvName: "WIREGUARD_GSO",
  126. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-wireguard-outbound-to-endpoint",
  127. }
  128. var OptionTUNGSO = Note{
  129. Name: "tun-gso",
  130. Description: "GSO option in tun",
  131. DeprecatedVersion: "1.11.0",
  132. ScheduledVersion: "1.12.0",
  133. EnvName: "TUN_GSO",
  134. }
  135. var Options = []Note{
  136. OptionBadMatchSource,
  137. OptionGEOIP,
  138. OptionGEOSITE,
  139. OptionTUNAddressX,
  140. OptionSpecialOutbounds,
  141. OptionInboundOptions,
  142. OptionDestinationOverrideFields,
  143. OptionWireGuardOutbound,
  144. OptionWireGuardGSO,
  145. OptionTUNGSO,
  146. }