mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-26 10:31:29 +00:00
Implement new deprecated warnings
This commit is contained in:
parent
74b16ff814
commit
a21eaa7de5
|
@ -68,6 +68,6 @@ func preRun(cmd *cobra.Command, args []string) {
|
||||||
if len(configPaths) == 0 && len(configDirectories) == 0 {
|
if len(configPaths) == 0 && len(configDirectories) == 0 {
|
||||||
configPaths = append(configPaths, "config.json")
|
configPaths = append(configPaths, "config.json")
|
||||||
}
|
}
|
||||||
globalCtx = service.ContextWith(globalCtx, deprecated.NewEnvManager(log.StdLogger()))
|
globalCtx = service.ContextWith(globalCtx, deprecated.NewStderrManager(log.StdLogger()))
|
||||||
globalCtx = box.Context(globalCtx, include.InboundRegistry(), include.OutboundRegistry())
|
globalCtx = box.Context(globalCtx, include.InboundRegistry(), include.OutboundRegistry())
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ func check() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(globalCtx)
|
||||||
instance, err := box.New(box.Options{
|
instance, err := box.New(box.Options{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
Options: options,
|
Options: options,
|
||||||
|
|
|
@ -78,9 +78,36 @@ var OptionTUNAddressX = Note{
|
||||||
MigrationLink: "https://sing-box.sagernet.org/migration/#tun-address-fields-are-merged",
|
MigrationLink: "https://sing-box.sagernet.org/migration/#tun-address-fields-are-merged",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var OptionSpecialOutbounds = Note{
|
||||||
|
Name: "special-outbounds",
|
||||||
|
Description: "legacy special outbounds",
|
||||||
|
DeprecatedVersion: "1.11.0",
|
||||||
|
ScheduledVersion: "1.13.0",
|
||||||
|
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",
|
||||||
|
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-special-outbounds-to-rule-actions",
|
||||||
|
}
|
||||||
|
|
||||||
|
var OptionLegacyDNSRouteOptions = Note{
|
||||||
|
Name: "legacy-dns-route-options",
|
||||||
|
Description: "legacy dns route options",
|
||||||
|
DeprecatedVersion: "1.11.0",
|
||||||
|
ScheduledVersion: "1.12.0",
|
||||||
|
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-dns-route-options-to-rule-actions",
|
||||||
|
}
|
||||||
|
|
||||||
var Options = []Note{
|
var Options = []Note{
|
||||||
OptionBadMatchSource,
|
OptionBadMatchSource,
|
||||||
OptionGEOIP,
|
OptionGEOIP,
|
||||||
OptionGEOSITE,
|
OptionGEOSITE,
|
||||||
OptionTUNAddressX,
|
OptionTUNAddressX,
|
||||||
|
OptionSpecialOutbounds,
|
||||||
|
OptionInboundOptions,
|
||||||
|
OptionLegacyDNSRouteOptions,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package deprecated
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"runtime/debug"
|
||||||
|
|
||||||
"github.com/sagernet/sing/service"
|
"github.com/sagernet/sing/service"
|
||||||
)
|
)
|
||||||
|
@ -13,6 +14,7 @@ type Manager interface {
|
||||||
func Report(ctx context.Context, feature Note) {
|
func Report(ctx context.Context, feature Note) {
|
||||||
manager := service.FromContext[Manager](ctx)
|
manager := service.FromContext[Manager](ctx)
|
||||||
if manager == nil {
|
if manager == nil {
|
||||||
|
debug.PrintStack()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
manager.ReportDeprecated(feature)
|
manager.ReportDeprecated(feature)
|
||||||
|
|
|
@ -7,15 +7,23 @@ import (
|
||||||
"github.com/sagernet/sing/common/logger"
|
"github.com/sagernet/sing/common/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type envManager struct {
|
type stderrManager struct {
|
||||||
logger logger.Logger
|
logger logger.Logger
|
||||||
|
reported map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEnvManager(logger logger.Logger) Manager {
|
func NewStderrManager(logger logger.Logger) Manager {
|
||||||
return &envManager{logger: logger}
|
return &stderrManager{
|
||||||
|
logger: logger,
|
||||||
|
reported: make(map[string]bool),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *envManager) ReportDeprecated(feature Note) {
|
func (f *stderrManager) ReportDeprecated(feature Note) {
|
||||||
|
if f.reported[feature.Name] {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
f.reported[feature.Name] = true
|
||||||
if !feature.Impending() {
|
if !feature.Impending() {
|
||||||
f.logger.Warn(feature.MessageWithLink())
|
f.logger.Warn(feature.MessageWithLink())
|
||||||
return
|
return
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/sagernet/sing-box/experimental/deprecated"
|
"github.com/sagernet/sing-box/experimental/deprecated"
|
||||||
|
"github.com/sagernet/sing/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ deprecated.Manager = (*deprecatedManager)(nil)
|
var _ deprecated.Manager = (*deprecatedManager)(nil)
|
||||||
|
@ -16,7 +17,7 @@ type deprecatedManager struct {
|
||||||
func (m *deprecatedManager) ReportDeprecated(feature deprecated.Note) {
|
func (m *deprecatedManager) ReportDeprecated(feature deprecated.Note) {
|
||||||
m.access.Lock()
|
m.access.Lock()
|
||||||
defer m.access.Unlock()
|
defer m.access.Unlock()
|
||||||
m.features = append(m.features, feature)
|
m.features = common.Uniq(append(m.features, feature))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *deprecatedManager) Get() []deprecated.Note {
|
func (m *deprecatedManager) Get() []deprecated.Note {
|
||||||
|
|
|
@ -43,16 +43,16 @@ type BoxService struct {
|
||||||
|
|
||||||
func NewService(configContent string, platformInterface PlatformInterface) (*BoxService, error) {
|
func NewService(configContent string, platformInterface PlatformInterface) (*BoxService, error) {
|
||||||
ctx := box.Context(context.Background(), include.InboundRegistry(), include.OutboundRegistry())
|
ctx := box.Context(context.Background(), include.InboundRegistry(), include.OutboundRegistry())
|
||||||
|
ctx = service.ContextWith[deprecated.Manager](ctx, new(deprecatedManager))
|
||||||
|
ctx = filemanager.WithDefault(ctx, sWorkingPath, sTempPath, sUserID, sGroupID)
|
||||||
options, err := parseConfig(ctx, configContent)
|
options, err := parseConfig(ctx, configContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
runtimeDebug.FreeOSMemory()
|
runtimeDebug.FreeOSMemory()
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
ctx = filemanager.WithDefault(ctx, sWorkingPath, sTempPath, sUserID, sGroupID)
|
|
||||||
urlTestHistoryStorage := urltest.NewHistoryStorage()
|
urlTestHistoryStorage := urltest.NewHistoryStorage()
|
||||||
ctx = service.ContextWithPtr(ctx, urlTestHistoryStorage)
|
ctx = service.ContextWithPtr(ctx, urlTestHistoryStorage)
|
||||||
ctx = service.ContextWith[deprecated.Manager](ctx, new(deprecatedManager))
|
|
||||||
platformWrapper := &platformInterfaceWrapper{iif: platformInterface, useProcFS: platformInterface.UseProcFS()}
|
platformWrapper := &platformInterfaceWrapper{iif: platformInterface, useProcFS: platformInterface.UseProcFS()}
|
||||||
ctx = service.ContextWith[platform.Interface](ctx, platformWrapper)
|
ctx = service.ContextWith[platform.Interface](ctx, platformWrapper)
|
||||||
instance, err := box.New(box.Options{
|
instance, err := box.New(box.Options{
|
||||||
|
|
|
@ -3,6 +3,8 @@ package option
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
C "github.com/sagernet/sing-box/constant"
|
||||||
|
"github.com/sagernet/sing-box/experimental/deprecated"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
"github.com/sagernet/sing/common/json"
|
"github.com/sagernet/sing/common/json"
|
||||||
"github.com/sagernet/sing/common/json/badjson"
|
"github.com/sagernet/sing/common/json/badjson"
|
||||||
|
@ -35,6 +37,10 @@ func (h *Outbound) UnmarshalJSONContext(ctx context.Context, content []byte) err
|
||||||
if registry == nil {
|
if registry == nil {
|
||||||
return E.New("missing outbound options registry in context")
|
return E.New("missing outbound options registry in context")
|
||||||
}
|
}
|
||||||
|
switch h.Type {
|
||||||
|
case C.TypeBlock, C.TypeDNS:
|
||||||
|
deprecated.Report(ctx, deprecated.OptionSpecialOutbounds)
|
||||||
|
}
|
||||||
options, loaded := registry.CreateOptions(h.Type)
|
options, loaded := registry.CreateOptions(h.Type)
|
||||||
if !loaded {
|
if !loaded {
|
||||||
return E.New("unknown outbound type: ", h.Type)
|
return E.New("unknown outbound type: ", h.Type)
|
||||||
|
@ -43,6 +49,11 @@ func (h *Outbound) UnmarshalJSONContext(ctx context.Context, content []byte) err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if listenWrapper, isListen := options.(ListenOptionsWrapper); isListen {
|
||||||
|
if listenWrapper.TakeListenOptions().InboundOptions != (InboundOptions{}) {
|
||||||
|
deprecated.Report(ctx, deprecated.OptionInboundOptions)
|
||||||
|
}
|
||||||
|
}
|
||||||
h.Options = options
|
h.Options = options
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package option
|
package option
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
|
"github.com/sagernet/sing-box/experimental/deprecated"
|
||||||
dns "github.com/sagernet/sing-dns"
|
dns "github.com/sagernet/sing-dns"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
"github.com/sagernet/sing/common/json"
|
"github.com/sagernet/sing/common/json"
|
||||||
|
@ -107,7 +109,7 @@ func (r DNSRuleAction) MarshalJSON() ([]byte, error) {
|
||||||
return badjson.MarshallObjects((_DNSRuleAction)(r), v)
|
return badjson.MarshallObjects((_DNSRuleAction)(r), v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *DNSRuleAction) UnmarshalJSON(data []byte) error {
|
func (r *DNSRuleAction) UnmarshalJSONContext(ctx context.Context, data []byte) error {
|
||||||
err := json.Unmarshal(data, (*_DNSRuleAction)(r))
|
err := json.Unmarshal(data, (*_DNSRuleAction)(r))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -124,11 +126,7 @@ func (r *DNSRuleAction) UnmarshalJSON(data []byte) error {
|
||||||
default:
|
default:
|
||||||
return E.New("unknown DNS rule action: " + r.Action)
|
return E.New("unknown DNS rule action: " + r.Action)
|
||||||
}
|
}
|
||||||
if v == nil {
|
return badjson.UnmarshallExcludedContext(ctx, data, (*_DNSRuleAction)(r), v)
|
||||||
// check unknown fields
|
|
||||||
return json.UnmarshalDisallowUnknownFields(data, &_DNSRuleAction{})
|
|
||||||
}
|
|
||||||
return badjson.UnmarshallExcluded(data, (*_DNSRuleAction)(r), v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type _RouteActionOptions struct {
|
type _RouteActionOptions struct {
|
||||||
|
@ -178,7 +176,7 @@ type _DNSRouteActionOptions struct {
|
||||||
|
|
||||||
type DNSRouteActionOptions _DNSRouteActionOptions
|
type DNSRouteActionOptions _DNSRouteActionOptions
|
||||||
|
|
||||||
func (r *DNSRouteActionOptions) UnmarshalJSON(data []byte) error {
|
func (r *DNSRouteActionOptions) UnmarshalJSONContext(ctx context.Context, data []byte) error {
|
||||||
err := json.Unmarshal(data, (*_DNSRouteActionOptions)(r))
|
err := json.Unmarshal(data, (*_DNSRouteActionOptions)(r))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -186,6 +184,9 @@ func (r *DNSRouteActionOptions) UnmarshalJSON(data []byte) error {
|
||||||
if r.Server == "" {
|
if r.Server == "" {
|
||||||
return E.New("missing server")
|
return E.New("missing server")
|
||||||
}
|
}
|
||||||
|
if r.DisableCache || r.RewriteTTL != nil || r.ClientSubnet != nil {
|
||||||
|
deprecated.Report(ctx, deprecated.OptionLegacyDNSRouteOptions)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package option
|
package option
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
|
@ -32,7 +33,7 @@ func (r DNSRule) MarshalJSON() ([]byte, error) {
|
||||||
return badjson.MarshallObjects((_DNSRule)(r), v)
|
return badjson.MarshallObjects((_DNSRule)(r), v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *DNSRule) UnmarshalJSON(bytes []byte) error {
|
func (r *DNSRule) UnmarshalJSONContext(ctx context.Context, bytes []byte) error {
|
||||||
err := json.Unmarshal(bytes, (*_DNSRule)(r))
|
err := json.Unmarshal(bytes, (*_DNSRule)(r))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -47,7 +48,7 @@ func (r *DNSRule) UnmarshalJSON(bytes []byte) error {
|
||||||
default:
|
default:
|
||||||
return E.New("unknown rule type: " + r.Type)
|
return E.New("unknown rule type: " + r.Type)
|
||||||
}
|
}
|
||||||
err = badjson.UnmarshallExcluded(bytes, (*_DNSRule)(r), v)
|
err = badjson.UnmarshallExcludedContext(ctx, bytes, (*_DNSRule)(r), v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -115,12 +116,12 @@ func (r DefaultDNSRule) MarshalJSON() ([]byte, error) {
|
||||||
return badjson.MarshallObjects(r.RawDefaultDNSRule, r.DNSRuleAction)
|
return badjson.MarshallObjects(r.RawDefaultDNSRule, r.DNSRuleAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *DefaultDNSRule) UnmarshalJSON(data []byte) error {
|
func (r *DefaultDNSRule) UnmarshalJSONContext(ctx context.Context, data []byte) error {
|
||||||
err := json.Unmarshal(data, &r.RawDefaultDNSRule)
|
err := json.Unmarshal(data, &r.RawDefaultDNSRule)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return badjson.UnmarshallExcluded(data, &r.RawDefaultDNSRule, &r.DNSRuleAction)
|
return badjson.UnmarshallExcludedContext(ctx, data, &r.RawDefaultDNSRule, &r.DNSRuleAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r DefaultDNSRule) IsValid() bool {
|
func (r DefaultDNSRule) IsValid() bool {
|
||||||
|
@ -145,12 +146,12 @@ func (r *LogicalDNSRule) MarshalJSON() ([]byte, error) {
|
||||||
return badjson.MarshallObjects(r._LogicalDNSRule, r.DNSRuleAction)
|
return badjson.MarshallObjects(r._LogicalDNSRule, r.DNSRuleAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LogicalDNSRule) UnmarshalJSON(data []byte) error {
|
func (r *LogicalDNSRule) UnmarshalJSONContext(ctx context.Context, data []byte) error {
|
||||||
err := json.Unmarshal(data, &r._LogicalDNSRule)
|
err := json.Unmarshal(data, &r._LogicalDNSRule)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return badjson.UnmarshallExcluded(data, &r._LogicalDNSRule, &r.DNSRuleAction)
|
return badjson.UnmarshallExcludedContext(ctx, data, &r._LogicalDNSRule, &r.DNSRuleAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LogicalDNSRule) IsValid() bool {
|
func (r *LogicalDNSRule) IsValid() bool {
|
||||||
|
|
Loading…
Reference in a new issue