ipfs name cmd improvements
- cleaned up cmd help - ipfs name publish [<name>] <ref> - ipfs name resolve [<name>] - publish validates <ref> - both validate n args
Juan Batiz-Benet committed
Oct 9, 2014 at 03:39 UTC
2fa43ce46c58533d4de5cae8565ba917117211c0
6 files changed
+125
-20
cmd/ipfs/name.go
+37
-5
@@ -8,11 +8,43 @@ import (
8
)
9
10
var cmdIpfsName = &commander.Command{
11
- UsageLine: "name",
12
- Short: "Ipfs namespace manipulation tools.",
13
- Long: `ipfs name [publish|resolve] <ref/hash>`,
14
- Run: addCmd,
15
- Flag: *flag.NewFlagSet("ipfs-name", flag.ExitOnError),
11
+ UsageLine: "name [publish | resolve]",
12
+ Short: "ipfs namespace (ipns) tool",
13
+ Long: `ipfs name - Get/Set ipfs config values.
14
+
15
+ ipfs name publish [<name>] <ref> - Assign the <ref> to <name>
16
+ ipfs name resolve [<name>] - Resolve the <ref> value of <name>
17
+
18
+IPNS is a PKI namespace, where names are the hashes of public keys, and
19
+the private key enables publishing new (signed) values. In both publish
20
+and resolve, the default value of <name> is your own identity public key.
21
+
22
+
23
+Examples:
24
+
25
+Publish a <ref> to your identity name:
26
+
27
+ > ipfs name publish QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
28
+ published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
29
+
30
+Publish a <ref> to another public key:
31
+
32
+ > ipfs name publish QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
33
+ published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
34
+
35
+Resolve the value of your identity:
36
+
37
+ > ipfs name resolve
38
+ QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
39
+
40
+Resolve te value of another name:
41
+
42
+ > ipfs name resolve QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n
43
+ QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
44
+
45
+`,
46
+ Run: addCmd,
47
+ Flag: *flag.NewFlagSet("ipfs-name", flag.ExitOnError),
48
Subcommands: []*commander.Command{
49
cmdIpfsPub,
50
cmdIpfsResolve,
cmd/ipfs/publish.go
+19
-7
@@ -8,22 +8,34 @@ import (
8
9
var cmdIpfsPub = &commander.Command{
10
UsageLine: "publish",
11
- Short: "Publish an object to ipns under your key.",
12
- Long: `ipfs publish <path> - Publish object to ipns.
11
+ Short: "publish a <ref> to ipns.",
12
+ Long: `ipfs publish [<name>] <ref> - publish a <ref> to ipns.
13
+
14
+IPNS is a PKI namespace, where names are the hashes of public keys, and
15
+the private key enables publishing new (signed) values. In publish, the
16
+default value of <name> is your own identity public key.
17
+
18
+Examples:
19
+
20
+Publish a <ref> to your identity name:
21
+
22
+ > ipfs name publish QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
23
+ published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
24
+
25
+Publish a <ref> to another public key:
26
+
27
+ > ipfs name publish QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
28
+ published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
29
30
`,
31
Run: pubCmd,
32
Flag: *flag.NewFlagSet("ipfs-publish", flag.ExitOnError),
33
}
34
19
-func init() {
20
- cmdIpfsPub.Flag.String("k", "", "Specify key to use for publishing.")
21
-}
22
-
35
var pubCmd = makeCommand(command{
36
name: "publish",
37
args: 1,
26
- flags: []string{"k"},
38
+ flags: nil,
39
online: true,
40
cmdFn: commands.Publish,
41
})
cmd/ipfs/resolve.go
+20
-3
@@ -8,8 +8,25 @@ import (
8
9
var cmdIpfsResolve = &commander.Command{
10
UsageLine: "resolve",
11
- Short: "resolve an ipns link to a hash",
12
- Long: `ipfs resolve <hash>... - Resolve hash.
11
+ Short: "resolve an ipns name to a <ref>",
12
+ Long: `ipfs resolve [<name>] - Resolve an ipns name to a <ref>.
13
+
14
+IPNS is a PKI namespace, where names are the hashes of public keys, and
15
+the private key enables publishing new (signed) values. In resolve, the
16
+default value of <name> is your own identity public key.
17
+
18
+
19
+Examples:
20
+
21
+Resolve the value of your identity:
22
+
23
+ > ipfs name resolve
24
+ QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
25
+
26
+Resolve te value of another name:
27
+
28
+ > ipfs name resolve QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n
29
+ QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
30
31
`,
32
Run: resolveCmd,
@@ -18,7 +35,7 @@ var cmdIpfsResolve = &commander.Command{
35
36
var resolveCmd = makeCommand(command{
37
name: "resolve",
21
- args: 1,
38
+ args: 0,
39
flags: nil,
40
online: true,
41
cmdFn: commands.Resolve,
core/commands/publish.go
+20
-2
@@ -13,14 +13,32 @@ import (
13
14
func Publish(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
15
log.Debug("Begin Publish")
16
+
17
if n.Identity == nil {
18
return errors.New("Identity not loaded!")
19
}
20
21
+ // name := ""
22
+ ref := ""
23
+
24
+ switch len(args) {
25
+ case 2:
26
+ // name = args[0]
27
+ ref = args[1]
28
+ return errors.New("keychains not yet implemented")
29
+ case 1:
30
+ // name = n.Identity.ID.String()
31
+ ref = args[0]
32
+
33
+ default:
34
+ return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
35
+ }
36
+
37
+ // later, n.Keychain.Get(name).PrivKey
38
k := n.Identity.PrivKey
39
40
pub := nsys.NewRoutingPublisher(n.Routing)
23
- err := pub.Publish(k, args[0])
41
+ err := pub.Publish(k, ref)
42
if err != nil {
43
return err
44
}
@@ -29,7 +47,7 @@ func Publish(n *core.IpfsNode, args []string, opts map[string]interface{}, out i
47
if err != nil {
48
return err
49
}
32
- fmt.Fprintf(out, "published mapping %s to %s\n", u.Key(hash), args[0])
50
+ fmt.Fprintf(out, "published name %s to %s\n", u.Key(hash), ref)
51
52
return nil
53
}
core/commands/resolve.go
+18
-1
@@ -1,6 +1,7 @@
1
package commands
2
3
import (
4
+ "errors"
5
"fmt"
6
"io"
7
@@ -8,7 +9,23 @@ import (
9
)
10
11
func Resolve(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
11
- res, err := n.Namesys.Resolve(args[0])
12
+
13
+ name := ""
14
+
15
+ switch len(args) {
16
+ case 1:
17
+ name = args[0]
18
+ case 0:
19
+ if n.Identity == nil {
20
+ return errors.New("Identity not loaded!")
21
+ }
22
+ name = n.Identity.ID.String()
23
+
24
+ default:
25
+ return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
26
+ }
27
+
28
+ res, err := n.Namesys.Resolve(name)
29
if err != nil {
30
return err
31
}
namesys/publisher.go
+11
-2
@@ -1,10 +1,12 @@
1
package namesys
2
3
import (
4
+ "fmt"
5
"time"
6
6
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
7
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
7
+ context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
8
+ proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
9
+ mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
10
11
ci "github.com/jbenet/go-ipfs/crypto"
12
routing "github.com/jbenet/go-ipfs/routing"
@@ -25,6 +27,13 @@ func NewRoutingPublisher(route routing.IpfsRouting) Publisher {
27
// Publish implements Publisher. Accepts a keypair and a value,
28
func (p *ipnsPublisher) Publish(k ci.PrivKey, value string) error {
29
log.Debug("namesys: Publish %s", value)
30
+
31
+ // validate `value` is a ref (multihash)
32
+ _, err := mh.FromB58String(value)
33
+ if err != nil {
34
+ return fmt.Errorf("publish value must be str multihash. %v", err)
35
+ }
36
+
37
ctx := context.TODO()
38
data, err := createRoutingEntryData(k, value)
39
if err != nil {