From 99e56a400fe0d487edab06d4cac5522ffa25328d Mon Sep 17 00:00:00 2001 From: Alison Winters Date: Sun, 6 Oct 2019 18:14:21 +0800 Subject: [PATCH] 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 --- dnscrypt-proxy/sources.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/dnscrypt-proxy/sources.go b/dnscrypt-proxy/sources.go index f257648a..60c95d14 100644 --- a/dnscrypt-proxy/sources.go +++ b/dnscrypt-proxy/sources.go @@ -217,12 +217,19 @@ func (source *Source) Parse(prefix string) ([]RegisteredServer, error) { func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) { 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) parts := strings.Split(in, "## ") if len(parts) < 2 { return registeredServers, fmt.Errorf("Invalid format for source at [%v]", source.urls) } parts = parts[1:] +PartsLoop: for _, part := range parts { part = strings.TrimFunc(part, unicode.IsSpace) subparts := strings.Split(part, "\n") @@ -240,7 +247,8 @@ func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) { subpart = strings.TrimFunc(subpart, unicode.IsSpace) if strings.HasPrefix(subpart, "sdns:") { 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 continue @@ -253,12 +261,13 @@ func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) { description += subpart } 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) if err != nil { - dlog.Errorf("Invalid or unsupported stamp: [%v]", stampStr) - return registeredServers, err + appendStampErr("Invalid or unsupported stamp [%v]: %s", stampStr, err.Error()) + continue } registeredServer := RegisteredServer{ 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()) registeredServers = append(registeredServers, registeredServer) } + if len(stampErrs) > 0 { + return registeredServers, fmt.Errorf("%s", strings.Join(stampErrs, ", ")) + } return registeredServers, nil }