Support multiple stamps per resolver
For now, a single stamp is randomly chosen in order to spread the load, but we may eventually want to also use this for failover mechanisms.
This commit is contained in:
parent
b0e883ebc6
commit
68ccd1410f
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -14,6 +15,7 @@ import (
|
||||||
"github.com/dchest/safefile"
|
"github.com/dchest/safefile"
|
||||||
|
|
||||||
"github.com/jedisct1/dlog"
|
"github.com/jedisct1/dlog"
|
||||||
|
"github.com/jedisct1/go-dnsstamps"
|
||||||
stamps "github.com/jedisct1/go-dnsstamps"
|
stamps "github.com/jedisct1/go-dnsstamps"
|
||||||
"github.com/jedisct1/go-minisign"
|
"github.com/jedisct1/go-minisign"
|
||||||
)
|
)
|
||||||
|
@ -244,7 +246,6 @@ func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) {
|
||||||
return registeredServers, fmt.Errorf("Invalid format for source at [%v]", source.urls)
|
return registeredServers, fmt.Errorf("Invalid format for source at [%v]", source.urls)
|
||||||
}
|
}
|
||||||
parts = parts[1:]
|
parts = parts[1:]
|
||||||
PartsLoop:
|
|
||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
part = strings.TrimFunc(part, unicode.IsSpace)
|
part = strings.TrimFunc(part, unicode.IsSpace)
|
||||||
subparts := strings.Split(part, "\n")
|
subparts := strings.Split(part, "\n")
|
||||||
|
@ -258,14 +259,11 @@ PartsLoop:
|
||||||
subparts = subparts[1:]
|
subparts = subparts[1:]
|
||||||
name = prefix + name
|
name = prefix + name
|
||||||
var stampStr, description string
|
var stampStr, description string
|
||||||
|
stampStrs := make([]string, 0)
|
||||||
for _, subpart := range subparts {
|
for _, subpart := range subparts {
|
||||||
subpart = strings.TrimFunc(subpart, unicode.IsSpace)
|
subpart = strings.TrimFunc(subpart, unicode.IsSpace)
|
||||||
if strings.HasPrefix(subpart, "sdns:") {
|
if strings.HasPrefix(subpart, "sdns:") && len(subpart) >= 6 {
|
||||||
if len(stampStr) > 0 {
|
stampStrs = append(stampStrs, subpart)
|
||||||
appendStampErr("Multiple stamps for server [%s]", name)
|
|
||||||
continue PartsLoop
|
|
||||||
}
|
|
||||||
stampStr = subpart
|
|
||||||
continue
|
continue
|
||||||
} else if len(subpart) == 0 || strings.HasPrefix(subpart, "//") {
|
} else if len(subpart) == 0 || strings.HasPrefix(subpart, "//") {
|
||||||
continue
|
continue
|
||||||
|
@ -275,13 +273,23 @@ PartsLoop:
|
||||||
}
|
}
|
||||||
description += subpart
|
description += subpart
|
||||||
}
|
}
|
||||||
if len(stampStr) < 6 {
|
stampStrsLen := len(stampStrs)
|
||||||
|
if stampStrsLen <= 0 {
|
||||||
appendStampErr("Missing stamp for server [%s]", name)
|
appendStampErr("Missing stamp for server [%s]", name)
|
||||||
continue
|
continue
|
||||||
|
} else if stampStrsLen > 1 {
|
||||||
|
rand.Shuffle(stampStrsLen, func(i, j int) { stampStrs[i], stampStrs[j] = stampStrs[j], stampStrs[i] })
|
||||||
}
|
}
|
||||||
stamp, err := stamps.NewServerStampFromString(stampStr)
|
var stamp dnsstamps.ServerStamp
|
||||||
if err != nil {
|
var err error
|
||||||
|
for _, stampStr = range stampStrs {
|
||||||
|
stamp, err = stamps.NewServerStampFromString(stampStr)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
appendStampErr("Invalid or unsupported stamp [%v]: %s", stampStr, err.Error())
|
appendStampErr("Invalid or unsupported stamp [%v]: %s", stampStr, err.Error())
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
registeredServer := RegisteredServer{
|
registeredServer := RegisteredServer{
|
||||||
|
|
Loading…
Reference in New Issue