From e413653b1d98283b6a9c922cb4cb4d71b7042514 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Mon, 5 Apr 2021 18:55:44 +0100 Subject: [PATCH] show legacy warning only once --- proxy/vmess/encoding/server.go | 4 +++- proxy/vmess/validator.go | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/proxy/vmess/encoding/server.go b/proxy/vmess/encoding/server.go index 02dae2635..9a3eb3e0c 100644 --- a/proxy/vmess/encoding/server.go +++ b/proxy/vmess/encoding/server.go @@ -199,7 +199,9 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request if s.isAEADForced { return nil, drainConnection(newError("invalid user: VMessAEAD is enforced and a non VMessAEAD connection is received. You can still disable this security feature with environment variable v2ray.vmess.aead.forced = false . You will not be able to enable legacy header workaround in the future.")) } - newError("Critical Warning: potentially invalid user: a non VMessAEAD connection is received. From 2022 Jan 1st, this kind of connection will be rejected by default. You should update or replace your client software now. ").AtWarning().WriteToLog() + if s.userValidator.ShouldShowLegacyWarn() { + newError("Critical Warning: potentially invalid user: a non VMessAEAD connection is received. From 2022 Jan 1st, this kind of connection will be rejected by default. You should update or replace your client software now. This message will not be shown for further violation on this inbound.").AtWarning().WriteToLog() + } user = userLegacy iv := hashTimestamp(md5.New(), timestamp) vmessAccount = userLegacy.Account.(*vmess.MemoryAccount) diff --git a/proxy/vmess/validator.go b/proxy/vmess/validator.go index 65eaf3f25..a46ecc755 100644 --- a/proxy/vmess/validator.go +++ b/proxy/vmess/validator.go @@ -42,6 +42,8 @@ type TimedUserValidator struct { behaviorFused bool aeadDecoderHolder *aead.AuthIDDecoderHolder + + legacyWarnShown bool } type indexTimePair struct { @@ -247,6 +249,17 @@ func (v *TimedUserValidator) BurnTaintFuse(userHash []byte) error { return ErrNotFound } +/* ShouldShowLegacyWarn will return whether a Legacy Warning should be shown +Not guaranteed to only return true once for every inbound, but it is okay. +*/ +func (v *TimedUserValidator) ShouldShowLegacyWarn() bool { + if v.legacyWarnShown { + return false + } + v.legacyWarnShown = true + return true +} + var ErrNotFound = newError("Not Found") var ErrTainted = newError("ErrTainted")