publish.go 656 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package commands

import (
	"errors"
	"fmt"
	"io"

	"github.com/jbenet/go-ipfs/core"
	u "github.com/jbenet/go-ipfs/util"

	nsys "github.com/jbenet/go-ipfs/namesys"
)

func Publish(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
	log.Debug("Begin Publish")
	if n.Identity == nil {
		return errors.New("Identity not loaded!")
	}

	k := n.Identity.PrivKey

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
22
	pub := nsys.NewRoutingPublisher(n.Routing)
23
	err := pub.Publish(k, args[0])
24 25 26 27 28 29 30 31
	if err != nil {
		return err
	}

	hash, err := k.GetPublic().Hash()
	if err != nil {
		return err
	}
32
	fmt.Fprintf(out, "published mapping %s to %s\n", u.Key(hash), args[0])
33 34 35

	return nil
}