mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Replace "only" with "xudpConcurrency" in Mux config
This commit is contained in:
parent
29d7865d78
commit
24a2be43ef
6 changed files with 112 additions and 90 deletions
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/xtls/xray-core/app/dispatcher"
|
||||
"github.com/xtls/xray-core/app/proxyman"
|
||||
"github.com/xtls/xray-core/app/stats"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/serial"
|
||||
core "github.com/xtls/xray-core/core"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
|
@ -108,36 +107,18 @@ func (c *SniffingConfig) Build() (*proxyman.SniffingConfig, error) {
|
|||
}
|
||||
|
||||
type MuxConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Concurrency int16 `json:"concurrency"`
|
||||
Only string `json:"only"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Concurrency int16 `json:"concurrency"`
|
||||
XudpConcurrency int16 `json:"xudpConcurrency"`
|
||||
}
|
||||
|
||||
// Build creates MultiplexingConfig, Concurrency < 0 completely disables mux.
|
||||
func (m *MuxConfig) Build() (*proxyman.MultiplexingConfig, error) {
|
||||
if m.Concurrency < 0 {
|
||||
return nil, nil
|
||||
}
|
||||
if m.Concurrency == 0 {
|
||||
m.Concurrency = 8
|
||||
}
|
||||
|
||||
config := &proxyman.MultiplexingConfig{
|
||||
Enabled: m.Enabled,
|
||||
Concurrency: uint32(m.Concurrency),
|
||||
}
|
||||
|
||||
switch strings.ToLower(m.Only) {
|
||||
case "", "both":
|
||||
case "tcp":
|
||||
config.Only = uint32(net.Network_TCP)
|
||||
case "udp":
|
||||
config.Only = uint32(net.Network_UDP)
|
||||
default:
|
||||
return nil, newError(`unknown "only": `, m.Only)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
return &proxyman.MultiplexingConfig{
|
||||
Enabled: m.Enabled,
|
||||
Concurrency: int32(m.Concurrency),
|
||||
XudpConcurrency: int32(m.XudpConcurrency),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type InboundDetourAllocationConfig struct {
|
||||
|
|
|
@ -345,13 +345,16 @@ func TestMuxConfig_Build(t *testing.T) {
|
|||
}},
|
||||
{"empty def", `{}`, &proxyman.MultiplexingConfig{
|
||||
Enabled: false,
|
||||
Concurrency: 8,
|
||||
Concurrency: 0,
|
||||
}},
|
||||
{"not enable", `{"enabled": false, "concurrency": 4}`, &proxyman.MultiplexingConfig{
|
||||
Enabled: false,
|
||||
Concurrency: 4,
|
||||
}},
|
||||
{"forbidden", `{"enabled": false, "concurrency": -1}`, nil},
|
||||
{"forbidden", `{"enabled": false, "concurrency": -1}`, &proxyman.MultiplexingConfig{
|
||||
Enabled: false,
|
||||
Concurrency: -1,
|
||||
}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue