when parsing a source, try to process all of the servers to ensure maximum connectivity
- a corrupt source (no names/descriptions) will still abort parsing immediately - a duplicate, missing or invalid server stamp will not abort parsing - these errors are logged as warnings, and returned as a single error at the end
This commit is contained in:
parent
6513818cb3
commit
99e56a400f
|
@ -217,12 +217,19 @@ func (source *Source) Parse(prefix string) ([]RegisteredServer, error) {
|
||||||
|
|
||||||
func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) {
|
func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) {
|
||||||
var registeredServers []RegisteredServer
|
var registeredServers []RegisteredServer
|
||||||
|
var stampErrs []string
|
||||||
|
appendStampErr := func(format string, a ...interface{}) {
|
||||||
|
stampErr := fmt.Sprintf(format, a...)
|
||||||
|
stampErrs = append(stampErrs, stampErr)
|
||||||
|
dlog.Warn(stampErr)
|
||||||
|
}
|
||||||
in := string(source.in)
|
in := string(source.in)
|
||||||
parts := strings.Split(in, "## ")
|
parts := strings.Split(in, "## ")
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
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")
|
||||||
|
@ -240,7 +247,8 @@ func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) {
|
||||||
subpart = strings.TrimFunc(subpart, unicode.IsSpace)
|
subpart = strings.TrimFunc(subpart, unicode.IsSpace)
|
||||||
if strings.HasPrefix(subpart, "sdns:") {
|
if strings.HasPrefix(subpart, "sdns:") {
|
||||||
if len(stampStr) > 0 {
|
if len(stampStr) > 0 {
|
||||||
return registeredServers, fmt.Errorf("Multiple stamps for server [%s] in source from [%v]", name, source.urls)
|
appendStampErr("Multiple stamps for server [%s]", name)
|
||||||
|
continue PartsLoop
|
||||||
}
|
}
|
||||||
stampStr = subpart
|
stampStr = subpart
|
||||||
continue
|
continue
|
||||||
|
@ -253,12 +261,13 @@ func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) {
|
||||||
description += subpart
|
description += subpart
|
||||||
}
|
}
|
||||||
if len(stampStr) < 6 {
|
if len(stampStr) < 6 {
|
||||||
return registeredServers, fmt.Errorf("Missing stamp for server [%s] in source from [%v]", name, source.urls)
|
appendStampErr("Missing stamp for server [%s]", name)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
stamp, err := stamps.NewServerStampFromString(stampStr)
|
stamp, err := stamps.NewServerStampFromString(stampStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dlog.Errorf("Invalid or unsupported stamp: [%v]", stampStr)
|
appendStampErr("Invalid or unsupported stamp [%v]: %s", stampStr, err.Error())
|
||||||
return registeredServers, err
|
continue
|
||||||
}
|
}
|
||||||
registeredServer := RegisteredServer{
|
registeredServer := RegisteredServer{
|
||||||
name: name, stamp: stamp, description: description,
|
name: name, stamp: stamp, description: description,
|
||||||
|
@ -266,6 +275,9 @@ func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) {
|
||||||
dlog.Debugf("Registered [%s] with stamp [%s]", name, stamp.String())
|
dlog.Debugf("Registered [%s] with stamp [%s]", name, stamp.String())
|
||||||
registeredServers = append(registeredServers, registeredServer)
|
registeredServers = append(registeredServers, registeredServer)
|
||||||
}
|
}
|
||||||
|
if len(stampErrs) > 0 {
|
||||||
|
return registeredServers, fmt.Errorf("%s", strings.Join(stampErrs, ", "))
|
||||||
|
}
|
||||||
return registeredServers, nil
|
return registeredServers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue