Skip to content

Commit

Permalink
Merge branch 'XTLS:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
omengye authored Oct 24, 2023
2 parents be5c249 + 67c66fa commit b6b08b9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
38 changes: 20 additions & 18 deletions infra/conf/xray.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,36 +489,38 @@ func (c *Config) Override(o *Config, fn string) {

// update the Inbound in slice if the only one in overide config has same tag
if len(o.InboundConfigs) > 0 {
if len(c.InboundConfigs) > 0 && len(o.InboundConfigs) == 1 {
if idx := c.findInboundTag(o.InboundConfigs[0].Tag); idx > -1 {
c.InboundConfigs[idx] = o.InboundConfigs[0]
ctllog.Println("[", fn, "] updated inbound with tag: ", o.InboundConfigs[0].Tag)
for i := range o.InboundConfigs {
if idx := c.findInboundTag(o.InboundConfigs[i].Tag); idx > -1 {
c.InboundConfigs[idx] = o.InboundConfigs[i]
newError("[", fn, "] updated inbound with tag: ", o.InboundConfigs[i].Tag).AtInfo().WriteToLog()

} else {
c.InboundConfigs = append(c.InboundConfigs, o.InboundConfigs[0])
ctllog.Println("[", fn, "] appended inbound with tag: ", o.InboundConfigs[0].Tag)
c.InboundConfigs = append(c.InboundConfigs, o.InboundConfigs[i])
newError("[", fn, "] appended inbound with tag: ", o.InboundConfigs[i].Tag).AtInfo().WriteToLog()
}
} else {
c.InboundConfigs = o.InboundConfigs

}
}

// update the Outbound in slice if the only one in overide config has same tag
if len(o.OutboundConfigs) > 0 {
if len(c.OutboundConfigs) > 0 && len(o.OutboundConfigs) == 1 {
if idx := c.findOutboundTag(o.OutboundConfigs[0].Tag); idx > -1 {
c.OutboundConfigs[idx] = o.OutboundConfigs[0]
ctllog.Println("[", fn, "] updated outbound with tag: ", o.OutboundConfigs[0].Tag)
outboundPrepends := []OutboundDetourConfig{}
for i := range o.OutboundConfigs {
if idx := c.findOutboundTag(o.OutboundConfigs[i].Tag); idx > -1 {
c.OutboundConfigs[idx] = o.OutboundConfigs[i]
newError("[", fn, "] updated outbound with tag: ", o.OutboundConfigs[i].Tag).AtInfo().WriteToLog()
} else {
if strings.Contains(strings.ToLower(fn), "tail") {
c.OutboundConfigs = append(c.OutboundConfigs, o.OutboundConfigs[0])
ctllog.Println("[", fn, "] appended outbound with tag: ", o.OutboundConfigs[0].Tag)
c.OutboundConfigs = append(c.OutboundConfigs, o.OutboundConfigs[i])
newError("[", fn, "] appended outbound with tag: ", o.OutboundConfigs[i].Tag).AtInfo().WriteToLog()
} else {
c.OutboundConfigs = append(o.OutboundConfigs, c.OutboundConfigs...)
ctllog.Println("[", fn, "] prepended outbound with tag: ", o.OutboundConfigs[0].Tag)
outboundPrepends = append(outboundPrepends, o.OutboundConfigs[i])
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...)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions infra/conf/xray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func TestConfig_Override(t *testing.T) {
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}},
"",
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}},
&Config{InboundConfigs: []InboundDetourConfig{{Tag: "pos0"}, {Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}},
},
{
"replace/notag-append",
Expand All @@ -445,10 +445,10 @@ func TestConfig_Override(t *testing.T) {
},
{
"replace/outbounds-prepend",
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}}},
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}}},
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos0"}, {Protocol: "vmess", Tag: "pos1"}, {Tag: "pos3"}}},
&Config{OutboundConfigs: []OutboundDetourConfig{{Tag: "pos1", Protocol: "kcp"}, {Tag: "pos2", Protocol: "kcp"}, {Tag: "pos4", Protocol: "kcp"}}},
"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",
Expand Down
2 changes: 1 addition & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func ReshapeMultiBuffer(ctx context.Context, buffer buf.MultiBuffer) buf.MultiBu
for i, buffer1 := range buffer {
if buffer1.Len() >= buf.Size-21 {
index := int32(bytes.LastIndex(buffer1.Bytes(), TlsApplicationDataStart))
if index <= 0 || index > buf.Size-21 {
if index < 21 || index > buf.Size-21 {
index = buf.Size / 2
}
buffer2 := buf.New()
Expand Down

0 comments on commit b6b08b9

Please sign in to comment.