ソースを参照

fix time based user hash

V2Ray 10 年 前
コミット
3138960443
1 ファイル変更11 行追加7 行削除
  1. 11 7
      userset.go

+ 11 - 7
userset.go

@@ -2,6 +2,8 @@ package core
 
 import (
 	"time"
+  
+  _ "github.com/v2ray/v2ray-core/log"
 )
 
 const (
@@ -37,7 +39,7 @@ func (us *TimedUserSet) updateUserHash(tick <-chan time.Time) {
 	now := time.Now().UTC()
 	lastSec := now.Unix() - cacheDurationSec
 
-	hash2Remove := make(chan hashEntry, updateIntervalSec*2)
+	hash2Remove := make(chan hashEntry, cacheDurationSec*2)
 	lastSec2Remove := now.Unix() + cacheDurationSec
 	for {
 		now := <-tick
@@ -51,14 +53,16 @@ func (us *TimedUserSet) updateUserHash(tick <-chan time.Time) {
 				delete(us.userHashes, entry.hash)
 			}
 		}
-
-		for i := lastSec + 1; i <= nowSec; i++ {
-			for idx, id := range us.validUserIds {
-				idHash := id.TimeHash(i)
-				hash2Remove <- hashEntry{string(idHash), i}
+    
+    for lastSec < nowSec + updateIntervalSec {
+      for idx, id := range us.validUserIds {
+				idHash := id.TimeHash(lastSec)
+				hash2Remove <- hashEntry{string(idHash), lastSec}
+        //log.Debug("Hash: %v", idHash)
 				us.userHashes[string(idHash)] = idx
 			}
-		}
+      lastSec ++
+    }
 	}
 }