Jelajahi Sumber

Add comments for GeoIP session cache.

Rod Hynes 9 tahun lalu
induk
melakukan
c55858c450
1 mengubah file dengan 7 tambahan dan 3 penghapusan
  1. 7 3
      psiphon/server/geoip.go

+ 7 - 3
psiphon/server/geoip.go

@@ -176,7 +176,8 @@ func (geoIP *GeoIPService) Lookup(ipAddress string) GeoIPData {
 }
 
 func (geoIP *GeoIPService) SetSessionCache(sessionID string, geoIPData GeoIPData) {
-	geoIP.sessionCache.Add(sessionID, geoIPData, cache.DefaultExpiration)
+	// Ignore errors. If this fails, related logs will not have Geo IP data.
+	_ = geoIP.sessionCache.Set(sessionID, geoIPData, cache.DefaultExpiration)
 }
 
 func (geoIP *GeoIPService) GetSessionCache(
@@ -185,8 +186,11 @@ func (geoIP *GeoIPService) GetSessionCache(
 	if !found {
 		return NewGeoIPData()
 	}
-	// Extend the TTL for this item
-	geoIP.sessionCache.Replace(sessionID, geoIPData, cache.DefaultExpiration)
+	// Extend the TTL for this item. If this fails, the cache entry
+	// value remains the same but the TTL is not extended.
+	// Note: sessionCache.Replace can clobber sessionCache.Set changes,
+	// but this is not a concern in practise.
+	_ = geoIP.sessionCache.Replace(sessionID, geoIPData, cache.DefaultExpiration)
 	return geoIPData.(GeoIPData)
 }