Skip to content

Commit

Permalink
Merge #106: Fix infinite loop in ncdumpzone with Namecoin Core 0.18.0+
Browse files Browse the repository at this point in the history
539bc89 ncdumpzone: Work around encoding errors (JeremyRand)

Pull request description:

  Fixes #105

  TODO:

  - [x] Merge #103 (this PR will then need a rebase)

ACKs for commit 539bc8:

Tree-SHA512: 5762687077ea2611cd7939dd49d337346b212a91442b32f7be5ac592e2580029bc0e63c4e6597b2685495de59a431fe422048fc3a1f0d52fb678e377eb947401
  • Loading branch information
JeremyRand committed Oct 28, 2019
2 parents 96d897a + 539bc89 commit 7c39b77
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 7c39b77

Please sign in to comment.