From 7dffc3de5fe95e836ec4970e1fca43831e33eb8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 22 Apr 2024 21:07:39 +0800 Subject: [PATCH] Add `subscription.process.rewrite_multiplex` --- docs/configuration/subscription.md | 7 ++++++- option/options.go | 1 + subscription/process.go | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/configuration/subscription.md b/docs/configuration/subscription.md index 5ae1ae1..fb4f6b1 100644 --- a/docs/configuration/subscription.md +++ b/docs/configuration/subscription.md @@ -12,7 +12,8 @@ "filter_outbound_type": [], "exclude_outbound_type": [], "rename": {}, - "remove_emoji": false + "remove_emoji": false, + "rewrite_multiplex": {} } ], "deduplication": false, @@ -77,6 +78,10 @@ Regexp rename rules, matching outbounds will be renamed. Remove emojis in outbound tags. +#### process.rewrite_multiplex + +Rewrite [Multiplex](https://sing-box.sagernet.org/configuration/shared/multiplex) options. + #### deduplication Remove outbounds with duplicate server destinations (Domain will be resolved to compare). diff --git a/option/options.go b/option/options.go index 3f2eb00..d0c2c91 100644 --- a/option/options.go +++ b/option/options.go @@ -68,6 +68,7 @@ type OutboundProcessOptions struct { ExcludeOutboundType option.Listable[string] `json:"exclude_outbound_type,omitempty"` Rename *badjson.TypedMap[string, string] `json:"rename,omitempty"` RemoveEmoji bool `json:"remove_emoji,omitempty"` + RewriteMultiplex *option.OutboundMultiplexOptions `json:"rewrite_multiplex,omitempty"` } type Profile struct { diff --git a/subscription/process.go b/subscription/process.go index 2e18137..54b4e38 100644 --- a/subscription/process.go +++ b/subscription/process.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/sagernet/serenity/option" + C "github.com/sagernet/sing-box/constant" boxOption "github.com/sagernet/sing-box/option" "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" @@ -103,6 +104,18 @@ func (o *ProcessOptions) Process(outbounds []boxOption.Outbound) []boxOption.Out if originTag != outbound.Tag { renameResult[originTag] = outbound.Tag } + if o.RewriteMultiplex != nil { + switch outbound.Type { + case C.TypeShadowsocks: + outbound.ShadowsocksOptions.Multiplex = o.RewriteMultiplex + case C.TypeTrojan: + outbound.TrojanOptions.Multiplex = o.RewriteMultiplex + case C.TypeVMess: + outbound.VMessOptions.Multiplex = o.RewriteMultiplex + case C.TypeVLESS: + outbound.VLESSOptions.Multiplex = o.RewriteMultiplex + } + } newOutbounds = append(newOutbounds, outbound) } if len(renameResult) > 0 {