Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publisher: cache by both URI and pubkey #7893

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions publisher/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,28 @@ 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
// verifier for the given uri & base64 public key.
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
Expand All @@ -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
}

Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion publisher/publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading