Skip to content

Commit

Permalink
Proof of concept: Namecoin Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
llopv committed May 25, 2017
1 parent 4cf046c commit c206f41
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions namesys/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"errors"
"net"
"strings"
"io/ioutil"
"net/http"
"encoding/json"

path "github.com/ipfs/go-ipfs/path"

Expand Down Expand Up @@ -58,6 +61,41 @@ func (r *DNSResolver) resolveOnce(ctx context.Context, name string) (path.Path,
}
log.Infof("DNSResolver resolving %s", domain)

if strings.HasSuffix(domain, ".bit") {
domain := strings.TrimSuffix(domain, ".bit")
res, err := http.Get("http://localhost:8336/rest/name/d/" + domain + ".json")
if err != nil {
return "", errors.New("Namecoin not connected")
}
body, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return "", errors.New("Namecoin not responding")
}

type Data struct {
Value string
}
type Value struct {
Ipfs string
}
var m Data
var n Value

err = json.Unmarshal([]byte(body), &m)
err = json.Unmarshal([]byte(m.Value), &n)
if err != nil {
return "", errors.New("Domain name has no ipfs registry")
}
var p = path.FromString(n.Ipfs)

if len(segments) > 1 {
return path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[1])
} else {
return p, nil
}
}

rootChan := make(chan lookupRes, 1)
go workDomain(r, domain, rootChan)

Expand Down

0 comments on commit c206f41

Please sign in to comment.