diff --git a/common/dialer/default.go b/common/dialer/default.go index b27b4820..f45b7809 100644 --- a/common/dialer/default.go +++ b/common/dialer/default.go @@ -7,7 +7,6 @@ import ( "github.com/sagernet/sing-box/adapter" "github.com/sagernet/sing-box/common/dialer/conntrack" - "github.com/sagernet/sing-box/common/warning" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/option" "github.com/sagernet/sing/common/control" @@ -17,41 +16,6 @@ import ( "github.com/sagernet/tfo-go" ) -var warnBindInterfaceOnUnsupportedPlatform = warning.New( - func() bool { - return !(C.IsLinux || C.IsWindows || C.IsDarwin) - }, - "outbound option `bind_interface` is only supported on Linux and Windows", -) - -var warnRoutingMarkOnUnsupportedPlatform = warning.New( - func() bool { - return !C.IsLinux - }, - "outbound option `routing_mark` is only supported on Linux", -) - -var warnReuseAdderOnUnsupportedPlatform = warning.New( - func() bool { - return !(C.IsDarwin || C.IsDragonfly || C.IsFreebsd || C.IsLinux || C.IsNetbsd || C.IsOpenbsd || C.IsSolaris || C.IsWindows) - }, - "outbound option `reuse_addr` is unsupported on current platform", -) - -var warnProtectPathOnNonAndroid = warning.New( - func() bool { - return !C.IsAndroid - }, - "outbound option `protect_path` is only supported on Android", -) - -var warnTFOOnUnsupportedPlatform = warning.New( - func() bool { - return !(C.IsDarwin || C.IsFreebsd || C.IsLinux || C.IsWindows) - }, - "outbound option `tcp_fast_open` is unsupported on current platform", -) - type DefaultDialer struct { dialer4 tfo.Dialer dialer6 tfo.Dialer @@ -66,7 +30,6 @@ func NewDefault(router adapter.Router, options option.DialerOptions) *DefaultDia var dialer net.Dialer var listener net.ListenConfig if options.BindInterface != "" { - warnBindInterfaceOnUnsupportedPlatform.Check() bindFunc := control.BindToInterface(router.InterfaceFinder(), options.BindInterface, -1) dialer.Control = control.Append(dialer.Control, bindFunc) listener.Control = control.Append(listener.Control, bindFunc) @@ -80,7 +43,6 @@ func NewDefault(router adapter.Router, options option.DialerOptions) *DefaultDia listener.Control = control.Append(listener.Control, bindFunc) } if options.RoutingMark != 0 { - warnRoutingMarkOnUnsupportedPlatform.Check() dialer.Control = control.Append(dialer.Control, control.RoutingMark(options.RoutingMark)) listener.Control = control.Append(listener.Control, control.RoutingMark(options.RoutingMark)) } else if router.DefaultMark() != 0 { @@ -88,11 +50,9 @@ func NewDefault(router adapter.Router, options option.DialerOptions) *DefaultDia listener.Control = control.Append(listener.Control, control.RoutingMark(router.DefaultMark())) } if options.ReuseAddr { - warnReuseAdderOnUnsupportedPlatform.Check() listener.Control = control.Append(listener.Control, control.ReuseAddr()) } if options.ProtectPath != "" { - warnProtectPathOnNonAndroid.Check() dialer.Control = control.Append(dialer.Control, control.ProtectPath(options.ProtectPath)) listener.Control = control.Append(listener.Control, control.ProtectPath(options.ProtectPath)) } @@ -101,9 +61,6 @@ func NewDefault(router adapter.Router, options option.DialerOptions) *DefaultDia } else { dialer.Timeout = C.TCPTimeout } - if options.TCPFastOpen { - warnTFOOnUnsupportedPlatform.Check() - } var udpFragment bool if options.UDPFragment != nil { udpFragment = *options.UDPFragment diff --git a/common/warning/warning.go b/common/warning/warning.go deleted file mode 100644 index dbcdc3d8..00000000 --- a/common/warning/warning.go +++ /dev/null @@ -1,31 +0,0 @@ -package warning - -import ( - "sync" - - "github.com/sagernet/sing-box/log" -) - -type Warning struct { - logger log.Logger - check CheckFunc - message string - checkOnce sync.Once -} - -type CheckFunc = func() bool - -func New(checkFunc CheckFunc, message string) Warning { - return Warning{ - check: checkFunc, - message: message, - } -} - -func (w *Warning) Check() { - w.checkOnce.Do(func() { - if w.check() { - log.Warn(w.message) - } - }) -} diff --git a/route/router.go b/route/router.go index 881b5b7a..7eeb20c5 100644 --- a/route/router.go +++ b/route/router.go @@ -21,7 +21,6 @@ import ( "github.com/sagernet/sing-box/common/mux" "github.com/sagernet/sing-box/common/process" "github.com/sagernet/sing-box/common/sniff" - "github.com/sagernet/sing-box/common/warning" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/experimental/libbox/platform" "github.com/sagernet/sing-box/log" @@ -43,27 +42,6 @@ import ( "github.com/sagernet/sing/common/uot" ) -var warnDefaultInterfaceOnUnsupportedPlatform = warning.New( - func() bool { - return !(C.IsLinux || C.IsWindows || C.IsDarwin) - }, - "route option `default_mark` is only supported on Linux and Windows", -) - -var warnDefaultMarkOnNonLinux = warning.New( - func() bool { - return !C.IsLinux - }, - "route option `default_mark` is only supported on Linux", -) - -var warnFindProcessOnUnsupportedPlatform = warning.New( - func() bool { - return !(C.IsLinux || C.IsWindows || C.IsDarwin) - }, - "route option `find_process` is only supported on Linux, Windows, and macOS", -) - var _ adapter.Router = (*Router)(nil) type Router struct { @@ -114,16 +92,6 @@ func NewRouter( inbounds []option.Inbound, platformInterface platform.Interface, ) (*Router, error) { - if options.DefaultInterface != "" { - warnDefaultInterfaceOnUnsupportedPlatform.Check() - } - if options.DefaultMark != 0 { - warnDefaultMarkOnNonLinux.Check() - } - if options.FindProcess { - warnFindProcessOnUnsupportedPlatform.Check() - } - router := &Router{ ctx: ctx, logger: logFactory.NewLogger("router"), diff --git a/route/rule_package_name.go b/route/rule_package_name.go index 3289b503..d1ca09eb 100644 --- a/route/rule_package_name.go +++ b/route/rule_package_name.go @@ -4,13 +4,6 @@ import ( "strings" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/common/warning" - C "github.com/sagernet/sing-box/constant" -) - -var warnPackageNameOnNonAndroid = warning.New( - func() bool { return !C.IsAndroid }, - "rule item `package_name` is only supported on Android", ) var _ RuleItem = (*PackageNameItem)(nil) @@ -21,7 +14,6 @@ type PackageNameItem struct { } func NewPackageNameItem(packageNameList []string) *PackageNameItem { - warnPackageNameOnNonAndroid.Check() rule := &PackageNameItem{ packageNames: packageNameList, packageMap: make(map[string]bool), diff --git a/route/rule_process_name.go b/route/rule_process_name.go index 37108eda..ce051666 100644 --- a/route/rule_process_name.go +++ b/route/rule_process_name.go @@ -5,13 +5,6 @@ import ( "strings" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/common/warning" - C "github.com/sagernet/sing-box/constant" -) - -var warnProcessNameOnNonSupportedPlatform = warning.New( - func() bool { return !(C.IsLinux || C.IsWindows || C.IsDarwin) }, - "rule item `process_name` is only supported on Linux, Windows and macOS", ) var _ RuleItem = (*ProcessItem)(nil) @@ -22,7 +15,6 @@ type ProcessItem struct { } func NewProcessItem(processNameList []string) *ProcessItem { - warnProcessNameOnNonSupportedPlatform.Check() rule := &ProcessItem{ processes: processNameList, processMap: make(map[string]bool), diff --git a/route/rule_process_path.go b/route/rule_process_path.go index 4398f614..feae4b27 100644 --- a/route/rule_process_path.go +++ b/route/rule_process_path.go @@ -4,13 +4,6 @@ import ( "strings" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/common/warning" - C "github.com/sagernet/sing-box/constant" -) - -var warnProcessPathOnNonSupportedPlatform = warning.New( - func() bool { return !(C.IsLinux || C.IsWindows || C.IsDarwin) }, - "rule item `process_path` is only supported on Linux, Windows and macOS", ) var _ RuleItem = (*ProcessPathItem)(nil) @@ -21,7 +14,6 @@ type ProcessPathItem struct { } func NewProcessPathItem(processNameList []string) *ProcessPathItem { - warnProcessPathOnNonSupportedPlatform.Check() rule := &ProcessPathItem{ processes: processNameList, processMap: make(map[string]bool), diff --git a/route/rule_user.go b/route/rule_user.go index e06250e4..bed97fba 100644 --- a/route/rule_user.go +++ b/route/rule_user.go @@ -4,16 +4,9 @@ import ( "strings" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/common/warning" - C "github.com/sagernet/sing-box/constant" F "github.com/sagernet/sing/common/format" ) -var warnUserOnNonLinux = warning.New( - func() bool { return !C.IsLinux }, - "rule item `user` is only supported on Linux", -) - var _ RuleItem = (*UserItem)(nil) type UserItem struct { @@ -22,7 +15,6 @@ type UserItem struct { } func NewUserItem(users []string) *UserItem { - warnUserOnNonLinux.Check() userMap := make(map[string]bool) for _, protocol := range users { userMap[protocol] = true diff --git a/route/rule_user_id.go b/route/rule_user_id.go index 59841300..43ab704e 100644 --- a/route/rule_user_id.go +++ b/route/rule_user_id.go @@ -4,16 +4,9 @@ import ( "strings" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/common/warning" - C "github.com/sagernet/sing-box/constant" F "github.com/sagernet/sing/common/format" ) -var warnUserIDOnNonLinux = warning.New( - func() bool { return !C.IsLinux }, - "rule item `user_id` is only supported on Linux", -) - var _ RuleItem = (*UserIdItem)(nil) type UserIdItem struct { @@ -22,7 +15,6 @@ type UserIdItem struct { } func NewUserIDItem(userIdList []int32) *UserIdItem { - warnUserIDOnNonLinux.Check() rule := &UserIdItem{ userIds: userIdList, userIdMap: make(map[int32]bool),