@@ -65,6 +65,7 @@ type General struct {
6565 KeepAliveIdle int `json:"keep-alive-idle"`
6666 KeepAliveInterval int `json:"keep-alive-interval"`
6767 DisableKeepAlive bool `json:"disable-keep-alive"`
68+ CloseOnSelected bool `json:"close-on-selected"`
6869}
6970
7071// Inbound config
@@ -270,7 +271,7 @@ type RawTun struct {
270271 MTU uint32 `yaml:"mtu" json:"mtu,omitempty"`
271272 GSO bool `yaml:"gso" json:"gso,omitempty"`
272273 GSOMaxSize uint32 `yaml:"gso-max-size" json:"gso-max-size,omitempty"`
273- //Inet4Address []netip.Prefix `yaml:"inet4-address" json:"inet4-address,omitempty"`
274+ // Inet4Address []netip.Prefix `yaml:"inet4-address" json:"inet4-address,omitempty"`
274275 Inet6Address []netip.Prefix `yaml:"inet6-address" json:"inet6-address,omitempty"`
275276 IPRoute2TableIndex int `yaml:"iproute2-table-index" json:"iproute2-table-index,omitempty"`
276277 IPRoute2RuleIndex int `yaml:"iproute2-rule-index" json:"iproute2-rule-index,omitempty"`
@@ -427,6 +428,7 @@ type RawConfig struct {
427428 KeepAliveIdle int `yaml:"keep-alive-idle" json:"keep-alive-idle"`
428429 KeepAliveInterval int `yaml:"keep-alive-interval" json:"keep-alive-interval"`
429430 DisableKeepAlive bool `yaml:"disable-keep-alive" json:"disable-keep-alive"`
431+ CloseOnSelected bool `yaml:"close-on-selected" json:"close-on-selected"`
430432
431433 ProxyProvider map [string ]map [string ]any `yaml:"proxy-providers" json:"proxy-providers"`
432434 RuleProvider map [string ]map [string ]any `yaml:"rule-providers" json:"rule-providers"`
@@ -595,7 +597,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
595597
596598func ParseRawConfig (rawCfg * RawConfig ) (* Config , error ) {
597599 config := & Config {}
598- log .Infoln ("Start initial configuration in progress" ) //Segment finished in xxm
600+ log .Infoln ("Start initial configuration in progress" ) // Segment finished in xxm
599601 startTime := time .Now ()
600602
601603 general , err := parseGeneral (rawCfg )
@@ -721,7 +723,7 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
721723 }
722724
723725 elapsedTime := time .Since (startTime ) / time .Millisecond // duration in ms
724- log .Infoln ("Initial configuration complete, total time: %dms" , elapsedTime ) //Segment finished in xxm
726+ log .Infoln ("Initial configuration complete, total time: %dms" , elapsedTime ) // Segment finished in xxm
725727
726728 return config , nil
727729}
@@ -772,6 +774,7 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
772774 KeepAliveIdle : cfg .KeepAliveIdle ,
773775 KeepAliveInterval : cfg .KeepAliveInterval ,
774776 DisableKeepAlive : cfg .DisableKeepAlive ,
777+ CloseOnSelected : cfg .CloseOnSelected ,
775778 }, nil
776779}
777780
@@ -916,8 +919,16 @@ func parseProxies(cfg *RawConfig) (proxies map[string]C.Proxy, providersMap map[
916919 slices .Sort (AllProxies )
917920 slices .Sort (AllProviders )
918921
922+ globalCloseOnSelected := cfg .CloseOnSelected
923+
919924 // parse proxy group
920925 for idx , mapping := range groupsConfig {
926+ if groupCloseOnSelected , ok := mapping ["close-on-selected" ].(bool ); ok {
927+ mapping ["close-on-selected" ] = groupCloseOnSelected
928+ } else {
929+ mapping ["close-on-selected" ] = globalCloseOnSelected
930+ }
931+
921932 group , err := outboundgroup .ParseProxyGroup (mapping , proxies , providersMap , AllProxies , AllProviders )
922933 if err != nil {
923934 return nil , nil , fmt .Errorf ("proxy group[%d]: %w" , idx , err )
0 commit comments