Add plumbing for stream isolation

The stream ID is not yet passed to namecoind.
pull/97/head
JeremyRand 5 years ago
parent 54d7d303be
commit ed8fa682eb
No known key found for this signature in database
GPG Key ID: B3F2D165786D6570

@ -2,7 +2,7 @@ package backend
import "github.com/miekg/dns" import "github.com/miekg/dns"
import "github.com/golang/groupcache/lru" import "github.com/golang/groupcache/lru"
import "gopkg.in/hlandau/madns.v1/merr" import "gopkg.in/hlandau/madns.v2/merr"
import "github.com/namecoin/ncdns/namecoin" import "github.com/namecoin/ncdns/namecoin"
import "github.com/namecoin/ncdns/util" import "github.com/namecoin/ncdns/util"
import "github.com/namecoin/ncdns/ncdomain" import "github.com/namecoin/ncdns/ncdomain"
@ -109,7 +109,7 @@ func convertEmail(email string) (string, error) {
// Do low-level queries against an abstract zone file. This is the per-query // Do low-level queries against an abstract zone file. This is the per-query
// entrypoint from madns. // entrypoint from madns.
func (b *Backend) Lookup(qname string) (rrs []dns.RR, err error) { func (b *Backend) Lookup(qname, streamIsolationID string) (rrs []dns.RR, err error) {
err = lookupReadyError() err = lookupReadyError()
if err != nil { if err != nil {
return return
@ -118,6 +118,7 @@ func (b *Backend) Lookup(qname string) (rrs []dns.RR, err error) {
btx := &btx{} btx := &btx{}
btx.b = b btx.b = b
btx.qname = qname btx.qname = qname
btx.streamIsolationID = streamIsolationID
return btx.Do() return btx.Do()
} }
@ -126,6 +127,8 @@ type btx struct {
b *Backend b *Backend
qname string qname string
streamIsolationID string
subname, basename, rootname string subname, basename, rootname string
} }
@ -269,7 +272,7 @@ func (tx *btx) doUserDomain() (rrs []dns.RR, err error) {
return return
} }
d, err := tx.b.getNamecoinEntry(ncname) d, err := tx.b.getNamecoinEntry(ncname, tx.streamIsolationID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -287,13 +290,13 @@ type domain struct {
ncv *ncdomain.Value ncv *ncdomain.Value
} }
func (b *Backend) getNamecoinEntry(name string) (*domain, error) { func (b *Backend) getNamecoinEntry(name, streamIsolationID string) (*domain, error) {
d := b.getNamecoinEntryCache(name) d := b.getNamecoinEntryCache(name)
if d != nil { if d != nil {
return d, nil return d, nil
} }
d, err := b.getNamecoinEntryLL(name) d, err := b.getNamecoinEntryLL(name, streamIsolationID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -321,13 +324,13 @@ func (b *Backend) addNamecoinEntryToCache(name string, d *domain) {
b.cache.Add(name, d) b.cache.Add(name, d)
} }
func (b *Backend) getNamecoinEntryLL(name string) (*domain, error) { func (b *Backend) getNamecoinEntryLL(name, streamIsolationID string) (*domain, error) {
v, err := b.resolveName(name) v, err := b.resolveName(name, streamIsolationID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
d, err := b.jsonToDomain(name, v) d, err := b.jsonToDomain(name, v, streamIsolationID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -335,7 +338,7 @@ func (b *Backend) getNamecoinEntryLL(name string) (*domain, error) {
return d, nil return d, nil
} }
func (b *Backend) resolveName(name string) (jsonValue string, err error) { func (b *Backend) resolveName(name, streamIsolationID string) (jsonValue string, err error) {
if fv, ok := b.cfg.FakeNames[name]; ok { if fv, ok := b.cfg.FakeNames[name]; ok {
if fv == "NX" { if fv == "NX" {
return "", merr.ErrNoSuchDomain return "", merr.ErrNoSuchDomain
@ -349,7 +352,7 @@ func (b *Backend) resolveName(name string) (jsonValue string, err error) {
// Namecoin JSON-RPC seem sluggish sometimes. // Namecoin JSON-RPC seem sluggish sometimes.
result := make(chan struct{}, 1) result := make(chan struct{}, 1)
go func() { go func() {
jsonValue, err = b.nc.Query(name) jsonValue, err = b.nc.Query(name, streamIsolationID)
log.Errore(err, "failed to query namecoin") log.Errore(err, "failed to query namecoin")
result <- struct{}{} result <- struct{}{}
}() }()
@ -362,10 +365,14 @@ func (b *Backend) resolveName(name string) (jsonValue string, err error) {
} }
} }
func (b *Backend) jsonToDomain(name, jsonValue string) (*domain, error) { func (b *Backend) jsonToDomain(name, jsonValue, streamIsolationID string) (*domain, error) {
d := &domain{} d := &domain{}
v := ncdomain.ParseValue(name, jsonValue, b.resolveExtraName, nil) resolveExtraIsolated := func(n string) (string, error) {
return b.resolveExtraName(n, streamIsolationID)
}
v := ncdomain.ParseValue(name, jsonValue, resolveExtraIsolated, nil)
if v == nil { if v == nil {
return nil, fmt.Errorf("couldn't parse value") return nil, fmt.Errorf("couldn't parse value")
} }
@ -375,8 +382,8 @@ func (b *Backend) jsonToDomain(name, jsonValue string) (*domain, error) {
return d, nil return d, nil
} }
func (b *Backend) resolveExtraName(name string) (jsonValue string, err error) { func (b *Backend) resolveExtraName(name, streamIsolationID string) (jsonValue string, err error) {
return b.resolveName(name) return b.resolveName(name, streamIsolationID)
} }
func (tx *btx) doUnderDomain(d *domain) (rrs []dns.RR, err error) { func (tx *btx) doUnderDomain(d *domain) (rrs []dns.RR, err error) {

@ -4,7 +4,7 @@ package namecoin
import ( import (
extratypes "github.com/hlandau/ncbtcjsontypes" extratypes "github.com/hlandau/ncbtcjsontypes"
"github.com/hlandauf/btcjson" "github.com/hlandauf/btcjson"
"gopkg.in/hlandau/madns.v1/merr" "gopkg.in/hlandau/madns.v2/merr"
"expvar" "expvar"
"fmt" "fmt"
@ -57,9 +57,14 @@ func (nc *Conn) rpcSend(cmd btcjson.Cmd) (btcjson.Reply, error) {
// Query the Namecoin daemon for a Namecoin domain (e.g. d/example). // Query the Namecoin daemon for a Namecoin domain (e.g. d/example).
// If the domain exists, returns the value stored in Namecoin, which should be JSON. // If the domain exists, returns the value stored in Namecoin, which should be JSON.
// Note that this will return domain data even if the domain is expired. // Note that this will return domain data even if the domain is expired.
func (nc *Conn) Query(name string) (v string, err error) { func (nc *Conn) Query(name string, streamIsolationID string) (v string, err error) {
cQueryCalls.Add(1) cQueryCalls.Add(1)
// TODO: Pass stream isolation ID to namecoind, and remove this error
if streamIsolationID != "" {
return "", fmt.Errorf("Stream isolation ID '%s' is not yet passed to namecoind", streamIsolationID)
}
cmd, err := extratypes.NewNameShowCmd(newID(), name) cmd, err := extratypes.NewNameShowCmd(newID(), name)
if err != nil { if err != nil {
//log.Info("NC NEWCMD ", err) //log.Info("NC NEWCMD ", err)

@ -41,7 +41,7 @@ func translateValue(k, v string) (string, error) {
f = os.NewFile(uintptr(n), "-") f = os.NewFile(uintptr(n), "-")
} else if len(v) == 1 { } else if len(v) == 1 {
return conn.Query(k) return conn.Query(k, "")
} else { } else {
f, err = os.Open(v) f, err = os.Open(v)
} }

@ -55,7 +55,7 @@ func dumpName(item *extratypes.NameFilterItem, conn namecoin.Conn,
} }
getNameFunc := func(k string) (string, error) { getNameFunc := func(k string) (string, error) {
return conn.Query(k) return conn.Query(k, "")
} }
var errors []error var errors []error

@ -14,7 +14,7 @@ import (
"github.com/miekg/dns" "github.com/miekg/dns"
"github.com/namecoin/ncdns/backend" "github.com/namecoin/ncdns/backend"
"github.com/namecoin/ncdns/namecoin" "github.com/namecoin/ncdns/namecoin"
"gopkg.in/hlandau/madns.v1" "gopkg.in/hlandau/madns.v2"
) )
var log, Log = xlog.New("ncdns.server") var log, Log = xlog.New("ncdns.server")

@ -140,7 +140,7 @@ func (ws *webServer) handleLookup(rw http.ResponseWriter, req *http.Request) {
info.JSONValue = req.FormValue("value") info.JSONValue = req.FormValue("value")
info.Value = strings.Trim(info.JSONValue, " \t\r\n") info.Value = strings.Trim(info.JSONValue, " \t\r\n")
if info.Value == "" { if info.Value == "" {
info.Value, info.ExistenceError = ws.s.namecoinConn.Query(info.NamecoinName) info.Value, info.ExistenceError = ws.s.namecoinConn.Query(info.NamecoinName, "")
if info.ExistenceError != nil { if info.ExistenceError != nil {
return return
} }
@ -170,7 +170,7 @@ func (ws *webServer) handleLookup(rw http.ResponseWriter, req *http.Request) {
} }
func (ws *webServer) resolveFunc(name string) (string, error) { func (ws *webServer) resolveFunc(name string) (string, error) {
return ws.s.namecoinConn.Query(name) return ws.s.namecoinConn.Query(name, "")
} }
func (ws *webServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { func (ws *webServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {

@ -1,7 +1,7 @@
package util package util
import "strings" import "strings"
import "gopkg.in/hlandau/madns.v1/merr" import "gopkg.in/hlandau/madns.v2/merr"
import "fmt" import "fmt"
import "regexp" import "regexp"
import "net/mail" import "net/mail"

@ -2,7 +2,7 @@ package util_test
import "testing" import "testing"
import "github.com/namecoin/ncdns/util" import "github.com/namecoin/ncdns/util"
import "gopkg.in/hlandau/madns.v1/merr" import "gopkg.in/hlandau/madns.v2/merr"
type item struct { type item struct {
input string input string

Loading…
Cancel
Save