@cryptotaxi247 / kubo / commits / e643f72c8

core/commands/dns: Add 'ipfs dns ...' for resolving DNS references

This lets users resolve (recursively or not) DNS links without pulling in the other protocols. That makes an easier, more isolated target for alternative implemenations, since they don't need to understand IPNS, proquint, etc. to handle these resolutions.

W. Trevor King committed May 7, 2015 at 15:09 UTC e643f72c86f122416131d00f12cb595a23695b6d
2 files changed +84
core/commands/dns.go new
+82
@@ -0,0 +1,82 @@
1 +package commands
2 +
3 +import (
4 + "io"
5 + "strings"
6 +
7 + cmds "github.com/ipfs/go-ipfs/commands"
8 + namesys "github.com/ipfs/go-ipfs/namesys"
9 + util "github.com/ipfs/go-ipfs/util"
10 +)
11 +
12 +var DNSCmd = &cmds.Command{
13 + Helptext: cmds.HelpText{
14 + Tagline: "DNS link resolver",
15 + ShortDescription: `
16 +Multihashes are hard to remember, but domain names are usually easy to
17 +remember. To create memorable aliases for multihashes, DNS TXT
18 +records can point to other DNS links, IPFS objects, IPNS keys, etc.
19 +This command resolves those links to the referenced object.
20 +`,
21 + LongDescription: `
22 +Multihashes are hard to remember, but domain names are usually easy to
23 +remember. To create memorable aliases for multihashes, DNS TXT
24 +records can point to other DNS links, IPFS objects, IPNS keys, etc.
25 +This command resolves those links to the referenced object.
26 +
27 +For example, with this DNS TXT record:
28 +
29 + ipfs.io. TXT "dnslink=/ipfs/QmRzTuh2Lpuz7Gr39stNr6mTFdqAghsZec1JoUnfySUzcy ..."
30 +
31 +The resolver will give:
32 +
33 + > ipfs dns ipfs.io
34 + /ipfs/QmRzTuh2Lpuz7Gr39stNr6mTFdqAghsZec1JoUnfySUzcy
35 +
36 +And with this DNS TXT record:
37 +
38 + ipfs.ipfs.io. TXT "dnslink=/dns/ipfs.io ..."
39 +
40 +The resolver will give:
41 +
42 + > ipfs dns ipfs.io
43 + /dns/ipfs.io
44 + > ipfs dns --recursive
45 + /ipfs/QmRzTuh2Lpuz7Gr39stNr6mTFdqAghsZec1JoUnfySUzcy
46 +`,
47 + },
48 +
49 + Arguments: []cmds.Argument{
50 + cmds.StringArg("domain-name", true, false, "The domain-name name to resolve.").EnableStdin(),
51 + },
52 + Options: []cmds.Option{
53 + cmds.BoolOption("recursive", "r", "Resolve until the result is not a DNS link"),
54 + },
55 + Run: func(req cmds.Request, res cmds.Response) {
56 +
57 + recursive, _, _ := req.Option("recursive").Bool()
58 + name := req.Arguments()[0]
59 + var resolver namesys.DNSResolver
60 +
61 + depth := 1
62 + if recursive {
63 + depth = namesys.DefaultDepthLimit
64 + }
65 + output, err := resolver.ResolveN(req.Context().Context, name, depth)
66 + if err != nil {
67 + res.SetError(err, cmds.ErrNormal)
68 + return
69 + }
70 + res.SetOutput(&ResolvedPath{output})
71 + },
72 + Marshalers: cmds.MarshalerMap{
73 + cmds.Text: func(res cmds.Response) (io.Reader, error) {
74 + output, ok := res.Output().(*ResolvedPath)
75 + if !ok {
76 + return nil, util.ErrCast()
77 + }
78 + return strings.NewReader(output.Path.String()), nil
79 + },
80 + },
81 + Type: ResolvedPath{},
82 +}
core/commands/root.go
+2
@@ -41,6 +41,7 @@ ADVANCED COMMANDS
41 daemon Start a long-running daemon process
42 mount Mount an ipfs read-only mountpoint
43 name Publish or resolve IPNS names
44 + dns Resolve DNS links
45 pin Pin objects to local storage
46 repo gc Garbage collect unpinned objects
47
@@ -84,6 +85,7 @@ var rootSubcommands = map[string]*cmds.Command{
85 "config": ConfigCmd,
86 "dht": DhtCmd,
87 "diag": DiagCmd,
88 + "dns": DNSCmd,
89 "get": GetCmd,
90 "id": IDCmd,
91 "log": LogCmd,