in pulsar/key_shared_policy.go [80:107]
func validateHashRanges(hashRanges []int) error {
sz := len(hashRanges)
if sz == 0 || sz%2 != 0 {
return fmt.Errorf("ranges must not be empty or not in value pairs")
}
var x1, x2, y1, y2 int
//check that the ranges are well-formed
for i := 0; i < sz; i += 2 {
x1, x2 = hashRanges[i], hashRanges[i+1]
if x1 >= x2 || x1 < 0 || x2 > 65535 {
return fmt.Errorf("ranges must be in [0, 65535], but provided range is, %d - %d", x1, x2)
}
}
//loop again for checking range overlap
for i := 0; i < sz; i += 2 {
x1, x2 = hashRanges[i], hashRanges[i+1]
for j := 0; j < sz; j += 2 {
if j == i {
continue
}
y1, y2 = hashRanges[j], hashRanges[j+1]
if x1 <= y2 && y1 <= x2 {
return fmt.Errorf("ranges with overlap between, %d - %d, and %d - %d", x1, x2, y1, y2)
}
}
}
return nil
}