Skip to content

Commit a3af521

Browse files
committed
refactor: use rwlock on urlMap
1 parent e115021 commit a3af521

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

internal/certificatetransparency/ct-watcher.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ import (
2323
var (
2424
processedCerts int64
2525
processedPrecerts int64
26-
urlMapMutex sync.Mutex
26+
urlMapMutex sync.RWMutex
2727
urlMap = make(map[string]int64)
28-
ownerMapMutex sync.Mutex
29-
ownerMap = make(map[string]int64)
3028
)
3129

3230
func GetProcessedCerts() int64 {
@@ -38,13 +36,23 @@ func GetProcessedPrecerts() int64 {
3836
}
3937

4038
func GetCertCountForLog(logname string) int64 {
41-
urlMapMutex.Lock()
42-
defer urlMapMutex.Unlock()
39+
urlMapMutex.RLock()
40+
defer urlMapMutex.RUnlock()
4341
return urlMap[logname]
4442
}
4543

46-
func GetLogs() map[string]int64 {
47-
return urlMap
44+
func GetLogs() []string {
45+
urlMapMutex.RLock()
46+
defer urlMapMutex.RUnlock()
47+
48+
urls := make([]string, len(urlMap))
49+
50+
counter := 0
51+
for key := range urlMap {
52+
urls[counter] = key
53+
counter++
54+
}
55+
return urls
4856
}
4957

5058
// Watcher describes a component that watches for new certificates in a CT log.

0 commit comments

Comments
 (0)