Skip to content

Commit

Permalink
Remove null outbounds in group references
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed May 11, 2024
1 parent c9527c6 commit e4d508b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions template/filter/filter_null_group_reference.go
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit e4d508b

Please sign in to comment.