mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-04 14:13:03 +00:00
Override outbounds in multi config files (#2659)
* fix override outbounds in multi config * log outbounds override status * fix prepend bug * improve outbounds-prepend test * fix prepend outbound * fix outbounds-prepend test
This commit is contained in:
parent
71fee07175
commit
67c66faaed
@ -504,21 +504,23 @@ func (c *Config) Override(o *Config, fn string) {
|
|||||||
|
|
||||||
// update the Outbound in slice if the only one in overide config has same tag
|
// update the Outbound in slice if the only one in overide config has same tag
|
||||||
if len(o.OutboundConfigs) > 0 {
|
if len(o.OutboundConfigs) > 0 {
|
||||||
if len(c.OutboundConfigs) > 0 && len(o.OutboundConfigs) == 1 {
|
outboundPrepends := []OutboundDetourConfig{}
|
||||||
if idx := c.findOutboundTag(o.OutboundConfigs[0].Tag); idx > -1 {
|
for i := range o.OutboundConfigs {
|
||||||
c.OutboundConfigs[idx] = o.OutboundConfigs[0]
|
if idx := c.findOutboundTag(o.OutboundConfigs[i].Tag); idx > -1 {
|
||||||
ctllog.Println("[", fn, "] updated outbound with tag: ", o.OutboundConfigs[0].Tag)
|
c.OutboundConfigs[idx] = o.OutboundConfigs[i]
|
||||||
|
newError("[", fn, "] updated outbound with tag: ", o.OutboundConfigs[i].Tag).AtInfo().WriteToLog()
|
||||||
} else {
|
} else {
|
||||||
if strings.Contains(strings.ToLower(fn), "tail") {
|
if strings.Contains(strings.ToLower(fn), "tail") {
|
||||||
c.OutboundConfigs = append(c.OutboundConfigs, o.OutboundConfigs[0])
|
c.OutboundConfigs = append(c.OutboundConfigs, o.OutboundConfigs[i])
|
||||||
ctllog.Println("[", fn, "] appended outbound with tag: ", o.OutboundConfigs[0].Tag)
|
newError("[", fn, "] appended outbound with tag: ", o.OutboundConfigs[i].Tag).AtInfo().WriteToLog()
|
||||||
} else {
|
} else {
|
||||||
c.OutboundConfigs = append(o.OutboundConfigs, c.OutboundConfigs...)
|
outboundPrepends = append(outboundPrepends, o.OutboundConfigs[i])
|
||||||
ctllog.Println("[", fn, "] prepended outbound with tag: ", o.OutboundConfigs[0].Tag)
|
newError("[", fn, "] prepend outbound with tag: ", o.OutboundConfigs[i].Tag).AtInfo().WriteToLog()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
c.OutboundConfigs = o.OutboundConfigs
|
if !strings.Contains(strings.ToLower(fn), "tail") && len(outboundPrepends) > 0 {
|
||||||
|
c.OutboundConfigs = append(outboundPrepends, c.OutboundConfigs...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -445,10 +445,10 @@ func TestConfig_Override(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"replace/outbounds-prepend",
|
"replace/outbounds-prepend",
|
||||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
|
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}, {Tag: "pos3"}}},
|
||||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}},
|
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}, {Tag: "pos4", Protocol: "kcp"}}},
|
||||||
"config.json",
|
"config.json",
|
||||||
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}},
|
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos2", Protocol: "kcp"}, {Tag: "pos4", Protocol: "kcp"}, {Tag: "pos0"}, {Tag: "pos1", Protocol: "kcp"}, {Tag: "pos3"}}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"replace/outbounds-append",
|
"replace/outbounds-append",
|
||||||
|
Loading…
Reference in New Issue
Block a user