From ee5bc8133a6717330dcbbb25f198a226179efa0c Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Fri, 6 Apr 2018 22:02:52 +0200 Subject: [PATCH] fix cached id generation after system sleep --- proxy/vmess/vmess.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/proxy/vmess/vmess.go b/proxy/vmess/vmess.go index 6d5510ad..20bd83b5 100644 --- a/proxy/vmess/vmess.go +++ b/proxy/vmess/vmess.go @@ -64,7 +64,11 @@ func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, user * var hashValue [16]byte genHashForID := func(id *protocol.ID) { idHash := v.hasher(id.Bytes()) - for ts := user.lastSec; ts <= nowSec; ts++ { + lastSec := user.lastSec + if lastSec < nowSec-cacheDurationSec*2 { + lastSec = nowSec - cacheDurationSec*2 + } + for ts := lastSec; ts <= nowSec; ts++ { common.Must2(idHash.Write(ts.Bytes(nil))) idHash.Sum(hashValue[:0]) idHash.Reset()