Skip to content

Commit 5a8dd0e

Browse files
oxzijulianbrost
authored andcommitted
config: NoRulesVersion for initial comparisons
Change the rule version string for empty or no rules from the wayward "N/A" string to an empty string. Doing so lets comparisons with an empty rule version evaluate to true, which conveniently reduces the amount of rule exchanges between a source and this daemon on a clean setup. In addition, explicitly set the version to NoRulesVersion. This was also done in Listener.writeSourceRulesInfo, even if this now has no real effect. However, before this method returned an empty string version, while the rule comparison expected "N/A", resulting in rejected submissions.
1 parent 6376947 commit 5a8dd0e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

internal/config/runtime.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ func (r *RuntimeConfig) GetRuleEscalation(escalationID int64) *rule.Escalation {
164164
return nil
165165
}
166166

167-
const MissingRuleVersion = "N/A"
167+
// NoRulesVersion is a source.RulesInfo version implying that no rules are available for this source.
168+
//
169+
// Setting this to the empty string lets comparisons with an empty rule version evaluate to true, which conveniently
170+
// reduces the amount of rule exchanges between a source and this daemon on a clean setup.
171+
const NoRulesVersion = ""
168172

169173
// GetRulesVersionFor retrieves the version of the rules for a specific source.
170174
//
171-
// If either no rules or no rule for this source exist, MissingRuleVersion is returned.
175+
// If either no rules or no rule for this source exist, NoRulesVersion is returned.
172176
//
173177
// May not be called while holding the write lock on the RuntimeConfig.
174178
func (r *RuntimeConfig) GetRulesVersionFor(srcId int64) string {
@@ -181,7 +185,7 @@ func (r *RuntimeConfig) GetRulesVersionFor(srcId int64) string {
181185
}
182186
}
183187

184-
return MissingRuleVersion
188+
return NoRulesVersion
185189
}
186190

187191
// GetContact returns *recipient.Contact by the given username (case-insensitive).

internal/listener/listener.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ func (l *Listener) DumpRules(w http.ResponseWriter, r *http.Request) {
306306
//
307307
// Internally, it converts the data to [baseSource.RulesInfo], being serialized JSON-encoded.
308308
func (l *Listener) writeSourceRulesInfo(w http.ResponseWriter, source *config.Source) {
309-
var rulesInfo baseSource.RulesInfo
309+
rulesInfo := baseSource.RulesInfo{
310+
Version: config.NoRulesVersion,
311+
}
310312

311313
func() { // Use a function to ensure that the RLock and RUnlock are called before writing the response.
312314
l.runtimeConfig.RLock()

0 commit comments

Comments
 (0)