From 2fd765ea4c31ed97d752f525f5f308f12cd04f45 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sun, 12 Nov 2023 12:28:21 -0500 Subject: [PATCH] Delay XUDP Basekey read --- common/xudp/xudp.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/common/xudp/xudp.go b/common/xudp/xudp.go index af18119f..566ba749 100644 --- a/common/xudp/xudp.go +++ b/common/xudp/xudp.go @@ -6,7 +6,9 @@ import ( "encoding/base64" "fmt" "io" + "strconv" "strings" + "time" "github.com/xtls/xray-core/common/buf" "github.com/xtls/xray-core/common/net" @@ -32,13 +34,16 @@ func init() { if strings.ToLower(platform.NewEnvFlag(platform.XUDPLog).GetValue(func() string { return "" })) == "true" { Show = true } - if raw := platform.NewEnvFlag(platform.XUDPBaseKey).GetValue(func() string { return "" }); raw != "" { - if BaseKey, _ = base64.RawURLEncoding.DecodeString(raw); len(BaseKey) == 32 { - return - } - panic(platform.XUDPBaseKey + ": invalid value: " + raw) - } rand.Read(BaseKey) + go func() { + time.Sleep(100 * time.Millisecond) // this is not nice, but need to give some time for Android to setup ENV + if raw := platform.NewEnvFlag(platform.XUDPBaseKey).GetValue(func() string { return "" }); raw != "" { + if BaseKey, _ = base64.RawURLEncoding.DecodeString(raw); len(BaseKey) == 32 { + return + } + panic(platform.XUDPBaseKey + ": invalid value (BaseKey must be 32 bytes): " + raw + " len " + strconv.Itoa(len(BaseKey))) + } + }() } func GetGlobalID(ctx context.Context) (globalID [8]byte) {