// ResolveN implements Resolver. func (ns *mpns) ResolveN(ctx context.Context, name string, depth int) (path.Path, error) { if strings.HasPrefix(name, "/ipfs/") { return path.ParsePath(name) } if !strings.HasPrefix(name, "/") { return path.ParsePath("/ipfs/" + name) } return resolve(ctx, ns, name, depth, "/ipns/") }
// TODO: extract all this logic from the core/commands/object.go to avoid dupe code func (s *Shell) Patch(root, action string, args ...string) (string, error) { p, err := path.ParsePath(root) if err != nil { return "", err } rootnd, err := core.Resolve(s.ctx, s.node, p) if err != nil { return "", err } insertpath := args[0] childhash := args[1] childpath, err := path.ParsePath(childhash) if err != nil { return "", err } nnode, err := core.Resolve(s.ctx, s.node, childpath) if err != nil { return "", err } e := dagutils.NewDagEditor(rootnd, s.node.DAG) switch action { case "add-link": err := e.InsertNodeAtPath(s.ctx, insertpath, nnode, nil) if err != nil { return "", err } _, err = e.Finalize(s.node.DAG) if err != nil { return "", err } final, err := e.GetNode().Key() if err != nil { return "", err } return final.B58String(), nil default: return "", fmt.Errorf("unsupported action (impl not complete)") } }
func (ns *mpns) addToDHTCache(key ci.PrivKey, value path.Path, eol time.Time) { rr, ok := ns.resolvers["dht"].(*routingResolver) if !ok { // should never happen, purely for sanity log.Panicf("unexpected type %T as DHT resolver.", ns.resolvers["dht"]) } if rr.cache == nil { // resolver has no caching return } var err error value, err = path.ParsePath(value.String()) if err != nil { log.Error("could not parse path") return } name, err := peer.IDFromPrivateKey(key) if err != nil { log.Error("while adding to cache, could not get peerid from private key") return } if time.Now().Add(DefaultResolverCacheTTL).Before(eol) { eol = time.Now().Add(DefaultResolverCacheTTL) } rr.cache.Add(name.Pretty(), cacheEntry{ val: value, eol: eol, }) }
func getNodeFromPath(ctx context.Context, node *core.IpfsNode, p string) (node.Node, error) { switch { case strings.HasPrefix(p, "/ipfs/"): np, err := path.ParsePath(p) if err != nil { return nil, err } resolver := &path.Resolver{ DAG: node.DAG, ResolveOnce: uio.ResolveUnixfsOnce, } nd, err := core.Resolve(ctx, node.Namesys, resolver, np) if err != nil { return nil, err } pbnd, ok := nd.(*dag.ProtoNode) if !ok { return nil, dag.ErrNotProtobuf } return pbnd, nil default: fsn, err := mfs.Lookup(node.FilesRoot, p) if err != nil { return nil, err } return fsn.GetNode() } }
func loadRoot(ctx context.Context, rt *keyRoot, ipfs *core.IpfsNode, name string) (fs.Node, error) { p, err := path.ParsePath("/ipns/" + name) if err != nil { log.Errorf("mkpath %s: %s", name, err) return nil, err } node, err := core.Resolve(ctx, ipfs, p) if err != nil { log.Errorf("looking up %s: %s", p, err) return nil, err } root, err := mfs.NewRoot(ctx, ipfs.DAG, node, ipnsPubFunc(ipfs, rt.k)) if err != nil { return nil, err } rt.root = root switch val := root.GetValue().(type) { case *mfs.Directory: return &Directory{dir: val}, nil case *mfs.File: return &FileNode{fi: val}, nil default: return nil, errors.New("unrecognized type") } panic("not reached") }
func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) { dagnodes := make([]node.Node, 0) for _, fpath := range paths { p, err := path.ParsePath(fpath) if err != nil { return nil, err } dagnode, err := core.Resolve(ctx, n.Namesys, n.Resolver, p) if err != nil { return nil, fmt.Errorf("pin: %s", err) } dagnodes = append(dagnodes, dagnode) } var out []*cid.Cid for _, dagnode := range dagnodes { c := dagnode.Cid() ctx, cancel := context.WithCancel(ctx) defer cancel() err := n.Pinning.Pin(ctx, dagnode, recursive) if err != nil { return nil, fmt.Errorf("pin: %s", err) } out = append(out, c) } err := n.Pinning.Flush() if err != nil { return nil, err } return out, nil }
func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) { var unpinned []*cid.Cid for _, p := range paths { p, err := path.ParsePath(p) if err != nil { return nil, err } k, err := core.ResolveToCid(ctx, n, p) if err != nil { return nil, err } ctx, cancel := context.WithCancel(ctx) defer cancel() err = n.Pinning.Unpin(ctx, k, recursive) if err != nil { return nil, err } unpinned = append(unpinned, k) } err := n.Pinning.Flush() if err != nil { return nil, err } return unpinned, nil }
func tryParseDnsLink(txt string) (path.Path, error) { parts := strings.SplitN(txt, "=", 2) if len(parts) == 2 && parts[0] == "dnslink" { return path.ParsePath(parts[1]) } return "", errors.New("not a valid dnslink entry") }
//TODO: hrm, maybe this interface could be better func (s *Shell) PatchLink(root, npath, childhash string, create bool) (string, error) { p, err := path.ParsePath(root) if err != nil { return "", err } rootnd, err := core.Resolve(s.ctx, s.node, p) if err != nil { return "", err } childpath, err := path.ParsePath(childhash) if err != nil { return "", err } nnode, err := core.Resolve(s.ctx, s.node, childpath) if err != nil { return "", err } e := dagutils.NewDagEditor(rootnd, s.node.DAG) err = e.InsertNodeAtPath(s.ctx, npath, nnode, func() *dag.Node { return &dag.Node{Data: ft.FolderPBData()} }) if err != nil { return "", err } _, err = e.Finalize(s.node.DAG) if err != nil { return "", err } final, err := e.GetNode().Key() if err != nil { return "", err } return final.B58String(), nil }
// resolveOnce implements resolver. Uses the IPFS routing system to // resolve SFS-like names. func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) { log.Debugf("RoutingResolve: '%s'", name) hash, err := mh.FromB58String(name) if err != nil { log.Warning("RoutingResolve: bad input hash: [%s]\n", name) return "", err } // name should be a multihash. if it isn't, error out here. // use the routing system to get the name. // /ipns/<name> h := []byte("/ipns/" + string(hash)) ipnsKey := key.Key(h) val, err := r.routing.GetValue(ctx, ipnsKey) if err != nil { log.Warning("RoutingResolve get failed.") return "", err } entry := new(pb.IpnsEntry) err = proto.Unmarshal(val, entry) if err != nil { return "", err } // name should be a public key retrievable from ipfs pubkey, err := routing.GetPublicKey(r.routing, ctx, hash) if err != nil { return "", err } hsh, _ := pubkey.Hash() log.Debugf("pk hash = %s", key.Key(hsh)) // check sig with pk if ok, err := pubkey.Verify(ipnsEntryDataForSig(entry), entry.GetSignature()); err != nil || !ok { return "", fmt.Errorf("Invalid value. Not signed by PrivateKey corresponding to %v", pubkey) } // ok sig checks out. this is a valid name. // check for old style record: valh, err := mh.Cast(entry.GetValue()) if err != nil { // Not a multihash, probably a new record return path.ParsePath(string(entry.GetValue())) } else { // Its an old style multihash record log.Warning("Detected old style multihash record") return path.FromKey(key.Key(valh)), nil } }
func (s *Shell) ResolvePath(ipath string) (string, error) { p, err := path.ParsePath(ipath) if err != nil { return "", err } nd, err := core.Resolve(s.ctx, s.node, p) if err != nil { return "", err } return nd.Key().B58String(), nil }
func resolve(ctx context.Context, n *core.IpfsNode, p string) (ipld.Node, error) { pp, err := path.ParsePath(p) if err != nil { return nil, err } dagnode, err := core.Resolve(ctx, n.Namesys, n.Resolver, pp) if err == core.ErrNoNamesys { return nil, coreiface.ErrOffline } else if err != nil { return nil, err } return dagnode, nil }
func TestPublishWithCache0(t *testing.T) { dst := ds.NewMapDatastore() priv, _, err := ci.GenerateKeyPair(ci.RSA, 1024) if err != nil { t.Fatal(err) } routing := offroute.NewOfflineRouter(dst, priv) nsys := NewNameSystem(routing, dst, 0) p, err := path.ParsePath(unixfs.EmptyDirNode().Cid().String()) if err != nil { t.Fatal(err) } nsys.Publish(context.Background(), priv, p) }
// Cat resolves the ipfs path p and returns a reader for that data, if it exists and is availalbe func (s *Shell) Cat(p string) (io.ReadCloser, error) { ipfsPath, err := path.ParsePath(p) if err != nil { return nil, errgo.Notef(err, "cat: could not parse %q", p) } nd, err := core.Resolve(s.ctx, s.node, ipfsPath) if err != nil { return nil, errgo.Notef(err, "cat: could not resolve %s", ipfsPath) } dr, err := unixfsio.NewDagReader(s.ctx, nd, s.node.DAG) if err != nil { return nil, errgo.Notef(err, "cat: failed to construct DAG reader") } return dr, nil }
func objectsForPaths(ctx context.Context, n *core.IpfsNode, paths []string) ([]node.Node, error) { objects := make([]node.Node, len(paths)) for i, sp := range paths { p, err := path.ParsePath(sp) if err != nil { return nil, err } o, err := core.Resolve(ctx, n.Namesys, n.Resolver, p) if err != nil { return nil, err } objects[i] = o } return objects, nil }
func getNodeFromPath(ctx context.Context, node *core.IpfsNode, p string) (*dag.Node, error) { switch { case strings.HasPrefix(p, "/ipfs/"): np, err := path.ParsePath(p) if err != nil { return nil, err } return core.Resolve(ctx, node, np) default: fsn, err := mfs.Lookup(node.FilesRoot, p) if err != nil { return nil, err } return fsn.GetNode() } }
func pinLsKeys(args []string, typeStr string, ctx context.Context, n *core.IpfsNode) (map[string]RefKeyObject, error) { keys := make(map[string]RefKeyObject) for _, p := range args { pth, err := path.ParsePath(p) if err != nil { return nil, err } dagNode, err := core.Resolve(ctx, n.Namesys, n.Resolver, pth) if err != nil { return nil, err } mode, ok := pin.StringToPinMode(typeStr) if !ok { return nil, fmt.Errorf("Invalid pin mode '%s'", typeStr) } c := dagNode.Cid() pinType, pinned, err := n.Pinning.IsPinnedWithType(c, mode) if err != nil { return nil, err } if !pinned { return nil, fmt.Errorf("Path '%s' is not pinned", p) } switch pinType { case "direct", "indirect", "recursive", "internal": default: pinType = "indirect through " + pinType } keys[c.String()] = RefKeyObject{ Type: pinType, } } return keys, nil }
// Cat resolves the ipfs path p and returns a reader for that data, if it exists and is availalbe func (s *Shell) Get(ref, outdir string) error { ipfsPath, err := path.ParsePath(ref) if err != nil { return errgo.Notef(err, "get: could not parse %q", ref) } nd, err := core.Resolve(s.ctx, s.node, ipfsPath) if err != nil { return errgo.Notef(err, "get: could not resolve %s", ipfsPath) } r, err := uarchive.DagArchive(s.ctx, nd, outdir, s.node.DAG, false, 0) if err != nil { return err } ext := tar.Extractor{outdir} return ext.Extract(r) }
func (s *Shell) List(ipath string) ([]*sh.LsLink, error) { p, err := path.ParsePath(ipath) if err != nil { return nil, err } nd, err := core.Resolve(s.ctx, s.node, p) if err != nil { return nil, err } var out []*sh.LsLink for _, l := range nd.Links { out = append(out, &sh.LsLink{ Hash: l.Hash.B58String(), Name: l.Name, Size: l.Size, }) } return out, nil }
cmds.StringArg("obj_b", true, false, "object to diff"), }, Options: []cmds.Option{ cmds.BoolOption("verbose", "v", "Produce verbose output"), }, Run: func(req cmds.Request, res cmds.Response) { node, err := req.InvocContext().GetNode() if err != nil { res.SetError(err, cmds.ErrNormal) return } a := req.Arguments()[0] b := req.Arguments()[1] pa, err := path.ParsePath(a) if err != nil { res.SetError(err, cmds.ErrNormal) return } pb, err := path.ParsePath(b) if err != nil { res.SetError(err, cmds.ErrNormal) return } ctx := req.Context() obj_a, err := core.Resolve(ctx, node, pa) if err != nil {
func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) { // TODO(cryptix): move me to ServeHTTP and pass into all handlers ctx, cancel := context.WithCancel(i.node.Context()) defer cancel() rootPath, err := path.ParsePath(r.URL.Path) if err != nil { webError(w, "putHandler: ipfs path not valid", err, http.StatusBadRequest) return } rsegs := rootPath.Segments() if rsegs[0] == ipnsPathPrefix { webError(w, "putHandler: updating named entries not supported", errors.New("WritableGateway: ipns put not supported"), http.StatusBadRequest) return } var newnode *dag.Node if rsegs[len(rsegs)-1] == "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn" { newnode = uio.NewEmptyDirectory() } else { putNode, err := i.newDagFromReader(r.Body) if err != nil { webError(w, "putHandler: Could not create DAG from request", err, http.StatusInternalServerError) return } newnode = putNode } var newPath string if len(rsegs) > 1 { newPath = path.Join(rsegs[2:]) } var newkey key.Key rnode, err := core.Resolve(ctx, i.node, rootPath) switch ev := err.(type) { case path.ErrNoLink: // ev.Node < node where resolve failed // ev.Name < new link // but we need to patch from the root rnode, err := i.node.DAG.Get(ctx, key.B58KeyDecode(rsegs[1])) if err != nil { webError(w, "putHandler: Could not create DAG from request", err, http.StatusInternalServerError) return } e := dagutils.NewDagEditor(rnode, i.node.DAG) err = e.InsertNodeAtPath(ctx, newPath, newnode, uio.NewEmptyDirectory) if err != nil { webError(w, "putHandler: InsertNodeAtPath failed", err, http.StatusInternalServerError) return } nnode, err := e.Finalize(i.node.DAG) if err != nil { webError(w, "putHandler: could not get node", err, http.StatusInternalServerError) return } newkey, err = nnode.Key() if err != nil { webError(w, "putHandler: could not get key of edited node", err, http.StatusInternalServerError) return } case nil: // object set-data case rnode.Data = newnode.Data newkey, err = i.node.DAG.Add(rnode) if err != nil { nnk, _ := newnode.Key() rk, _ := rnode.Key() webError(w, fmt.Sprintf("putHandler: Could not add newnode(%q) to root(%q)", nnk.B58String(), rk.B58String()), err, http.StatusInternalServerError) return } default: log.Warningf("putHandler: unhandled resolve error %T", ev) webError(w, "could not resolve root DAG", ev, http.StatusInternalServerError) return } i.addUserHeaders(w) // ok, _now_ write user's headers. w.Header().Set("IPFS-Hash", newkey.String()) http.Redirect(w, r, gopath.Join(ipfsPathPrefix, newkey.String(), newPath), http.StatusCreated) }
data within an object. Objects have a max size of 1MB and objects larger than the limit will not be respected by the network. `, }, Arguments: []cmds.Argument{ cmds.StringArg("root", true, false, "The hash of the node to modify."), cmds.FileArg("data", true, false, "Data to append.").EnableStdin(), }, Run: func(req cmds.Request, res cmds.Response) { nd, err := req.InvocContext().GetNode() if err != nil { res.SetError(err, cmds.ErrNormal) return } root, err := path.ParsePath(req.Arguments()[0]) if err != nil { res.SetError(err, cmds.ErrNormal) return } rootnd, err := core.Resolve(req.Context(), nd, root) if err != nil { res.SetError(err, cmds.ErrNormal) return } fi, err := req.Files().NextFile() if err != nil { res.SetError(err, cmds.ErrNormal) return
name := req.Arguments()[0] recursive, _, _ := req.Option("recursive").Bool() // the case when ipns is resolved step by step if strings.HasPrefix(name, "/ipns/") && !recursive { p, err := n.Namesys.ResolveN(req.Context(), name, 1) if err != nil { res.SetError(err, cmds.ErrNormal) return } res.SetOutput(&ResolvedPath{p}) return } // else, ipfs path or ipns with recursive flag p, err := path.ParsePath(name) if err != nil { res.SetError(err, cmds.ErrNormal) return } node, err := core.Resolve(req.Context(), n, p) if err != nil { res.SetError(err, cmds.ErrNormal) return } key, err := node.Key() if err != nil { res.SetError(err, cmds.ErrNormal) return
func (i *gatewayHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { urlPath := r.URL.Path ctx, cancel := context.WithCancel(i.node.Context()) defer cancel() p, err := path.ParsePath(urlPath) if err != nil { webError(w, "failed to parse path", err, http.StatusBadRequest) return } c, components, err := path.SplitAbsPath(p) if err != nil { webError(w, "Could not split path", err, http.StatusInternalServerError) return } tctx, cancel := context.WithTimeout(ctx, time.Minute) defer cancel() rootnd, err := i.node.Resolver.DAG.Get(tctx, c) if err != nil { webError(w, "Could not resolve root object", err, http.StatusBadRequest) return } pathNodes, err := i.node.Resolver.ResolveLinks(tctx, rootnd, components[:len(components)-1]) if err != nil { webError(w, "Could not resolve parent object", err, http.StatusBadRequest) return } pbnd, ok := pathNodes[len(pathNodes)-1].(*dag.ProtoNode) if !ok { webError(w, "Cannot read non protobuf nodes through gateway", dag.ErrNotProtobuf, http.StatusBadRequest) return } // TODO(cyrptix): assumes len(pathNodes) > 1 - not found is an error above? err = pbnd.RemoveNodeLink(components[len(components)-1]) if err != nil { webError(w, "Could not delete link", err, http.StatusBadRequest) return } var newnode *dag.ProtoNode = pbnd for j := len(pathNodes) - 2; j >= 0; j-- { if _, err := i.node.DAG.Add(newnode); err != nil { webError(w, "Could not add node", err, http.StatusInternalServerError) return } pathpb, ok := pathNodes[j].(*dag.ProtoNode) if !ok { webError(w, "Cannot read non protobuf nodes through gateway", dag.ErrNotProtobuf, http.StatusBadRequest) return } newnode, err = pathpb.UpdateNodeLink(components[j], newnode) if err != nil { webError(w, "Could not update node links", err, http.StatusInternalServerError) return } } if _, err := i.node.DAG.Add(newnode); err != nil { webError(w, "Could not add root node", err, http.StatusInternalServerError) return } // Redirect to new path ncid := newnode.Cid() i.addUserHeaders(w) // ok, _now_ write user's headers. w.Header().Set("IPFS-Hash", ncid.String()) http.Redirect(w, r, gopath.Join(ipfsPathPrefix+ncid.String(), path.Join(components[:len(components)-1])), http.StatusCreated) }
// resolveOnce implements resolver. Uses the IPFS routing system to // resolve SFS-like names. func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) { log.Debugf("RoutingResolve: '%s'", name) cached, ok := r.cacheGet(name) if ok { return cached, nil } name = strings.TrimPrefix(name, "/ipns/") hash, err := mh.FromB58String(name) if err != nil { // name should be a multihash. if it isn't, error out here. log.Warningf("RoutingResolve: bad input hash: [%s]\n", name) return "", err } // use the routing system to get the name. // /ipns/<name> h := []byte("/ipns/" + string(hash)) var entry *pb.IpnsEntry var pubkey ci.PubKey resp := make(chan error, 2) go func() { ipnsKey := string(h) val, err := r.routing.GetValue(ctx, ipnsKey) if err != nil { log.Warning("RoutingResolve get failed.") resp <- err return } entry = new(pb.IpnsEntry) err = proto.Unmarshal(val, entry) if err != nil { resp <- err return } resp <- nil }() go func() { // name should be a public key retrievable from ipfs pubk, err := routing.GetPublicKey(r.routing, ctx, hash) if err != nil { resp <- err return } pubkey = pubk resp <- nil }() for i := 0; i < 2; i++ { err = <-resp if err != nil { return "", err } } // check sig with pk if ok, err := pubkey.Verify(ipnsEntryDataForSig(entry), entry.GetSignature()); err != nil || !ok { return "", fmt.Errorf("Invalid value. Not signed by PrivateKey corresponding to %v", pubkey) } // ok sig checks out. this is a valid name. // check for old style record: valh, err := mh.Cast(entry.GetValue()) if err != nil { // Not a multihash, probably a new record p, err := path.ParsePath(string(entry.GetValue())) if err != nil { return "", err } r.cacheSet(name, p, entry) return p, nil } else { // Its an old style multihash record log.Warning("Detected old style multihash record") p := path.FromCid(cid.NewCidV0(valh)) r.cacheSet(name, p, entry) return p, nil } }
Note that the "--encoding" option does not affect the output, since the output is the raw data of the object. `, }, Arguments: []cmds.Argument{ cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() if err != nil { res.SetError(err, cmds.ErrNormal) return } fpath, err := path.ParsePath(req.Arguments()[0]) if err != nil { res.SetError(err, cmds.ErrNormal) return } node, err := core.Resolve(req.Context(), n.Namesys, n.Resolver, fpath) if err != nil { res.SetError(err, cmds.ErrNormal) return } pbnode, ok := node.(*dag.ProtoNode) if !ok { res.SetError(dag.ErrNotProtobuf, cmds.ErrNormal) return
func main() { app := cli.NewApp() app.Name = "ipget" app.Usage = "Retrieve and save IPFS objects." app.Version = "0.2.0" app.Flags = []cli.Flag{ cli.StringFlag{ Name: "output,o", Usage: "specify output location", }, cli.StringFlag{ Name: "node,n", Usage: "specify ipfs node strategy ('local', 'spawn', or 'fallback')", Value: "fallback", }, } app.Action = func(c *cli.Context) error { if !c.Args().Present() { fmt.Fprintf(os.Stderr, "usage: ipget <ipfs ref>\n") os.Exit(1) } outfile := c.String("output") arg := c.Args().First() // Use the final segment of the object's path if no path was given. if outfile == "" { ipfsPath, err := path.ParsePath(arg) if err != nil { fmt.Fprintf(os.Stderr, "ParsePath failure: %s\n", err) os.Exit(1) } segments := ipfsPath.Segments() outfile = segments[len(segments)-1] } var shell fallback.Shell var err error if c.String("node") == "fallback" { shell, err = fallback.NewShell() if err != nil { fmt.Fprintf(os.Stderr, "error: %s\n", err) os.Exit(1) } } else if c.String("node") == "spawn" { shell, err = fallback.NewEmbeddedShell() if err != nil { fmt.Fprintf(os.Stderr, "error: %s\n", err) os.Exit(1) } } else if c.String("node") == "local" { shell, err = fallback.NewApiShell() if err != nil { fmt.Fprintf(os.Stderr, "error: %s\n", err) os.Exit(1) } } else { fmt.Fprintf(os.Stderr, "error: no such 'node' strategy, '%s'\n", c.String("node")) os.Exit(1) return nil } if err := shell.Get(arg, outfile); err != nil { os.Remove(outfile) fmt.Fprintf(os.Stderr, "ipget failed: %s\n", err) os.Exit(2) } return nil } // Catch interrupt signal sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) go func() { <-sigs os.Exit(1) }() // TODO(noffle): remove this once https://github.com/urfave/cli/issues/427 is // fixed. args := movePostfixOptions(os.Args) app.Run(args) }
if _, _, err := req.Option("headers").Bool(); err != nil { res.SetError(err, cmds.ErrNormal) return } resolve, _, err := req.Option("resolve-type").Bool() if err != nil { res.SetError(err, cmds.ErrNormal) return } paths := req.Arguments() var dagnodes []node.Node for _, fpath := range paths { p, err := path.ParsePath(fpath) if err != nil { res.SetError(err, cmds.ErrNormal) return } r := &path.Resolver{ DAG: nd.DAG, ResolveOnce: uio.ResolveUnixfsOnce, } dagnode, err := core.Resolve(req.Context(), nd.Namesys, r, p) if err != nil { res.SetError(err, cmds.ErrNormal) return }
var pstr string switch len(args) { case 2: name = args[0] pstr = args[1] if name != n.Identity.Pretty() { res.SetError(errors.New("keychains not yet implemented"), cmds.ErrNormal) return } case 1: // name = n.Identity.Pretty() pstr = args[0] } p, err := path.ParsePath(pstr) if err != nil { res.SetError(fmt.Errorf("failed to validate path: %v", err), cmds.ErrNormal) return } // TODO n.Keychain.Get(name).PrivKey // TODO(cryptix): is req.Context().Context a child of n.Context()? output, err := publish(req.Context().Context, n, n.PrivateKey, p) if err != nil { res.SetError(err, cmds.ErrNormal) return } res.SetOutput(output) }, Marshalers: cmds.MarshalerMap{
func (r *mockResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) { return path.ParsePath(r.entries[name]) }