2020-08-17 21:24:49 +00:00
|
|
|
package dns
|
|
|
|
|
2021-07-19 22:22:51 +00:00
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"regexp"
|
|
|
|
)
|
2020-08-17 21:24:49 +00:00
|
|
|
|
|
|
|
// MaxLabelLength is the maximum length for a name that can be used in DNS.
|
|
|
|
const MaxLabelLength = 63
|
|
|
|
|
|
|
|
// InvalidNameRe is a regex that matches characters which can not be included in
|
|
|
|
// a DNS name.
|
|
|
|
var InvalidNameRe = regexp.MustCompile(`[^A-Za-z0-9\\-]+`)
|
2021-07-19 22:22:51 +00:00
|
|
|
|
|
|
|
type RecursorStrategy string
|
|
|
|
|
|
|
|
const (
|
|
|
|
RecursorStrategySequential RecursorStrategy = "sequential"
|
|
|
|
RecursorStrategyRandom RecursorStrategy = "random"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s RecursorStrategy) Indexes(max int) []int {
|
|
|
|
switch s {
|
|
|
|
case RecursorStrategyRandom:
|
|
|
|
return rand.Perm(max)
|
|
|
|
default:
|
|
|
|
idxs := make([]int, max)
|
|
|
|
for i := range idxs {
|
|
|
|
idxs[i] = i
|
|
|
|
}
|
|
|
|
return idxs
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|