Remove null outbounds in group references

This commit is contained in:
世界 2024-05-12 00:20:16 +08:00
parent c9527c63c3
commit e4d508b725
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4

View File

@ -0,0 +1,33 @@
package filter
import (
M "github.com/sagernet/serenity/common/metadata"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing/common"
)
func init() {
filters = append(filters, filterNullGroupReference)
}
func filterNullGroupReference(metadata M.Metadata, options *option.Options) {
outboundTags := common.Map(options.Outbounds, func(it option.Outbound) string {
return it.Tag
})
for i, outbound := range options.Outbounds {
switch outbound.Type {
case C.TypeSelector:
outbound.SelectorOptions.Outbounds = common.Filter(outbound.SelectorOptions.Outbounds, func(outbound string) bool {
return common.Contains(outboundTags, outbound)
})
case C.TypeURLTest:
outbound.URLTestOptions.Outbounds = common.Filter(outbound.URLTestOptions.Outbounds, func(outbound string) bool {
return common.Contains(outboundTags, outbound)
})
default:
continue
}
options.Outbounds[i] = outbound
}
}