diff --git a/publisher/publisher.go b/publisher/publisher.go index 3d377c69891..d006787a3d1 100644 --- a/publisher/publisher.go +++ b/publisher/publisher.go @@ -39,11 +39,20 @@ type Log struct { client *ctClient.LogClient } +// cacheKey is a comparable type for use as a key within a logCache. It holds +// both the log URI and its log_id (base64 encoding of its pubkey), so that +// the cache won't interfere if the RA decides that a log's URI or pubkey has +// changed. +type cacheKey struct { + uri string + pubkey string +} + // logCache contains a cache of *Log's that are constructed as required by // `SubmitToSingleCT` type logCache struct { sync.RWMutex - logs map[string]*Log + logs map[cacheKey]*Log } // AddLog adds a *Log to the cache by constructing the statName, client and @@ -51,7 +60,7 @@ type logCache struct { func (c *logCache) AddLog(uri, b64PK, userAgent string, logger blog.Logger) (*Log, error) { // Lock the mutex for reading to check the cache c.RLock() - log, present := c.logs[b64PK] + log, present := c.logs[cacheKey{uri, b64PK}] c.RUnlock() // If we have already added this log, give it back @@ -68,7 +77,7 @@ func (c *logCache) AddLog(uri, b64PK, userAgent string, logger blog.Logger) (*Lo if err != nil { return nil, err } - c.logs[b64PK] = log + c.logs[cacheKey{uri, b64PK}] = log return log, nil } @@ -218,7 +227,7 @@ func New( issuerBundles: bundles, userAgent: userAgent, ctLogsCache: logCache{ - logs: make(map[string]*Log), + logs: make(map[cacheKey]*Log), }, log: logger, metrics: initMetrics(stats), diff --git a/publisher/publisher_test.go b/publisher/publisher_test.go index 3ed5007fcbc..ea02d1cdaee 100644 --- a/publisher/publisher_test.go +++ b/publisher/publisher_test.go @@ -269,7 +269,7 @@ func TestTimestampVerificationPast(t *testing.T) { func TestLogCache(t *testing.T) { cache := logCache{ - logs: make(map[string]*Log), + logs: make(map[cacheKey]*Log), } // Adding a log with an invalid base64 public key should error