Skip to content

Commit c206f41

Browse files
committed
Proof of concept: Namecoin Integration
1 parent 4cf046c commit c206f41

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

namesys/dns.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"errors"
66
"net"
77
"strings"
8+
"io/ioutil"
9+
"net/http"
10+
"encoding/json"
811

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

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

64+
if strings.HasSuffix(domain, ".bit") {
65+
domain := strings.TrimSuffix(domain, ".bit")
66+
res, err := http.Get("http://localhost:8336/rest/name/d/" + domain + ".json")
67+
if err != nil {
68+
return "", errors.New("Namecoin not connected")
69+
}
70+
body, err := ioutil.ReadAll(res.Body)
71+
res.Body.Close()
72+
if err != nil {
73+
return "", errors.New("Namecoin not responding")
74+
}
75+
76+
type Data struct {
77+
Value string
78+
}
79+
type Value struct {
80+
Ipfs string
81+
}
82+
var m Data
83+
var n Value
84+
85+
err = json.Unmarshal([]byte(body), &m)
86+
err = json.Unmarshal([]byte(m.Value), &n)
87+
if err != nil {
88+
return "", errors.New("Domain name has no ipfs registry")
89+
}
90+
var p = path.FromString(n.Ipfs)
91+
92+
if len(segments) > 1 {
93+
return path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[1])
94+
} else {
95+
return p, nil
96+
}
97+
}
98+
6199
rootChan := make(chan lookupRes, 1)
62100
go workDomain(r, domain, rootChan)
63101

0 commit comments

Comments
 (0)