mirror of https://github.com/v2ray/v2ray-core
env flag controlled global padding
parent
ad336ca568
commit
9a8488074e
|
@ -12,6 +12,13 @@ type EnvFlag struct {
|
||||||
AltName string
|
AltName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewEnvFlag(name string) EnvFlag {
|
||||||
|
return EnvFlag{
|
||||||
|
Name: name,
|
||||||
|
AltName: NormalizeEnvName(name),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (f EnvFlag) GetValue(defaultValue func() string) string {
|
func (f EnvFlag) GetValue(defaultValue func() string) string {
|
||||||
if v, found := os.LookupEnv(f.Name); found {
|
if v, found := os.LookupEnv(f.Name); found {
|
||||||
return v
|
return v
|
||||||
|
@ -61,18 +68,18 @@ func getExecutableSubDir(dir string) func() string {
|
||||||
|
|
||||||
func GetAssetLocation(file string) string {
|
func GetAssetLocation(file string) string {
|
||||||
const name = "v2ray.location.asset"
|
const name = "v2ray.location.asset"
|
||||||
assetPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableDir)
|
assetPath := NewEnvFlag(name).GetValue(getExecutableDir)
|
||||||
return filepath.Join(assetPath, file)
|
return filepath.Join(assetPath, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPluginDirectory() string {
|
func GetPluginDirectory() string {
|
||||||
const name = "v2ray.location.plugin"
|
const name = "v2ray.location.plugin"
|
||||||
pluginDir := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableSubDir("plugins"))
|
pluginDir := NewEnvFlag(name).GetValue(getExecutableSubDir("plugins"))
|
||||||
return pluginDir
|
return pluginDir
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConfigurationPath() string {
|
func GetConfigurationPath() string {
|
||||||
const name = "v2ray.location.config"
|
const name = "v2ray.location.config"
|
||||||
configPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableDir)
|
configPath := NewEnvFlag(name).GetValue(getExecutableDir)
|
||||||
return filepath.Join(configPath, "config.json")
|
return filepath.Join(configPath, "config.json")
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,6 +112,6 @@ func (s *ShakeSizeParser) NextPaddingLen() uint16 {
|
||||||
return s.next() % 64
|
return s.next() % 64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShakeSizeParser) MaxPaddingLne() uint16 {
|
func (s *ShakeSizeParser) MaxPaddingLen() uint16 {
|
||||||
return 64
|
return 64
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"v2ray.com/core/common/session"
|
|
||||||
"v2ray.com/core/common/task"
|
|
||||||
|
|
||||||
"v2ray.com/core"
|
"v2ray.com/core"
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
|
@ -20,7 +17,9 @@ import (
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
|
"v2ray.com/core/common/session"
|
||||||
"v2ray.com/core/common/signal"
|
"v2ray.com/core/common/signal"
|
||||||
|
"v2ray.com/core/common/task"
|
||||||
"v2ray.com/core/common/uuid"
|
"v2ray.com/core/common/uuid"
|
||||||
"v2ray.com/core/proxy/vmess"
|
"v2ray.com/core/proxy/vmess"
|
||||||
"v2ray.com/core/proxy/vmess/encoding"
|
"v2ray.com/core/proxy/vmess/encoding"
|
||||||
|
|
|
@ -6,16 +6,16 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"v2ray.com/core/common/session"
|
|
||||||
"v2ray.com/core/common/task"
|
|
||||||
|
|
||||||
"v2ray.com/core"
|
"v2ray.com/core"
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
|
"v2ray.com/core/common/platform"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/common/retry"
|
"v2ray.com/core/common/retry"
|
||||||
|
"v2ray.com/core/common/session"
|
||||||
"v2ray.com/core/common/signal"
|
"v2ray.com/core/common/signal"
|
||||||
|
"v2ray.com/core/common/task"
|
||||||
"v2ray.com/core/proxy"
|
"v2ray.com/core/proxy"
|
||||||
"v2ray.com/core/proxy/vmess"
|
"v2ray.com/core/proxy/vmess"
|
||||||
"v2ray.com/core/proxy/vmess/encoding"
|
"v2ray.com/core/proxy/vmess/encoding"
|
||||||
|
@ -87,6 +87,10 @@ func (v *Handler) Process(ctx context.Context, link *core.Link, dialer proxy.Dia
|
||||||
Option: protocol.RequestOptionChunkStream,
|
Option: protocol.RequestOptionChunkStream,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if enablePadding {
|
||||||
|
request.Option.Set(protocol.RequestOptionGlobalPadding)
|
||||||
|
}
|
||||||
|
|
||||||
rawAccount, err := request.User.GetTypedAccount()
|
rawAccount, err := request.User.GetTypedAccount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newError("failed to get user account").Base(err).AtWarning()
|
return newError("failed to get user account").Base(err).AtWarning()
|
||||||
|
@ -161,8 +165,18 @@ func (v *Handler) Process(ctx context.Context, link *core.Link, dialer proxy.Dia
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
enablePadding = false
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||||
return New(ctx, config.(*Config))
|
return New(ctx, config.(*Config))
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const defaultFlagValue = "NOT_DEFINED_AT_ALL"
|
||||||
|
paddingValue := platform.NewEnvFlag("v2ray.vmess.padding").GetValue(func() string { return defaultFlagValue })
|
||||||
|
if paddingValue != defaultFlagValue {
|
||||||
|
enablePadding = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,8 +253,15 @@ func TestVMessGCM(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
const envName = "V2RAY_VMESS_PADDING"
|
||||||
|
common.Must(os.Setenv(envName, "1"))
|
||||||
|
defer os.Unsetenv(envName)
|
||||||
|
*/
|
||||||
|
|
||||||
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
|
defer CloseAllServers(servers)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(10)
|
wg.Add(10)
|
||||||
|
@ -280,8 +287,6 @@ func TestVMessGCM(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
CloseAllServers(servers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVMessGCMUDP(t *testing.T) {
|
func TestVMessGCMUDP(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue