Skip to content

Commit

Permalink
Make isAEAD more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
RPRX authored Sep 21, 2020
1 parent 470dc85 commit 010fbf4
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions proxy/vmess/outbound/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package outbound

import (
"context"
"os"
"time"

"v2ray.com/core"
Expand All @@ -31,7 +30,6 @@ type Handler struct {
serverList *protocol.ServerList
serverPicker protocol.ServerPicker
policyManager policy.Manager
aead_disabled bool
}

// New creates a new VMess outbound handler.
Expand All @@ -52,10 +50,6 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
}

if disabled, _ := os.LookupEnv("V2RAY_VMESS_AEAD_DISABLED"); disabled == "true" {
handler.aead_disabled = true
}

return handler, nil
}

Expand Down Expand Up @@ -120,7 +114,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
output := link.Writer

isAEAD := false
if !h.aead_disabled && len(account.AlterIDs) == 0 {
if !aead_disabled && len(account.AlterIDs) == 0 {
isAEAD = true
}

Expand Down Expand Up @@ -185,6 +179,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte

var (
enablePadding = false
aead_disabled = false
)

func shouldEnablePadding(s protocol.SecurityType) bool {
Expand All @@ -197,8 +192,14 @@ func init() {
}))

const defaultFlagValue = "NOT_DEFINED_AT_ALL"

paddingValue := platform.NewEnvFlag("v2ray.vmess.padding").GetValue(func() string { return defaultFlagValue })
if paddingValue != defaultFlagValue {
enablePadding = true
}

aeadDisabled := platform.NewEnvFlag("v2ray.vmess.aead.disabled").GetValue(func() string { return defaultFlagValue })
if aeadDisabled == "true" {
aead_disabled = true
}
}

0 comments on commit 010fbf4

Please sign in to comment.