提交 2fa43ce4 作者: Juan Batiz-Benet

ipfs name cmd improvements

- cleaned up cmd help
- ipfs name publish [<name>] <ref>
- ipfs name resolve [<name>]
- publish validates <ref>
- both validate n args
上级 6ac11702
...@@ -8,9 +8,41 @@ import ( ...@@ -8,9 +8,41 @@ import (
) )
var cmdIpfsName = &commander.Command{ var cmdIpfsName = &commander.Command{
UsageLine: "name", UsageLine: "name [publish | resolve]",
Short: "Ipfs namespace manipulation tools.", Short: "ipfs namespace (ipns) tool",
Long: `ipfs name [publish|resolve] <ref/hash>`, Long: `ipfs name - Get/Set ipfs config values.
ipfs name publish [<name>] <ref> - Assign the <ref> to <name>
ipfs name resolve [<name>] - Resolve the <ref> value of <name>
IPNS is a PKI namespace, where names are the hashes of public keys, and
the private key enables publishing new (signed) values. In both publish
and resolve, the default value of <name> is your own identity public key.
Examples:
Publish a <ref> to your identity name:
> ipfs name publish QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
Publish a <ref> to another public key:
> ipfs name publish QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
Resolve the value of your identity:
> ipfs name resolve
QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
Resolve te value of another name:
> ipfs name resolve QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n
QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
`,
Run: addCmd, Run: addCmd,
Flag: *flag.NewFlagSet("ipfs-name", flag.ExitOnError), Flag: *flag.NewFlagSet("ipfs-name", flag.ExitOnError),
Subcommands: []*commander.Command{ Subcommands: []*commander.Command{
......
...@@ -8,22 +8,34 @@ import ( ...@@ -8,22 +8,34 @@ import (
var cmdIpfsPub = &commander.Command{ var cmdIpfsPub = &commander.Command{
UsageLine: "publish", UsageLine: "publish",
Short: "Publish an object to ipns under your key.", Short: "publish a <ref> to ipns.",
Long: `ipfs publish <path> - Publish object to ipns. Long: `ipfs publish [<name>] <ref> - publish a <ref> to ipns.
IPNS is a PKI namespace, where names are the hashes of public keys, and
the private key enables publishing new (signed) values. In publish, the
default value of <name> is your own identity public key.
Examples:
Publish a <ref> to your identity name:
> ipfs name publish QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
Publish a <ref> to another public key:
> ipfs name publish QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
`, `,
Run: pubCmd, Run: pubCmd,
Flag: *flag.NewFlagSet("ipfs-publish", flag.ExitOnError), Flag: *flag.NewFlagSet("ipfs-publish", flag.ExitOnError),
} }
func init() {
cmdIpfsPub.Flag.String("k", "", "Specify key to use for publishing.")
}
var pubCmd = makeCommand(command{ var pubCmd = makeCommand(command{
name: "publish", name: "publish",
args: 1, args: 1,
flags: []string{"k"}, flags: nil,
online: true, online: true,
cmdFn: commands.Publish, cmdFn: commands.Publish,
}) })
...@@ -8,8 +8,25 @@ import ( ...@@ -8,8 +8,25 @@ import (
var cmdIpfsResolve = &commander.Command{ var cmdIpfsResolve = &commander.Command{
UsageLine: "resolve", UsageLine: "resolve",
Short: "resolve an ipns link to a hash", Short: "resolve an ipns name to a <ref>",
Long: `ipfs resolve <hash>... - Resolve hash. Long: `ipfs resolve [<name>] - Resolve an ipns name to a <ref>.
IPNS is a PKI namespace, where names are the hashes of public keys, and
the private key enables publishing new (signed) values. In resolve, the
default value of <name> is your own identity public key.
Examples:
Resolve the value of your identity:
> ipfs name resolve
QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
Resolve te value of another name:
> ipfs name resolve QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n
QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
`, `,
Run: resolveCmd, Run: resolveCmd,
...@@ -18,7 +35,7 @@ var cmdIpfsResolve = &commander.Command{ ...@@ -18,7 +35,7 @@ var cmdIpfsResolve = &commander.Command{
var resolveCmd = makeCommand(command{ var resolveCmd = makeCommand(command{
name: "resolve", name: "resolve",
args: 1, args: 0,
flags: nil, flags: nil,
online: true, online: true,
cmdFn: commands.Resolve, cmdFn: commands.Resolve,
......
...@@ -13,14 +13,32 @@ import ( ...@@ -13,14 +13,32 @@ import (
func Publish(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error { func Publish(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
log.Debug("Begin Publish") log.Debug("Begin Publish")
if n.Identity == nil { if n.Identity == nil {
return errors.New("Identity not loaded!") return errors.New("Identity not loaded!")
} }
// name := ""
ref := ""
switch len(args) {
case 2:
// name = args[0]
ref = args[1]
return errors.New("keychains not yet implemented")
case 1:
// name = n.Identity.ID.String()
ref = args[0]
default:
return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
}
// later, n.Keychain.Get(name).PrivKey
k := n.Identity.PrivKey k := n.Identity.PrivKey
pub := nsys.NewRoutingPublisher(n.Routing) pub := nsys.NewRoutingPublisher(n.Routing)
err := pub.Publish(k, args[0]) err := pub.Publish(k, ref)
if err != nil { if err != nil {
return err return err
} }
...@@ -29,7 +47,7 @@ func Publish(n *core.IpfsNode, args []string, opts map[string]interface{}, out i ...@@ -29,7 +47,7 @@ func Publish(n *core.IpfsNode, args []string, opts map[string]interface{}, out i
if err != nil { if err != nil {
return err return err
} }
fmt.Fprintf(out, "published mapping %s to %s\n", u.Key(hash), args[0]) fmt.Fprintf(out, "published name %s to %s\n", u.Key(hash), ref)
return nil return nil
} }
package commands package commands
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
...@@ -8,7 +9,23 @@ import ( ...@@ -8,7 +9,23 @@ import (
) )
func Resolve(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error { func Resolve(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
res, err := n.Namesys.Resolve(args[0])
name := ""
switch len(args) {
case 1:
name = args[0]
case 0:
if n.Identity == nil {
return errors.New("Identity not loaded!")
}
name = n.Identity.ID.String()
default:
return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
}
res, err := n.Namesys.Resolve(name)
if err != nil { if err != nil {
return err return err
} }
......
package namesys package namesys
import ( import (
"fmt"
"time" "time"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto" proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
ci "github.com/jbenet/go-ipfs/crypto" ci "github.com/jbenet/go-ipfs/crypto"
routing "github.com/jbenet/go-ipfs/routing" routing "github.com/jbenet/go-ipfs/routing"
...@@ -25,6 +27,13 @@ func NewRoutingPublisher(route routing.IpfsRouting) Publisher { ...@@ -25,6 +27,13 @@ func NewRoutingPublisher(route routing.IpfsRouting) Publisher {
// Publish implements Publisher. Accepts a keypair and a value, // Publish implements Publisher. Accepts a keypair and a value,
func (p *ipnsPublisher) Publish(k ci.PrivKey, value string) error { func (p *ipnsPublisher) Publish(k ci.PrivKey, value string) error {
log.Debug("namesys: Publish %s", value) log.Debug("namesys: Publish %s", value)
// validate `value` is a ref (multihash)
_, err := mh.FromB58String(value)
if err != nil {
return fmt.Errorf("publish value must be str multihash. %v", err)
}
ctx := context.TODO() ctx := context.TODO()
data, err := createRoutingEntryData(k, value) data, err := createRoutingEntryData(k, value)
if err != nil { if err != nil {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论