diff --git a/test/ct-test-srv/main.go b/test/ct-test-srv/main.go index bc413cc2b88..66a13cf42d4 100644 --- a/test/ct-test-srv/main.go +++ b/test/ct-test-srv/main.go @@ -29,7 +29,8 @@ type ctSubmissionRequest struct { type integrationSrv struct { sync.Mutex - submissions map[string]int64 + submissions map[string]int64 + submissionsCap int // Hostnames where we refuse to provide an SCT. This is to exercise the code // path where all CT servers fail. rejectHosts map[string]bool @@ -156,9 +157,7 @@ func (is *integrationSrv) addChainOrPre(w http.ResponseWriter, r *http.Request, } } - is.Lock() - is.submissions[hostnames]++ - is.Unlock() + is.addSubmission(hostnames) if is.flakinessRate != 0 && rand.IntN(100) < is.flakinessRate { time.Sleep(10 * time.Second) @@ -168,6 +167,16 @@ func (is *integrationSrv) addChainOrPre(w http.ResponseWriter, r *http.Request, w.Write(publisher.CreateTestingSignedSCT(addChainReq.Chain, is.key, precert, time.Now())) } +func (is *integrationSrv) addSubmission(hostnames string) { + is.Lock() + defer is.Unlock() + + _, ok := is.submissions[hostnames] + if ok || len(is.submissions) < is.submissionsCap { + is.submissions[hostnames]++ + } +} + func (is *integrationSrv) getSubmissions(w http.ResponseWriter, r *http.Request) { if r.Method != "GET" { http.NotFound(w, r) @@ -199,6 +208,9 @@ type Personality struct { // FlakinessRate is an integer between 0-100 that controls how often the log // "flakes", i.e. fails to respond in a reasonable time frame. FlakinessRate int + // SubmissionsCap limits the number of hostnames we track. Defaults to 1 million. + // After that many entries, new hostnames won't be counted in /submissions. + SubmissionsCap int } func runPersonality(p Personality) { @@ -210,12 +222,17 @@ func runPersonality(p Personality) { if err != nil { log.Fatal(err) } + cap := p.SubmissionsCap + if cap == 0 { + cap = 1_000_000 + } is := integrationSrv{ - key: key, - flakinessRate: p.FlakinessRate, - submissions: make(map[string]int64), - rejectHosts: make(map[string]bool), - userAgent: p.UserAgent, + key: key, + flakinessRate: p.FlakinessRate, + submissions: make(map[string]int64), + submissionsCap: cap, + rejectHosts: make(map[string]bool), + userAgent: p.UserAgent, } m := http.NewServeMux() m.HandleFunc("/submissions", is.getSubmissions)