From 539bc890129a7ff79f93749296073c125993439d Mon Sep 17 00:00:00 2001 From: JeremyRand Date: Sun, 27 Oct 2019 19:37:29 +0000 Subject: [PATCH] ncdumpzone: Work around encoding errors Namecoin Core 0.18.0+ now reports an empty Name with a non-empty NameError when an encoding error was encountered. This was causing an infinite loop in ncdumpzone. Fixes https://github.com/namecoin/ncdns/issues/105 --- ncdumpzone/ncdumpzone.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/ncdumpzone/ncdumpzone.go b/ncdumpzone/ncdumpzone.go index 0b5329a..ccb8fe8 100644 --- a/ncdumpzone/ncdumpzone.go +++ b/ncdumpzone/ncdumpzone.go @@ -18,7 +18,7 @@ import ( var log, Log = xlog.New("ncdumpzone") -const perCall = 1000 +const defaultPerCall uint32 = 1000 func dumpRR(rr dns.RR, dest io.Writer, format string) error { switch format { @@ -91,6 +91,7 @@ func Dump(conn *namecoin.Client, dest io.Writer, format string) error { currentName := "d/" continuing := 0 + perCall := defaultPerCall for { results, err := conn.NameScan(currentName, perCall) @@ -110,6 +111,33 @@ func Dump(conn *namecoin.Client, dest io.Writer, format string) error { continuing = 1 } + // Temporary hack to fix + // https://github.com/namecoin/ncdns/issues/105 + // TODO: Replace this hack with hex encoding after Namecoin + // Core 0.18.0+ is ubiquitous. + lenResults := len(results) + for results[len(results)-1].NameError != "" { + results = results[:len(results)-1] + + if len(results) == 0 { + break + } + } + // Edge case: if all of the results had a NameError, + // then try to get more results at once. + if len(results) == 0 { + // All of the results had a nameError but we're + // at the end of the results, so not a problem. + if lenResults < int(perCall)-1 { + log.Info("out of results, stopping") + break + } + + log.Warnf("All %d results (start point %s) had a NameError", lenResults, currentName) + perCall *= 2 + continue + } + for i := range results { r := &results[i]