diff --git a/server/profile.go b/server/profile.go index 44f0a37..b8f5b08 100644 --- a/server/profile.go +++ b/server/profile.go @@ -159,13 +159,10 @@ func (p *Profile) Render(metadata metadata.Metadata) (*boxOption.Options, error) if metadata.Version == nil || metadata.Version.LessThan(semver.ParseVersion("1.12.0-alpha.1")) { ctx = boxOption.ContextWithDontUpgrade(ctx) } - options, err := selectedTemplate.Render(ctx, metadata, p.Name, outbounds, subscriptions) + options, err := selectedTemplate.Render(ctx, metadata, p.Name, endpoints, outbounds, subscriptions) if err != nil { return nil, err } - if metadata.Version != nil && metadata.Version.GreaterThanOrEqual(semver.ParseVersion("1.12.0-alpha.1")) { - options.Endpoints = endpoints - } options, err = badjson.Omitempty(ctx, options) if err != nil { return nil, E.Cause(err, "omitempty") diff --git a/template/filter/filter_null_references.go b/template/filter/filter_null_references.go index 3f88beb..b221a89 100644 --- a/template/filter/filter_null_references.go +++ b/template/filter/filter_null_references.go @@ -15,6 +15,10 @@ func filterNullGroupReference(metadata M.Metadata, options *option.Options) erro outboundTags := common.Map(options.Outbounds, func(it option.Outbound) string { return it.Tag }) + endpointTags := common.Map(options.Endpoints, func(it option.Endpoint) string { + return it.Tag + }) + routingTargets := append(outboundTags, endpointTags...) for _, outbound := range options.Outbounds { switch outboundOptions := outbound.Options.(type) { case *option.SelectorOutboundOptions: @@ -35,12 +39,12 @@ func filterNullGroupReference(metadata M.Metadata, options *option.Options) erro if it.DefaultOptions.Action != C.RuleActionTypeRoute { return true } - return common.Contains(outboundTags, it.DefaultOptions.RouteOptions.Outbound) + return common.Contains(routingTargets, it.DefaultOptions.RouteOptions.Outbound) case C.RuleTypeLogical: if it.LogicalOptions.Action != C.RuleActionTypeRoute { return true } - return common.Contains(outboundTags, it.LogicalOptions.RouteOptions.Outbound) + return common.Contains(routingTargets, it.LogicalOptions.RouteOptions.Outbound) default: panic("no") } diff --git a/template/template.go b/template/template.go index 9535701..26b5438 100644 --- a/template/template.go +++ b/template/template.go @@ -5,6 +5,7 @@ import ( "regexp" M "github.com/sagernet/serenity/common/metadata" + "github.com/sagernet/serenity/common/semver" "github.com/sagernet/serenity/option" "github.com/sagernet/serenity/subscription" "github.com/sagernet/serenity/template/filter" @@ -40,9 +41,12 @@ type ExtraGroup struct { exclude []*regexp.Regexp } -func (t *Template) Render(ctx context.Context, metadata M.Metadata, profileName string, outbounds [][]boxOption.Outbound, subscriptions []*subscription.Subscription) (*boxOption.Options, error) { +func (t *Template) Render(ctx context.Context, metadata M.Metadata, profileName string, endpoints []boxOption.Endpoint, outbounds [][]boxOption.Outbound, subscriptions []*subscription.Subscription) (*boxOption.Options, error) { var options boxOption.Options options.Log = t.Log + if metadata.Version != nil && metadata.Version.GreaterThanOrEqual(semver.ParseVersion("1.12.0-alpha.1")) { + options.Endpoints = endpoints + } err := t.renderDNS(ctx, metadata, &options) if err != nil { return nil, E.Cause(err, "render dns")