当前位置: 首页>>代码示例>>Golang>>正文


Golang Node.Key方法代码示例

本文整理汇总了Golang中github.com/ipfs/go-ipfs/merkledag.Node.Key方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Key方法的具体用法?Golang Node.Key怎么用?Golang Node.Key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/ipfs/go-ipfs/merkledag.Node的用法示例。


在下文中一共展示了Node.Key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: addNode

func (adder *Adder) addNode(node *dag.Node, path string) error {
	// patch it into the root
	if path == "" {
		key, err := node.Key()
		if err != nil {
			return err
		}

		path = key.Pretty()
	}

	dir := gopath.Dir(path)
	if dir != "." {
		if err := mfs.Mkdir(adder.mr, dir, true, false); err != nil {
			return err
		}
	}

	if err := mfs.PutNode(adder.mr, path, node); err != nil {
		return err
	}

	if !adder.Silent {
		return outputDagnode(adder.out, path, node)
	}
	return nil
}
开发者ID:kalmi,项目名称:go-ipfs,代码行数:27,代码来源:add.go

示例2: writeRefsSingle

func (rw *RefWriter) writeRefsSingle(n *dag.Node) (int, error) {
	nkey, err := n.Key()
	if err != nil {
		return 0, err
	}

	if rw.skip(nkey) {
		return 0, nil
	}

	count := 0
	for _, l := range n.Links {
		lk := key.Key(l.Hash)

		if rw.skip(lk) {
			continue
		}

		if err := rw.WriteEdge(nkey, lk, l.Name); err != nil {
			return count, err
		}
		count++
	}
	return count, nil
}
开发者ID:Patagonicus,项目名称:go-ipfs,代码行数:25,代码来源:refs.go

示例3: randNode

func randNode() (*merkledag.Node, key.Key) {
	node := new(merkledag.Node)
	node.Data = make([]byte, 32)
	util.NewTimeSeededRand().Read(node.Data)
	k, _ := node.Key()
	return node, k
}
开发者ID:ccsblueboy,项目名称:go-ipfs,代码行数:7,代码来源:resolver_test.go

示例4: FromDAGNode

//FromDAGNode creates Records from  links of merkledag n and retuns it.
//links must contain "Stamp" and "Thread"
func FromDAGNode(self *peer.Self, n *merkledag.Node, sign []byte) (*Record, error) {
	r := &Record{
		self:     self,
		Stamp:    time.Unix(0, 0),
		Sign:     sign,
		Contents: make(map[string][]byte),
	}
	var err error
	r.Key, err = n.Key()
	if log.If(err) {
		return nil, err
	}
	for _, l := range n.Links {
		nn, err := r.self.GetLinkedNode(n, l.Name)
		if log.If(err) {
			return nil, err
		}
		r.Contents[l.Name] = nn.Data
		switch l.Name {
		case "thread":
			r.Thread = string(nn.Data)
		case "stamp":
			stamp := binary.BigEndian.Uint64(nn.Data)
			r.Stamp = time.Unix(0, int64(stamp))
		}
	}
	if err := r.check(false); log.If(err) {
		return nil, err
	}
	return r, nil
}
开发者ID:utamaro,项目名称:core,代码行数:33,代码来源:record.go

示例5: randNode

func randNode() (*mdag.Node, key.Key) {
	nd := new(mdag.Node)
	nd.Data = make([]byte, 32)
	util.NewTimeSeededRand().Read(nd.Data)
	k, _ := nd.Key()
	return nd, k
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:7,代码来源:pin_test.go

示例6: writeRefsRecursive

func (rw *RefWriter) writeRefsRecursive(n *dag.Node) (int, error) {
	nkey, err := n.Key()
	if err != nil {
		return 0, err
	}

	var count int
	for i, ng := range rw.DAG.GetDAG(rw.Ctx, n) {
		lk := key.Key(n.Links[i].Hash)
		if rw.skip(lk) {
			continue
		}

		if err := rw.WriteEdge(nkey, lk, n.Links[i].Name); err != nil {
			return count, err
		}

		nd, err := ng.Get(rw.Ctx)
		if err != nil {
			return count, err
		}

		c, err := rw.writeRefsRecursive(nd)
		count += c
		if err != nil {
			return count, err
		}
	}
	return count, nil
}
开发者ID:Patagonicus,项目名称:go-ipfs,代码行数:30,代码来源:refs.go

示例7: pinIndirectRecurse

func (p *pinner) pinIndirectRecurse(ctx context.Context, node *mdag.Node) error {
	k, err := node.Key()
	if err != nil {
		return err
	}

	p.indirPin.Increment(k)
	return p.pinLinks(ctx, node)
}
开发者ID:noscripter,项目名称:go-ipfs,代码行数:9,代码来源:pin.go

示例8: Diff

func Diff(ctx context.Context, ds dag.DAGService, a, b *dag.Node) []*Change {
	if len(a.Links) == 0 && len(b.Links) == 0 {
		ak, _ := a.Key()
		bk, _ := b.Key()
		return []*Change{
			&Change{
				Type:   Mod,
				Before: ak,
				After:  bk,
			},
		}
	}

	var out []*Change
	clean_a := a.Copy()
	clean_b := b.Copy()

	// strip out unchanged stuff
	for _, lnk := range a.Links {
		l, err := b.GetNodeLink(lnk.Name)
		if err == nil {
			if bytes.Equal(l.Hash, lnk.Hash) {
				// no change... ignore it
			} else {
				anode, _ := lnk.GetNode(ctx, ds)
				bnode, _ := l.GetNode(ctx, ds)
				sub := Diff(ctx, ds, anode, bnode)

				for _, subc := range sub {
					subc.Path = path.Join(lnk.Name, subc.Path)
					out = append(out, subc)
				}
			}
			clean_a.RemoveNodeLink(l.Name)
			clean_b.RemoveNodeLink(l.Name)
		}
	}

	for _, lnk := range clean_a.Links {
		out = append(out, &Change{
			Type:   Remove,
			Path:   lnk.Name,
			Before: key.Key(lnk.Hash),
		})
	}
	for _, lnk := range clean_b.Links {
		out = append(out, &Change{
			Type:  Add,
			Path:  lnk.Name,
			After: key.Key(lnk.Hash),
		})
	}

	return out
}
开发者ID:MichalPokorny,项目名称:go-ipfs,代码行数:55,代码来源:diff.go

示例9: NewList

//NewList returns List obj.
func NewList(self *peer.Self, key key.Key) (*List, error) {
	if key == "" {
		var err error
		n := merkledag.Node{}
		key, err = n.Key()
		if log.If(err) {
			return nil, err
		}
	}
	tl := &List{
		self: self,
		key:  key,
	}
	return tl, nil
}
开发者ID:utamaro,项目名称:core,代码行数:16,代码来源:thread_list.go

示例10: shouldSkip

func (t *traversal) shouldSkip(n *mdag.Node) (bool, error) {
	if t.opts.SkipDuplicates {
		k, err := n.Key()
		if err != nil {
			return true, err
		}

		if _, found := t.seen[string(k)]; found {
			return true, nil
		}
		t.seen[string(k)] = struct{}{}
	}

	return false, nil
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:15,代码来源:traverse.go

示例11: AddDAGNode

//AddDAGNode adds dagNode and returns key
func (m *Self) AddDAGNode(dagNode *merkledag.Node, pin bool) (key.Key, error) {
	if err := m.ipfsNode.DAG.AddRecursive(dagNode); log.If(err) {
		return "", err
	}
	k, err := dagNode.Key()
	if log.If(err) {
		return "", err
	}
	log.Println("added DAG", k.B58String())
	if pin {
		err = m.ipfsNode.Pinning.Pin(m.ctx, dagNode, true)
	}
	log.If(err)
	return k, err
}
开发者ID:utamaro,项目名称:core,代码行数:16,代码来源:self.go

示例12: addNode

func (params *adder) addNode(node *dag.Node, path string) error {
	// patch it into the root
	if path == "" {
		key, err := node.Key()
		if err != nil {
			return err
		}

		path = key.Pretty()
	}

	if err := params.editor.InsertNodeAtPath(params.ctx, path, node, newDirNode); err != nil {
		return err
	}

	return outputDagnode(params.out, path, node)
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:17,代码来源:add.go

示例13: New

//New returns Thread obj.
func New(self *peer.Self, name string, root key.Key) (*Thread, error) {
	if root == "" {
		var err error
		r := merkledag.Node{}
		root, err = r.Key()
		if log.If(err) {
			return nil, err
		}
		log.Println("root key", root)
	}
	t := &Thread{
		self: self,
		name: name,
		root: root,
	}
	return t, nil
}
开发者ID:utamaro,项目名称:core,代码行数:18,代码来源:thread.go

示例14: getOutput

func getOutput(dagnode *dag.Node) (*Object, error) {
	key, err := dagnode.Key()
	if err != nil {
		return nil, err
	}

	output := &Object{
		Hash:  key.B58String(),
		Links: make([]Link, len(dagnode.Links)),
	}

	for i, link := range dagnode.Links {
		output.Links[i] = Link{
			Name: link.Name,
			Hash: link.Hash.B58String(),
			Size: link.Size,
		}
	}

	return output, nil
}
开发者ID:yuanwr,项目名称:go-ipfs,代码行数:21,代码来源:object.go

示例15: unpinLinks

func (p *pinner) unpinLinks(ctx context.Context, node *mdag.Node) error {
	for _, l := range node.Links {
		node, err := l.GetNode(ctx, p.dserv)
		if err != nil {
			return err
		}

		k, err := node.Key()
		if err != nil {
			return err
		}

		p.indirPin.Decrement(k)

		err = p.unpinLinks(ctx, node)
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:noscripter,项目名称:go-ipfs,代码行数:21,代码来源:pin.go


注:本文中的github.com/ipfs/go-ipfs/merkledag.Node.Key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。