Просмотр исходного кода

Improve readability: use go-cache-lru constants

Rod Hynes 5 лет назад
Родитель
Сommit
c8cefd24ce
3 измененных файлов с 8 добавлено и 4 удалено
  1. 2 2
      psiphon/common/obfuscator/history.go
  2. 1 1
      psiphon/controller.go
  3. 5 1
      psiphon/server/replay.go

+ 2 - 2
psiphon/common/obfuscator/history.go

@@ -126,9 +126,9 @@ func (h *SeedHistory) AddNew(
 	// an unlikely possibility that this Add and the following Get don't see the
 	// same existing key/value state.
 
-	if h.seedToTime.Add(key, time.Now(), 0) == nil {
+	if h.seedToTime.Add(key, time.Now(), lrucache.DefaultExpiration) == nil {
 		// Seed was not already in cache
-		h.seedToClientIP.Set(key, clientIP, 0)
+		h.seedToClientIP.Set(key, clientIP, lrucache.DefaultExpiration)
 		return true, nil
 	}
 

+ 1 - 1
psiphon/controller.go

@@ -1300,7 +1300,7 @@ func (controller *Controller) Dial(
 		// The server has indicated that the client should make a direct,
 		// untunneled dial. Cache the classification to avoid this round trip in
 		// the immediate future.
-		untunneledCache.Add(splitTunnelHost, true, 0)
+		untunneledCache.Add(splitTunnelHost, true, lrucache.DefaultExpiration)
 	}
 
 	NoticeUntunneled(splitTunnelHost)

+ 5 - 1
psiphon/server/replay.go

@@ -74,10 +74,14 @@ type replayParameters struct {
 
 // NewReplayCache creates a new ReplayCache.
 func NewReplayCache(support *SupportServices) *ReplayCache {
+	// Cache TTL may vary based on tactics filtering, so each cache.Add must set
+	// the entry TTL.
 	return &ReplayCache{
 		support: support,
 		cache: lrucache.NewWithLRU(
-			0, REPLAY_CACHE_CLEANUP_INTERVAL, REPLAY_CACHE_MAX_ENTRIES),
+			lrucache.NoExpiration,
+			REPLAY_CACHE_CLEANUP_INTERVAL,
+			REPLAY_CACHE_MAX_ENTRIES),
 		metrics: &replayCacheMetrics{},
 	}
 }