constants.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 OptionBadMatchSource = Note{
  53. Name: "bad-match-source",
  54. Description: "legacy match source rule item",
  55. DeprecatedVersion: "1.10.0",
  56. ScheduledVersion: "1.11.0",
  57. EnvName: "BAD_MATCH_SOURCE",
  58. MigrationLink: "https://sing-box.sagernet.org/deprecated/#match-source-rule-items-are-renamed",
  59. }
  60. var OptionGEOIP = Note{
  61. Name: "geoip",
  62. Description: "geoip database",
  63. DeprecatedVersion: "1.8.0",
  64. ScheduledVersion: "1.12.0",
  65. EnvName: "GEOIP",
  66. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-geoip-to-rule-sets",
  67. }
  68. var OptionGEOSITE = Note{
  69. Name: "geosite",
  70. Description: "geosite database",
  71. DeprecatedVersion: "1.8.0",
  72. ScheduledVersion: "1.12.0",
  73. EnvName: "GEOSITE",
  74. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-geosite-to-rule-sets",
  75. }
  76. var OptionTUNAddressX = Note{
  77. Name: "tun-address-x",
  78. Description: "legacy tun address fields",
  79. DeprecatedVersion: "1.10.0",
  80. ScheduledVersion: "1.12.0",
  81. EnvName: "TUN_ADDRESS_X",
  82. MigrationLink: "https://sing-box.sagernet.org/migration/#tun-address-fields-are-merged",
  83. }
  84. var OptionSpecialOutbounds = Note{
  85. Name: "special-outbounds",
  86. Description: "legacy special outbounds",
  87. DeprecatedVersion: "1.11.0",
  88. ScheduledVersion: "1.13.0",
  89. EnvName: "SPECIAL_OUTBOUNDS",
  90. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-special-outbounds-to-rule-actions",
  91. }
  92. var OptionInboundOptions = Note{
  93. Name: "inbound-options",
  94. Description: "legacy inbound fields",
  95. DeprecatedVersion: "1.11.0",
  96. ScheduledVersion: "1.13.0",
  97. EnvName: "INBOUND_OPTIONS",
  98. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-special-outbounds-to-rule-actions",
  99. }
  100. var OptionDestinationOverrideFields = Note{
  101. Name: "destination-override-fields",
  102. Description: "destination override fields in direct outbound",
  103. DeprecatedVersion: "1.11.0",
  104. ScheduledVersion: "1.13.0",
  105. EnvName: "DESTINATION_OVERRIDE_FIELDS",
  106. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-destination-override-fields-to-route-options",
  107. }
  108. var OptionWireGuardOutbound = Note{
  109. Name: "wireguard-outbound",
  110. Description: "legacy wireguard outbound",
  111. DeprecatedVersion: "1.11.0",
  112. ScheduledVersion: "1.13.0",
  113. EnvName: "WIREGUARD_OUTBOUND",
  114. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-wireguard-outbound-to-endpoint",
  115. }
  116. var OptionWireGuardGSO = Note{
  117. Name: "wireguard-gso",
  118. Description: "GSO option in wireguard outbound",
  119. DeprecatedVersion: "1.11.0",
  120. ScheduledVersion: "1.13.0",
  121. EnvName: "WIREGUARD_GSO",
  122. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-wireguard-outbound-to-endpoint",
  123. }
  124. var OptionTUNGSO = Note{
  125. Name: "tun-gso",
  126. Description: "GSO option in tun",
  127. DeprecatedVersion: "1.11.0",
  128. ScheduledVersion: "1.12.0",
  129. EnvName: "TUN_GSO",
  130. MigrationLink: "https://sing-box.sagernet.org/deprecated/#gso-option-in-tun",
  131. }
  132. var OptionLegacyDNSTransport = Note{
  133. Name: "legacy-dns-transport",
  134. Description: "legacy DNS servers",
  135. DeprecatedVersion: "1.12.0",
  136. ScheduledVersion: "1.14.0",
  137. EnvName: "LEGACY_DNS_SERVERS",
  138. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-to-new-dns-server-formats",
  139. }
  140. var OptionLegacyDNSFakeIPOptions = Note{
  141. Name: "legacy-dns-fakeip-options",
  142. Description: "legacy DNS fakeip options",
  143. DeprecatedVersion: "1.12.0",
  144. ScheduledVersion: "1.14.0",
  145. EnvName: "LEGACY_DNS_FAKEIP_OPTIONS",
  146. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-to-new-dns-server-formats",
  147. }
  148. var OptionOutboundDNSRuleItem = Note{
  149. Name: "outbound-dns-rule-item",
  150. Description: "outbound DNS rule item",
  151. DeprecatedVersion: "1.12.0",
  152. ScheduledVersion: "1.14.0",
  153. EnvName: "OUTBOUND_DNS_RULE_ITEM",
  154. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-outbound-dns-rule-items-to-domain-resolver",
  155. }
  156. var OptionMissingDomainResolver = Note{
  157. Name: "missing-domain-resolver",
  158. Description: "missing `route.default_domain_resolver` or `domain_resolver` in dial fields",
  159. DeprecatedVersion: "1.12.0",
  160. ScheduledVersion: "1.14.0",
  161. EnvName: "MISSING_DOMAIN_RESOLVER",
  162. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-outbound-dns-rule-items-to-domain-resolver",
  163. }
  164. var OptionLegacyECHOptions = Note{
  165. Name: "legacy-ech-options",
  166. Description: "legacy ECH options",
  167. DeprecatedVersion: "1.12.0",
  168. ScheduledVersion: "1.13.0",
  169. EnvName: "LEGACY_ECH_OPTIONS",
  170. MigrationLink: "https://sing-box.sagernet.org/deprecated/#legacy-ech-fields",
  171. }
  172. var OptionLegacyDomainStrategyOptions = Note{
  173. Name: "legacy-domain-strategy-options",
  174. Description: "legacy domain strategy options",
  175. DeprecatedVersion: "1.12.0",
  176. ScheduledVersion: "1.14.0",
  177. EnvName: "LEGACY_DOMAIN_STRATEGY_OPTIONS",
  178. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-domain-strategy-options",
  179. }
  180. var Options = []Note{
  181. OptionBadMatchSource,
  182. OptionGEOIP,
  183. OptionGEOSITE,
  184. OptionTUNAddressX,
  185. OptionSpecialOutbounds,
  186. OptionInboundOptions,
  187. OptionDestinationOverrideFields,
  188. OptionWireGuardOutbound,
  189. OptionWireGuardGSO,
  190. OptionTUNGSO,
  191. OptionLegacyDNSTransport,
  192. OptionLegacyDNSFakeIPOptions,
  193. OptionOutboundDNSRuleItem,
  194. OptionMissingDomainResolver,
  195. OptionLegacyECHOptions,
  196. OptionLegacyDomainStrategyOptions,
  197. }