mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-04-22 16:17:16 +08:00
chore: correct the xhttp reuse-settings item order
This commit is contained in:
@@ -89,8 +89,8 @@ type XHTTPOptions struct {
|
||||
}
|
||||
|
||||
type XHTTPReuseSettings struct {
|
||||
MaxConnections string `proxy:"max-connections,omitempty"`
|
||||
MaxConcurrency string `proxy:"max-concurrency,omitempty"`
|
||||
MaxConnections string `proxy:"max-connections,omitempty"`
|
||||
CMaxReuseTimes string `proxy:"c-max-reuse-times,omitempty"`
|
||||
HMaxRequestTimes string `proxy:"h-max-request-times,omitempty"`
|
||||
HMaxReusableSecs string `proxy:"h-max-reusable-secs,omitempty"`
|
||||
@@ -529,8 +529,8 @@ func NewVless(option VlessOption) (*Vless, error) {
|
||||
var reuseCfg *xhttp.ReuseConfig
|
||||
if option.XHTTPOpts.ReuseSettings != nil {
|
||||
reuseCfg = &xhttp.ReuseConfig{
|
||||
MaxConnections: option.XHTTPOpts.ReuseSettings.MaxConnections,
|
||||
MaxConcurrency: option.XHTTPOpts.ReuseSettings.MaxConcurrency,
|
||||
MaxConnections: option.XHTTPOpts.ReuseSettings.MaxConnections,
|
||||
CMaxReuseTimes: option.XHTTPOpts.ReuseSettings.CMaxReuseTimes,
|
||||
HMaxRequestTimes: option.XHTTPOpts.ReuseSettings.HMaxRequestTimes,
|
||||
HMaxReusableSecs: option.XHTTPOpts.ReuseSettings.HMaxReusableSecs,
|
||||
@@ -651,8 +651,8 @@ func NewVless(option VlessOption) (*Vless, error) {
|
||||
downloadReuseCfg := reuseCfg
|
||||
if ds.ReuseSettings != nil {
|
||||
downloadReuseCfg = &xhttp.ReuseConfig{
|
||||
MaxConnections: ds.ReuseSettings.MaxConnections,
|
||||
MaxConcurrency: ds.ReuseSettings.MaxConcurrency,
|
||||
MaxConnections: ds.ReuseSettings.MaxConnections,
|
||||
CMaxReuseTimes: ds.ReuseSettings.CMaxReuseTimes,
|
||||
HMaxRequestTimes: ds.ReuseSettings.HMaxRequestTimes,
|
||||
HMaxReusableSecs: ds.ReuseSettings.HMaxReusableSecs,
|
||||
|
||||
+4
-4
@@ -827,8 +827,8 @@ proxies: # socks5
|
||||
# x-padding-bytes: "100-1000"
|
||||
# sc-max-each-post-bytes: 1000000
|
||||
# reuse-settings: # aka XMUX
|
||||
# max-connections: "16-32"
|
||||
# max-concurrency: "0"
|
||||
# max-concurrency: "16-32"
|
||||
# max-connections: "0"
|
||||
# c-max-reuse-times: "0"
|
||||
# h-max-request-times: "600-900"
|
||||
# h-max-reusable-secs: "1800-3000"
|
||||
@@ -842,8 +842,8 @@ proxies: # socks5
|
||||
# x-padding-bytes: "100-1000"
|
||||
# sc-max-each-post-bytes: 1000000
|
||||
# reuse-settings: # aka XMUX
|
||||
# max-connections: "16-32"
|
||||
# max-concurrency: "0"
|
||||
# max-concurrency: "16-32"
|
||||
# max-connections: "0"
|
||||
# c-max-reuse-times: "0"
|
||||
# h-max-request-times: "600-900"
|
||||
# h-max-reusable-secs: "1800-3000"
|
||||
|
||||
+13
-13
@@ -26,8 +26,8 @@ type Config struct {
|
||||
}
|
||||
|
||||
type ReuseConfig struct {
|
||||
MaxConnections string
|
||||
MaxConcurrency string
|
||||
MaxConnections string
|
||||
CMaxReuseTimes string
|
||||
HMaxRequestTimes string
|
||||
HMaxReusableSecs string
|
||||
@@ -171,17 +171,17 @@ func (c *ReuseConfig) ResolveManagerConfig() (Range, Range, error) {
|
||||
return Range{}, Range{}, nil
|
||||
}
|
||||
|
||||
maxConnections, err := ParseRange(c.MaxConnections, "0")
|
||||
if err != nil {
|
||||
return Range{}, Range{}, fmt.Errorf("invalid max-connections: %w", err)
|
||||
}
|
||||
|
||||
maxConcurrency, err := ParseRange(c.MaxConcurrency, "0")
|
||||
if err != nil {
|
||||
return Range{}, Range{}, fmt.Errorf("invalid max-concurrency: %w", err)
|
||||
}
|
||||
|
||||
return maxConnections, maxConcurrency, nil
|
||||
maxConnections, err := ParseRange(c.MaxConnections, "0")
|
||||
if err != nil {
|
||||
return Range{}, Range{}, fmt.Errorf("invalid max-connections: %w", err)
|
||||
}
|
||||
|
||||
return maxConcurrency, maxConnections, nil
|
||||
}
|
||||
|
||||
func (c *ReuseConfig) ResolveEntryConfig() (Range, Range, Range, error) {
|
||||
@@ -189,6 +189,11 @@ func (c *ReuseConfig) ResolveEntryConfig() (Range, Range, Range, error) {
|
||||
return Range{}, Range{}, Range{}, nil
|
||||
}
|
||||
|
||||
cMaxReuseTimes, err := ParseRange(c.CMaxReuseTimes, "0")
|
||||
if err != nil {
|
||||
return Range{}, Range{}, Range{}, fmt.Errorf("invalid c-max-reuse-times: %w", err)
|
||||
}
|
||||
|
||||
hMaxRequestTimes, err := ParseRange(c.HMaxRequestTimes, "0")
|
||||
if err != nil {
|
||||
return Range{}, Range{}, Range{}, fmt.Errorf("invalid h-max-request-times: %w", err)
|
||||
@@ -199,12 +204,7 @@ func (c *ReuseConfig) ResolveEntryConfig() (Range, Range, Range, error) {
|
||||
return Range{}, Range{}, Range{}, fmt.Errorf("invalid h-max-reusable-secs: %w", err)
|
||||
}
|
||||
|
||||
cMaxReuseTimes, err := ParseRange(c.CMaxReuseTimes, "0")
|
||||
if err != nil {
|
||||
return Range{}, Range{}, Range{}, fmt.Errorf("invalid c-max-reuse-times: %w", err)
|
||||
}
|
||||
|
||||
return hMaxRequestTimes, hMaxReusableSecs, cMaxReuseTimes, nil
|
||||
return cMaxReuseTimes, hMaxRequestTimes, hMaxReusableSecs, nil
|
||||
}
|
||||
|
||||
func (c *Config) FillStreamRequest(req *http.Request, sessionID string) error {
|
||||
|
||||
@@ -55,11 +55,11 @@ func (rt *ReuseTransport) Close() error {
|
||||
var _ http.RoundTripper = (*ReuseTransport)(nil)
|
||||
|
||||
type ReuseManager struct {
|
||||
maxConnections int
|
||||
maxConcurrency int
|
||||
maxConnections int
|
||||
cMaxReuseTimes Range
|
||||
hMaxRequestTimes Range
|
||||
hMaxReusableSecs Range
|
||||
cMaxReuseTimes Range
|
||||
maker TransportMaker
|
||||
mu sync.Mutex
|
||||
entries []*reuseEntry
|
||||
@@ -69,20 +69,20 @@ func NewReuseManager(cfg *ReuseConfig, makeTransport TransportMaker) (*ReuseMana
|
||||
if cfg == nil {
|
||||
return nil, nil
|
||||
}
|
||||
connections, concurrency, err := cfg.ResolveManagerConfig()
|
||||
concurrency, connections, err := cfg.ResolveManagerConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hMaxRequestTimes, hMaxReusableSecs, cMaxReuseTimes, err := cfg.ResolveEntryConfig()
|
||||
cMaxReuseTimes, hMaxRequestTimes, hMaxReusableSecs, err := cfg.ResolveEntryConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ReuseManager{
|
||||
maxConnections: connections.Rand(),
|
||||
maxConcurrency: concurrency.Rand(),
|
||||
maxConnections: connections.Rand(),
|
||||
cMaxReuseTimes: cMaxReuseTimes,
|
||||
hMaxRequestTimes: hMaxRequestTimes,
|
||||
hMaxReusableSecs: hMaxReusableSecs,
|
||||
cMaxReuseTimes: cMaxReuseTimes,
|
||||
maker: makeTransport,
|
||||
entries: make([]*reuseEntry, 0),
|
||||
}, nil
|
||||
|
||||
@@ -31,8 +31,8 @@ func TestManagerReuseSameEntry(t *testing.T) {
|
||||
var created atomic.Int64
|
||||
|
||||
manager, err := NewReuseManager(&ReuseConfig{
|
||||
MaxConnections: "1",
|
||||
MaxConcurrency: "1",
|
||||
MaxConnections: "1",
|
||||
HMaxRequestTimes: "10",
|
||||
}, makeTestTransportFactory(&created))
|
||||
if err != nil {
|
||||
@@ -65,8 +65,8 @@ func TestManagerRespectMaxConnections(t *testing.T) {
|
||||
var created atomic.Int64
|
||||
|
||||
manager, err := NewReuseManager(&ReuseConfig{
|
||||
MaxConnections: "2",
|
||||
MaxConcurrency: "1",
|
||||
MaxConnections: "2",
|
||||
HMaxRequestTimes: "100",
|
||||
}, makeTestTransportFactory(&created))
|
||||
if err != nil {
|
||||
@@ -110,8 +110,8 @@ func TestManagerRotateOnRequestLimit(t *testing.T) {
|
||||
var created atomic.Int64
|
||||
|
||||
manager, err := NewReuseManager(&ReuseConfig{
|
||||
MaxConnections: "1",
|
||||
MaxConcurrency: "1",
|
||||
MaxConnections: "1",
|
||||
HMaxRequestTimes: "1",
|
||||
}, makeTestTransportFactory(&created))
|
||||
if err != nil {
|
||||
@@ -144,8 +144,8 @@ func TestManagerRotateOnReusableSecs(t *testing.T) {
|
||||
var created atomic.Int64
|
||||
|
||||
manager, err := NewReuseManager(&ReuseConfig{
|
||||
MaxConnections: "1",
|
||||
MaxConcurrency: "1",
|
||||
MaxConnections: "1",
|
||||
HMaxRequestTimes: "100",
|
||||
HMaxReusableSecs: "1",
|
||||
}, makeTestTransportFactory(&created))
|
||||
@@ -180,8 +180,8 @@ func TestManagerRotateOnConnReuseLimit(t *testing.T) {
|
||||
var created atomic.Int64
|
||||
|
||||
manager, err := NewReuseManager(&ReuseConfig{
|
||||
MaxConnections: "1",
|
||||
MaxConcurrency: "1",
|
||||
MaxConnections: "1",
|
||||
CMaxReuseTimes: "1",
|
||||
HMaxRequestTimes: "100",
|
||||
}, makeTestTransportFactory(&created))
|
||||
|
||||
Reference in New Issue
Block a user