From 0fd0389d5c4bb616bbea2558bbb7de4ae0d3bf51 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Tue, 21 Apr 2026 20:02:39 +0200 Subject: sub json fix fragment noises effect Co-Authored-By: Alireza Ahmadi --- sub/subJsonService.go | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'sub/subJsonService.go') diff --git a/sub/subJsonService.go b/sub/subJsonService.go index 7ce93e22..acb8e05f 100644 --- a/sub/subJsonService.go +++ b/sub/subJsonService.go @@ -22,8 +22,7 @@ var defaultJson string type SubJsonService struct { configJson map[string]any defaultOutbounds []json_util.RawMessage - fragment string - noises string + fragmentOrNoises bool mux string inboundService service.InboundService @@ -42,6 +41,31 @@ func NewSubJsonService(fragment string, noises string, mux string, rules string, } } + fragmentOrNoises := false + if fragment != "" || noises != "" { + fragmentOrNoises = true + defaultOutboundsSettings := map[string]interface{}{ + "domainStrategy": "UseIP", + "redirect": "", + } + + if fragment != "" { + defaultOutboundsSettings["fragment"] = json_util.RawMessage(fragment) + } + + if noises != "" { + defaultOutboundsSettings["noises"] = json_util.RawMessage(noises) + } + + defaultDirectOutbound := map[string]interface{}{ + "protocol": "freedom", + "settings": defaultOutboundsSettings, + "tag": "direct_out", + } + jsonBytes, _ := json.MarshalIndent(defaultDirectOutbound, "", " ") + defaultOutbounds = append(defaultOutbounds, jsonBytes) + } + if rules != "" { var newRules []any routing, _ := configJson["routing"].(map[string]any) @@ -52,19 +76,10 @@ func NewSubJsonService(fragment string, noises string, mux string, rules string, configJson["routing"] = routing } - if fragment != "" { - defaultOutbounds = append(defaultOutbounds, json_util.RawMessage(fragment)) - } - - if noises != "" { - defaultOutbounds = append(defaultOutbounds, json_util.RawMessage(noises)) - } - return &SubJsonService{ configJson: configJson, defaultOutbounds: defaultOutbounds, - fragment: fragment, - noises: noises, + fragmentOrNoises: fragmentOrNoises, mux: mux, SubService: subService, } @@ -224,8 +239,8 @@ func (s *SubJsonService) streamData(stream string) map[string]any { } delete(streamSettings, "sockopt") - if s.fragment != "" { - streamSettings["sockopt"] = json_util.RawMessage(`{"dialerProxy": "fragment", "tcpKeepAliveIdle": 100, "tcpMptcp": true, "penetrate": true}`) + if s.fragmentOrNoises { + streamSettings["sockopt"] = json_util.RawMessage(`{"dialerProxy": "direct_out", "tcpKeepAliveIdle": 100}`) } // remove proxy protocol -- cgit v1.2.3