constants.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-to-new-dns-server-formats",
  146. }
  147. var OptionOutboundDNSRuleItem = Note{
  148. Name: "outbound-dns-rule-item",
  149. Description: "outbound DNS rule item",
  150. DeprecatedVersion: "1.12.0",
  151. ScheduledVersion: "1.14.0",
  152. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-outbound-dns-rule-items-to-domain-resolver",
  153. }
  154. var OptionMissingDomainResolver = Note{
  155. Name: "missing-domain-resolver",
  156. Description: "missing `route.default_domain_resolver` or `domain_resolver` in dial fields",
  157. DeprecatedVersion: "1.12.0",
  158. ScheduledVersion: "1.14.0",
  159. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-outbound-dns-rule-items-to-domain-resolver",
  160. }
  161. var OptionLegacyECHOptions = Note{
  162. Name: "legacy-ech-options",
  163. Description: "legacy ECH options",
  164. DeprecatedVersion: "1.12.0",
  165. ScheduledVersion: "1.13.0",
  166. MigrationLink: "https://sing-box.sagernet.org/deprecated/#legacy-ech-fields",
  167. }
  168. var Options = []Note{
  169. OptionBadMatchSource,
  170. OptionGEOIP,
  171. OptionGEOSITE,
  172. OptionTUNAddressX,
  173. OptionSpecialOutbounds,
  174. OptionInboundOptions,
  175. OptionDestinationOverrideFields,
  176. OptionWireGuardOutbound,
  177. OptionWireGuardGSO,
  178. OptionTUNGSO,
  179. OptionLegacyDNSTransport,
  180. OptionLegacyDNSFakeIPOptions,
  181. OptionOutboundDNSRuleItem,
  182. OptionMissingDomainResolver,
  183. OptionLegacyECHOptions,
  184. }