Merge #106: Fix infinite loop in ncdumpzone with Namecoin Core 0.18.0+

539bc89 ncdumpzone: Work around encoding errors (JeremyRand)

Pull request description:

  Fixes https://github.com/namecoin/ncdns/issues/105

  TODO:

  - [x] Merge https://github.com/namecoin/ncdns/pull/103 (this PR will then need a rebase)

ACKs for commit 539bc8:

Tree-SHA512: 5762687077ea2611cd7939dd49d337346b212a91442b32f7be5ac592e2580029bc0e63c4e6597b2685495de59a431fe422048fc3a1f0d52fb678e377eb947401
pull/129/head
JeremyRand 5 years ago
commit 7c39b77cca
No known key found for this signature in database
GPG Key ID: B3F2D165786D6570

@ -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]

Loading…
Cancel
Save