Sfoglia il codice sorgente

Improve readability: use go-cache-lru constants

Rod Hynes 5 anni fa
parent
commit
c8cefd24ce

+ 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
 	// an unlikely possibility that this Add and the following Get don't see the
 	// same existing key/value state.
 	// 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
 		// Seed was not already in cache
-		h.seedToClientIP.Set(key, clientIP, 0)
+		h.seedToClientIP.Set(key, clientIP, lrucache.DefaultExpiration)
 		return true, nil
 		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,
 		// The server has indicated that the client should make a direct,
 		// untunneled dial. Cache the classification to avoid this round trip in
 		// untunneled dial. Cache the classification to avoid this round trip in
 		// the immediate future.
 		// the immediate future.
-		untunneledCache.Add(splitTunnelHost, true, 0)
+		untunneledCache.Add(splitTunnelHost, true, lrucache.DefaultExpiration)
 	}
 	}
 
 
 	NoticeUntunneled(splitTunnelHost)
 	NoticeUntunneled(splitTunnelHost)

+ 5 - 1
psiphon/server/replay.go

@@ -74,10 +74,14 @@ type replayParameters struct {
 
 
 // NewReplayCache creates a new ReplayCache.
 // NewReplayCache creates a new ReplayCache.
 func NewReplayCache(support *SupportServices) *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{
 	return &ReplayCache{
 		support: support,
 		support: support,
 		cache: lrucache.NewWithLRU(
 		cache: lrucache.NewWithLRU(
-			0, REPLAY_CACHE_CLEANUP_INTERVAL, REPLAY_CACHE_MAX_ENTRIES),
+			lrucache.NoExpiration,
+			REPLAY_CACHE_CLEANUP_INTERVAL,
+			REPLAY_CACHE_MAX_ENTRIES),
 		metrics: &replayCacheMetrics{},
 		metrics: &replayCacheMetrics{},
 	}
 	}
 }
 }