2024-10-18 09:58:03 +08:00
|
|
|
package deprecated
|
|
|
|
|
|
|
|
import (
|
2024-12-14 00:18:58 +08:00
|
|
|
"fmt"
|
|
|
|
|
2024-11-18 14:06:25 +08:00
|
|
|
"github.com/sagernet/sing-box/common/badversion"
|
2024-10-18 09:58:03 +08:00
|
|
|
C "github.com/sagernet/sing-box/constant"
|
2024-12-14 00:18:58 +08:00
|
|
|
"github.com/sagernet/sing-box/experimental/locale"
|
2024-10-18 09:58:03 +08:00
|
|
|
F "github.com/sagernet/sing/common/format"
|
|
|
|
|
|
|
|
"golang.org/x/mod/semver"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Note struct {
|
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
DeprecatedVersion string
|
|
|
|
ScheduledVersion string
|
|
|
|
EnvName string
|
|
|
|
MigrationLink string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n Note) Impending() bool {
|
|
|
|
if n.ScheduledVersion == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !semver.IsValid("v" + C.Version) {
|
|
|
|
return false
|
|
|
|
}
|
2024-11-18 14:06:25 +08:00
|
|
|
versionCurrent := badversion.Parse(C.Version)
|
|
|
|
versionMinor := badversion.Parse(n.ScheduledVersion).Minor - versionCurrent.Minor
|
|
|
|
if versionCurrent.PreReleaseIdentifier == "" && versionMinor < 0 {
|
2024-10-18 09:58:03 +08:00
|
|
|
panic("invalid deprecated note: " + n.Name)
|
|
|
|
}
|
2024-11-18 14:06:25 +08:00
|
|
|
return versionMinor <= 1
|
2024-10-18 09:58:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n Note) Message() string {
|
2024-12-14 00:18:58 +08:00
|
|
|
if n.MigrationLink != "" {
|
|
|
|
return fmt.Sprintf(locale.Current().DeprecatedMessage, n.Description, n.DeprecatedVersion, n.ScheduledVersion)
|
|
|
|
} else {
|
|
|
|
return fmt.Sprintf(locale.Current().DeprecatedMessageNoLink, n.Description, n.DeprecatedVersion, n.ScheduledVersion)
|
|
|
|
}
|
2024-10-18 09:58:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n Note) MessageWithLink() string {
|
|
|
|
return F.ToString(
|
|
|
|
n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
|
|
|
|
" and will be removed in sing-box ", n.ScheduledVersion, ", checkout documentation for migration: ", n.MigrationLink,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
var OptionBadMatchSource = Note{
|
|
|
|
Name: "bad-match-source",
|
|
|
|
Description: "legacy match source rule item",
|
|
|
|
DeprecatedVersion: "1.10.0",
|
|
|
|
ScheduledVersion: "1.11.0",
|
2024-11-18 14:06:25 +08:00
|
|
|
EnvName: "BAD_MATCH_SOURCE",
|
2024-10-18 09:58:03 +08:00
|
|
|
MigrationLink: "https://sing-box.sagernet.org/deprecated/#match-source-rule-items-are-renamed",
|
|
|
|
}
|
|
|
|
|
|
|
|
var OptionGEOIP = Note{
|
|
|
|
Name: "geoip",
|
|
|
|
Description: "geoip database",
|
|
|
|
DeprecatedVersion: "1.8.0",
|
|
|
|
ScheduledVersion: "1.12.0",
|
|
|
|
EnvName: "GEOIP",
|
|
|
|
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-geoip-to-rule-sets",
|
|
|
|
}
|
|
|
|
|
|
|
|
var OptionGEOSITE = Note{
|
|
|
|
Name: "geosite",
|
|
|
|
Description: "geosite database",
|
|
|
|
DeprecatedVersion: "1.8.0",
|
|
|
|
ScheduledVersion: "1.12.0",
|
|
|
|
EnvName: "GEOSITE",
|
|
|
|
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-geosite-to-rule-sets",
|
|
|
|
}
|
|
|
|
|
|
|
|
var OptionTUNAddressX = Note{
|
|
|
|
Name: "tun-address-x",
|
|
|
|
Description: "legacy tun address fields",
|
|
|
|
DeprecatedVersion: "1.10.0",
|
|
|
|
ScheduledVersion: "1.12.0",
|
2024-11-18 14:06:25 +08:00
|
|
|
EnvName: "TUN_ADDRESS_X",
|
2024-10-18 09:58:03 +08:00
|
|
|
MigrationLink: "https://sing-box.sagernet.org/migration/#tun-address-fields-are-merged",
|
|
|
|
}
|
|
|
|
|
2024-11-07 12:02:36 +08:00
|
|
|
var OptionSpecialOutbounds = Note{
|
|
|
|
Name: "special-outbounds",
|
|
|
|
Description: "legacy special outbounds",
|
|
|
|
DeprecatedVersion: "1.11.0",
|
|
|
|
ScheduledVersion: "1.13.0",
|
|
|
|
EnvName: "SPECIAL_OUTBOUNDS",
|
|
|
|
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-special-outbounds-to-rule-actions",
|
|
|
|
}
|
|
|
|
|
|
|
|
var OptionInboundOptions = Note{
|
|
|
|
Name: "inbound-options",
|
|
|
|
Description: "legacy inbound fields",
|
|
|
|
DeprecatedVersion: "1.11.0",
|
|
|
|
ScheduledVersion: "1.13.0",
|
|
|
|
EnvName: "INBOUND_OPTIONS",
|
|
|
|
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-special-outbounds-to-rule-actions",
|
|
|
|
}
|
|
|
|
|
2024-11-14 18:31:37 +08:00
|
|
|
var OptionDestinationOverrideFields = Note{
|
|
|
|
Name: "destination-override-fields",
|
|
|
|
Description: "destination override fields in direct outbound",
|
|
|
|
DeprecatedVersion: "1.11.0",
|
|
|
|
ScheduledVersion: "1.13.0",
|
|
|
|
EnvName: "DESTINATION_OVERRIDE_FIELDS",
|
|
|
|
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-destination-override-fields-to-route-options",
|
|
|
|
}
|
|
|
|
|
2024-11-21 18:10:41 +08:00
|
|
|
var OptionWireGuardOutbound = Note{
|
|
|
|
Name: "wireguard-outbound",
|
|
|
|
Description: "legacy wireguard outbound",
|
|
|
|
DeprecatedVersion: "1.11.0",
|
|
|
|
ScheduledVersion: "1.13.0",
|
|
|
|
EnvName: "WIREGUARD_OUTBOUND",
|
|
|
|
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-wireguard-outbound-to-endpoint",
|
|
|
|
}
|
|
|
|
|
2024-10-18 09:58:03 +08:00
|
|
|
var Options = []Note{
|
|
|
|
OptionBadMatchSource,
|
|
|
|
OptionGEOIP,
|
|
|
|
OptionGEOSITE,
|
|
|
|
OptionTUNAddressX,
|
2024-11-07 12:02:36 +08:00
|
|
|
OptionSpecialOutbounds,
|
|
|
|
OptionInboundOptions,
|
2024-11-14 18:31:37 +08:00
|
|
|
OptionDestinationOverrideFields,
|
2024-11-21 18:10:41 +08:00
|
|
|
OptionWireGuardOutbound,
|
2024-10-18 09:58:03 +08:00
|
|
|
}
|