mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-20 16:26:23 -05:00
env flag controlled global padding
This commit is contained in:
parent
ad336ca568
commit
9a8488074e
@ -12,6 +12,13 @@ type EnvFlag struct {
|
||||
AltName string
|
||||
}
|
||||
|
||||
func NewEnvFlag(name string) EnvFlag {
|
||||
return EnvFlag{
|
||||
Name: name,
|
||||
AltName: NormalizeEnvName(name),
|
||||
}
|
||||
}
|
||||
|
||||
func (f EnvFlag) GetValue(defaultValue func() string) string {
|
||||
if v, found := os.LookupEnv(f.Name); found {
|
||||
return v
|
||||
@ -61,18 +68,18 @@ func getExecutableSubDir(dir string) func() string {
|
||||
|
||||
func GetAssetLocation(file string) string {
|
||||
const name = "v2ray.location.asset"
|
||||
assetPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableDir)
|
||||
assetPath := NewEnvFlag(name).GetValue(getExecutableDir)
|
||||
return filepath.Join(assetPath, file)
|
||||
}
|
||||
|
||||
func GetPluginDirectory() string {
|
||||
const name = "v2ray.location.plugin"
|
||||
pluginDir := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableSubDir("plugins"))
|
||||
pluginDir := NewEnvFlag(name).GetValue(getExecutableSubDir("plugins"))
|
||||
return pluginDir
|
||||
}
|
||||
|
||||
func GetConfigurationPath() string {
|
||||
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")
|
||||
}
|
||||
|
@ -112,6 +112,6 @@ func (s *ShakeSizeParser) NextPaddingLen() uint16 {
|
||||
return s.next() % 64
|
||||
}
|
||||
|
||||
func (s *ShakeSizeParser) MaxPaddingLne() uint16 {
|
||||
func (s *ShakeSizeParser) MaxPaddingLen() uint16 {
|
||||
return 64
|
||||
}
|
||||
|
@ -9,9 +9,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core/common/session"
|
||||
"v2ray.com/core/common/task"
|
||||
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
@ -20,7 +17,9 @@ import (
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/common/session"
|
||||
"v2ray.com/core/common/signal"
|
||||
"v2ray.com/core/common/task"
|
||||
"v2ray.com/core/common/uuid"
|
||||
"v2ray.com/core/proxy/vmess"
|
||||
"v2ray.com/core/proxy/vmess/encoding"
|
||||
|
@ -6,16 +6,16 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core/common/session"
|
||||
"v2ray.com/core/common/task"
|
||||
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/platform"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/retry"
|
||||
"v2ray.com/core/common/session"
|
||||
"v2ray.com/core/common/signal"
|
||||
"v2ray.com/core/common/task"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/proxy/vmess"
|
||||
"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,
|
||||
}
|
||||
|
||||
if enablePadding {
|
||||
request.Option.Set(protocol.RequestOptionGlobalPadding)
|
||||
}
|
||||
|
||||
rawAccount, err := request.User.GetTypedAccount()
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
var (
|
||||
enablePadding = false
|
||||
)
|
||||
|
||||
func init() {
|
||||
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||
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)
|
||||
assert(err, IsNil)
|
||||
defer CloseAllServers(servers)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(10)
|
||||
@ -280,8 +287,6 @@ func TestVMessGCM(t *testing.T) {
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
CloseAllServers(servers)
|
||||
}
|
||||
|
||||
func TestVMessGCMUDP(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user