diff --git a/infra/conf/cfgcommon/muxcfg/mux.go b/infra/conf/cfgcommon/muxcfg/mux.go new file mode 100644 index 000000000..ccd3bd776 --- /dev/null +++ b/infra/conf/cfgcommon/muxcfg/mux.go @@ -0,0 +1,25 @@ +package muxcfg + +import "github.com/v2fly/v2ray-core/v4/app/proxyman" + +type MuxConfig struct { + Enabled bool `json:"enabled"` + Concurrency int16 `json:"concurrency"` +} + +// Build creates MultiplexingConfig, Concurrency < 0 completely disables mux. +func (m *MuxConfig) Build() *proxyman.MultiplexingConfig { + if m.Concurrency < 0 { + return nil + } + + var con uint32 = 8 + if m.Concurrency > 0 { + con = uint32(m.Concurrency) + } + + return &proxyman.MultiplexingConfig{ + Enabled: m.Enabled, + Concurrency: con, + } +} diff --git a/infra/conf/cfgcommon/proxycfg/proxy.go b/infra/conf/cfgcommon/proxycfg/proxy.go new file mode 100644 index 000000000..239fe10ac --- /dev/null +++ b/infra/conf/cfgcommon/proxycfg/proxy.go @@ -0,0 +1,21 @@ +package proxycfg + +import "github.com/v2fly/v2ray-core/v4/transport/internet" + +type ProxyConfig struct { + Tag string `json:"tag"` + TransportLayerProxy bool `json:"transportLayer"` +} + +//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen + +// Build implements Buildable. +func (v *ProxyConfig) Build() (*internet.ProxyConfig, error) { + if v.Tag == "" { + return nil, newError("Proxy tag is not set.") + } + return &internet.ProxyConfig{ + Tag: v.Tag, + TransportLayerProxy: v.TransportLayerProxy, + }, nil +} diff --git a/infra/conf/v4/transport_internet.go b/infra/conf/v4/transport_internet.go index e45907332..b79fcbe53 100644 --- a/infra/conf/v4/transport_internet.go +++ b/infra/conf/v4/transport_internet.go @@ -406,19 +406,3 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) { } return config, nil } - -type ProxyConfig struct { - Tag string `json:"tag"` - TransportLayerProxy bool `json:"transportLayer"` -} - -// Build implements Buildable. -func (v *ProxyConfig) Build() (*internet.ProxyConfig, error) { - if v.Tag == "" { - return nil, newError("Proxy tag is not set.") - } - return &internet.ProxyConfig{ - Tag: v.Tag, - TransportLayerProxy: v.TransportLayerProxy, - }, nil -} diff --git a/infra/conf/v4/v2ray.go b/infra/conf/v4/v2ray.go index 306de1525..c41832ade 100644 --- a/infra/conf/v4/v2ray.go +++ b/infra/conf/v4/v2ray.go @@ -3,6 +3,8 @@ package v4 import ( "encoding/json" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/loader" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/muxcfg" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/proxycfg" "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/sniffer" "github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/dns" "github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/log" @@ -58,28 +60,6 @@ func toProtocolList(s []string) ([]proxyman.KnownProtocols, error) { return kp, nil } -type MuxConfig struct { - Enabled bool `json:"enabled"` - Concurrency int16 `json:"concurrency"` -} - -// Build creates MultiplexingConfig, Concurrency < 0 completely disables mux. -func (m *MuxConfig) Build() *proxyman.MultiplexingConfig { - if m.Concurrency < 0 { - return nil - } - - var con uint32 = 8 - if m.Concurrency > 0 { - con = uint32(m.Concurrency) - } - - return &proxyman.MultiplexingConfig{ - Enabled: m.Enabled, - Concurrency: con, - } -} - type InboundDetourAllocationConfig struct { Strategy string `json:"strategy"` Concurrency *uint32 `json:"concurrency"` @@ -221,13 +201,13 @@ func (c *InboundDetourConfig) Build() (*core.InboundHandlerConfig, error) { } type OutboundDetourConfig struct { - Protocol string `json:"protocol"` - SendThrough *cfgcommon.Address `json:"sendThrough"` - Tag string `json:"tag"` - Settings *json.RawMessage `json:"settings"` - StreamSetting *StreamConfig `json:"streamSettings"` - ProxySettings *ProxyConfig `json:"proxySettings"` - MuxSettings *MuxConfig `json:"mux"` + Protocol string `json:"protocol"` + SendThrough *cfgcommon.Address `json:"sendThrough"` + Tag string `json:"tag"` + Settings *json.RawMessage `json:"settings"` + StreamSetting *StreamConfig `json:"streamSettings"` + ProxySettings *proxycfg.ProxyConfig `json:"proxySettings"` + MuxSettings *muxcfg.MuxConfig `json:"mux"` } // Build implements Buildable.