@@ -52,12 +52,12 @@ type groupState struct {
5252// When some group is complete cancels all requests that are not needed by any
5353// group.
5454type safeSubmissionState struct {
55- mu sync.Mutex
56- logToGroups map [string ]ctpolicy.GroupSet
57- groupNeeds map [string ]int // number of logs that need to be submitted for each group.
58- maxSubmissionsPerGroup int // maximum number of logs that can be submitted to a group.
55+ mu sync.Mutex
56+ logToGroups map [string ]ctpolicy.GroupSet
57+ groupNeeds map [string ]int // number of logs that need to be submitted for each group.
58+ minDistinctGroups int // number of groups that need a submission
5959
60- groups map [string ]int // number of logs submitted to each group..
60+ groups map [string ]bool // groups that have a stored result
6161 results map [string ]* submissionResult
6262 cancels map [string ]context.CancelFunc
6363}
@@ -70,9 +70,9 @@ func newSafeSubmissionState(groups ctpolicy.LogPolicyData) *safeSubmissionState
7070 s .groupNeeds [g .Name ] = g .MinInclusions
7171 }
7272 if baseGroup , ok := groups [ctpolicy .BaseName ]; ok {
73- s .maxSubmissionsPerGroup = baseGroup .MaxSubmissionsPerOperator
73+ s .minDistinctGroups = baseGroup .MinDistinctOperators
7474 }
75- s .groups = make (map [string ]int )
75+ s .groups = make (map [string ]bool )
7676 s .results = make (map [string ]* submissionResult )
7777 s .cancels = make (map [string ]context.CancelFunc )
7878 return & s
@@ -90,10 +90,6 @@ func (sub *safeSubmissionState) request(logURL string, cancel context.CancelFunc
9090 sub .results [logURL ] = & submissionResult {}
9191 isAwaited := false
9292 for g := range sub .logToGroups [logURL ] {
93- if g != ctpolicy .BaseName && sub .groups [g ] < sub .maxSubmissionsPerGroup {
94- isAwaited = true
95- break
96- }
9793 if sub .groupNeeds [g ] > 0 {
9894 isAwaited = true
9995 break
@@ -119,21 +115,21 @@ func (sub *safeSubmissionState) setResult(logURL string, sct *ct.SignedCertifica
119115 }
120116 // group name associated with logURL outside of BaseName.
121117 // (this assumes the logURL is associated with only one group ignoring BaseName)
122- var nonBaseGroupName string
123118 // If at least one group needs that SCT, result is set. Otherwise dumped.
124119 for groupName := range sub .logToGroups [logURL ] {
125120 // Ignore the base group (All-logs) here to check separately.
126121 if groupName == ctpolicy .BaseName {
127122 continue
128123 }
129- nonBaseGroupName = groupName
130- if sub .groups [groupName ] < sub . maxSubmissionsPerGroup {
124+ // Set the result if the group does not have a submission.
125+ if ! sub .groups [groupName ] {
131126 sub .results [logURL ] = & submissionResult {sct : sct , err : err }
127+ sub .groups [groupName ] = true
132128 }
133129 if sub .groupNeeds [groupName ] > 0 {
134130 sub .results [logURL ] = & submissionResult {sct : sct , err : err }
131+ sub .groups [groupName ] = true
135132 }
136- sub .groups [groupName ]++
137133 sub .groupNeeds [groupName ]--
138134 }
139135
@@ -143,19 +139,12 @@ func (sub *safeSubmissionState) setResult(logURL string, sct *ct.SignedCertifica
143139 // It is already processed in a non-base group, so we can reduce the groupNeeds for the base group as well.
144140 sub .groupNeeds [ctpolicy .BaseName ]--
145141 } else if sub .groupNeeds [ctpolicy .BaseName ] > 0 {
146- minInclusionsForOtherGroup := 0
147- for g , cnt := range sub .groupNeeds {
148- if g != ctpolicy .BaseName && cnt > 0 {
149- minInclusionsForOtherGroup += cnt
150- }
151- }
142+ extraSubmissions := sub .minDistinctGroups - len (sub .groups )
152143 // Set the result only if the base group still needs SCTs more than total counts
153144 // of minimum inclusions for other groups.
154- if sub .groupNeeds [ctpolicy .BaseName ] > minInclusionsForOtherGroup {
155- if sub .groups [nonBaseGroupName ] < sub .maxSubmissionsPerGroup {
156- sub .results [logURL ] = & submissionResult {sct : sct , err : err }
157- sub .groupNeeds [ctpolicy .BaseName ]--
158- }
145+ if sub .groupNeeds [ctpolicy .BaseName ] > extraSubmissions {
146+ sub .results [logURL ] = & submissionResult {sct : sct , err : err }
147+ sub .groupNeeds [ctpolicy .BaseName ]--
159148 }
160149 }
161150 }
@@ -165,10 +154,6 @@ func (sub *safeSubmissionState) setResult(logURL string, sct *ct.SignedCertifica
165154 for logURL , groupSet := range sub .logToGroups {
166155 isAwaited := false
167156 for g := range groupSet {
168- if g != ctpolicy .BaseName && sub .groups [g ] < sub .maxSubmissionsPerGroup {
169- isAwaited = true
170- break
171- }
172157 if sub .groupNeeds [g ] > 0 {
173158 isAwaited = true
174159 break
@@ -189,10 +174,8 @@ func (sub *safeSubmissionState) groupComplete(groupName string) bool {
189174 if ! ok {
190175 return true
191176 }
192- for _ , submission := range sub .groups {
193- if submission < sub .maxSubmissionsPerGroup {
194- return false
195- }
177+ if len (sub .groups ) < sub .minDistinctGroups {
178+ return false
196179 }
197180 return needs <= 0
198181}
0 commit comments