Skip to content

Commit

Permalink
ncdumpzone: Work around encoding errors
Browse files Browse the repository at this point in the history
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 #105
  • Loading branch information
JeremyRand committed Oct 27, 2019
1 parent 96d897a commit 539bc89
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion ncdumpzone/ncdumpzone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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]

Expand Down

0 comments on commit 539bc89

Please sign in to comment.