• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang blocks.Block类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Put

func (w *writecache) Put(b *blocks.Block) error {
	if _, ok := w.cache.Get(b.Key()); ok {
		return nil
	}
	w.cache.Add(b.Key(), struct{}{})
	return w.blockstore.Put(b)
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:7,代码来源:write_cache.go


示例2: HasBlock

// HasBlock announces the existance of a block to this bitswap service. The
// service will potentially notify its peers.
func (bs *Bitswap) HasBlock(blk blocks.Block) error {
	select {
	case <-bs.process.Closing():
		return errors.New("bitswap is closed")
	default:
	}

	err := bs.blockstore.Put(blk)
	if err != nil {
		log.Errorf("Error writing block to datastore: %s", err)
		return err
	}

	// NOTE: There exists the possiblity for a race condition here.  If a user
	// creates a node, then adds it to the dagservice while another goroutine
	// is waiting on a GetBlock for that object, they will receive a reference
	// to the same node. We should address this soon, but i'm not going to do
	// it now as it requires more thought and isnt causing immediate problems.
	bs.notifications.Publish(blk)

	bs.engine.AddBlock(blk)

	select {
	case bs.newBlocks <- blk.Cid():
		// send block off to be reprovided
	case <-bs.process.Closing():
		return bs.process.Close()
	}
	return nil
}
开发者ID:tswindell,项目名称:go-ipfs,代码行数:32,代码来源:bitswap.go


示例3: assertBlocksEqual

func assertBlocksEqual(t *testing.T, a, b *blocks.Block) {
	if !bytes.Equal(a.Data, b.Data) {
		t.Fatal("blocks aren't equal")
	}
	if a.Key() != b.Key() {
		t.Fatal("block keys aren't equal")
	}
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:8,代码来源:notifications_test.go


示例4: getOrFail

func getOrFail(bitswap Instance, b *blocks.Block, t *testing.T, wg *sync.WaitGroup) {
	if _, err := bitswap.Blockstore().Get(b.Key()); err != nil {
		_, err := bitswap.Exchange.GetBlock(context.Background(), b.Key())
		if err != nil {
			t.Fatal(err)
		}
	}
	wg.Done()
}
开发者ID:musha68k,项目名称:go-ipfs,代码行数:9,代码来源:bitswap_test.go


示例5: Put

func (bs *blockstore) Put(block blocks.Block) error {
	k := dshelp.CidToDsKey(block.Cid())

	// Has is cheaper than Put, so see if we already have it
	exists, err := bs.datastore.Has(k)
	if err == nil && exists {
		return nil // already stored.
	}
	return bs.datastore.Put(k, block.RawData())
}
开发者ID:tswindell,项目名称:go-ipfs,代码行数:10,代码来源:blockstore.go


示例6: Put

func (w *writecache) Put(b blocks.Block) error {
	k := b.Key()
	if _, ok := w.cache.Get(k); ok {
		return nil
	}
	defer log.EventBegin(context.TODO(), "writecache.BlockAdded", &k).Done()

	w.cache.Add(b.Key(), struct{}{})
	return w.blockstore.Put(b)
}
开发者ID:ccsblueboy,项目名称:go-ipfs,代码行数:10,代码来源:write_cache.go


示例7: Push

func (s *BlockList) Push(b *blocks.Block) {
	if s.uniques == nil {
		s.uniques = make(map[key.Key]*list.Element)
	}
	_, ok := s.uniques[b.Key()]
	if !ok {
		e := s.list.PushBack(b)
		s.uniques[b.Key()] = e
	}
}
开发者ID:noscripter,项目名称:go-ipfs,代码行数:10,代码来源:worker.go


示例8: Put

func (bs *blockstore) Put(block *blocks.Block) error {
	k := block.Key().DsKey()

	// Has is cheaper than Put, so see if we already have it
	exists, err := bs.datastore.Has(k)
	if err == nil && exists {
		return nil // already stored.
	}
	return bs.datastore.Put(k, block.Data)
}
开发者ID:avbalu,项目名称:go-ipfs,代码行数:10,代码来源:blockstore.go


示例9: Put

func (b *bloomcache) Put(bl blocks.Block) error {
	if has, ok := b.hasCached(bl.Cid()); ok && has {
		return nil
	}

	err := b.blockstore.Put(bl)
	if err == nil {
		b.bloom.AddTS(bl.Cid().Bytes())
	}
	return err
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:11,代码来源:bloom_cache.go


示例10: Put

func (b *arccache) Put(bl blocks.Block) error {
	if has, ok := b.hasCached(bl.Cid()); ok && has {
		return nil
	}

	err := b.blockstore.Put(bl)
	if err == nil {
		b.addCache(bl.Cid(), true)
	}
	return err
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:11,代码来源:arc_cache.go


示例11: AddBlock

// AddBlock adds a particular block to the service, Putting it into the datastore.
// TODO pass a context into this if the remote.HasBlock is going to remain here.
func (s *BlockService) AddBlock(b *blocks.Block) (key.Key, error) {
	k := b.Key()
	err := s.Blockstore.Put(b)
	if err != nil {
		return k, err
	}
	if err := s.worker.HasBlock(b); err != nil {
		return "", errors.New("blockservice is closed")
	}
	return k, nil
}
开发者ID:noscripter,项目名称:go-ipfs,代码行数:13,代码来源:blockservice.go


示例12: assertBlocksEqual

func assertBlocksEqual(t *testing.T, a, b blocks.Block) {
	if !bytes.Equal(a.RawData(), b.RawData()) {
		t.Fatal("blocks aren't equal")
	}
	if a.Cid() != b.Cid() {
		t.Fatal("block keys aren't equal")
	}
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:8,代码来源:notifications_test.go


示例13: getCmd

func getCmd(nodes []int, block *blocks.Block) error {
	var wg sync.WaitGroup
	for _, node := range nodes {
		wg.Add(1)
		go func(i int) {
			ctx, cancel := context.WithTimeout(context.Background(), deadline)
			defer cancel()

			peers[i].Exchange.GetBlock(ctx, block.Key())
			fmt.Printf("Gotem from node %d.\n", i)
			peers[i].Exchange.Close()
			wg.Done()
		}(node)
	}

	wg.Wait()
	return nil
}
开发者ID:rht,项目名称:bssim,代码行数:18,代码来源:main.go


示例14: updateReceiveCounters

func (bs *Bitswap) updateReceiveCounters(b blocks.Block) error {
	bs.counterLk.Lock()
	defer bs.counterLk.Unlock()
	bs.blocksRecvd++
	has, err := bs.blockstore.Has(b.Cid())
	if err != nil {
		log.Infof("blockstore.Has error: %s", err)
		return err
	}
	if err == nil && has {
		bs.dupBlocksRecvd++
		bs.dupDataRecvd += uint64(len(b.RawData()))
	}

	if has {
		return ErrAlreadyHaveBlock
	}
	return nil
}
开发者ID:tswindell,项目名称:go-ipfs,代码行数:19,代码来源:bitswap.go


示例15: Add

// Add adds a node to the dagService, storing the block in the BlockService
func (n *dagService) Add(nd *Node) (key.Key, error) {
	if n == nil { // FIXME remove this assertion. protect with constructor invariant
		return "", fmt.Errorf("dagService is nil")
	}

	d, err := nd.Encoded(false)
	if err != nil {
		return "", err
	}

	b := new(blocks.Block)
	b.Data = d
	b.Multihash, err = nd.Multihash()
	if err != nil {
		return "", err
	}

	return n.Blocks.AddBlock(b)
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:20,代码来源:merkledag.go


示例16: decodeBlock

func decodeBlock(b blocks.Block) (node.Node, error) {
	c := b.Cid()

	switch c.Type() {
	case cid.Protobuf:
		decnd, err := DecodeProtobuf(b.RawData())
		if err != nil {
			if strings.Contains(err.Error(), "Unmarshal failed") {
				return nil, fmt.Errorf("The block referred to by '%s' was not a valid merkledag node", c)
			}
			return nil, fmt.Errorf("Failed to decode Protocol Buffers: %v", err)
		}

		decnd.cached = b.Cid()
		return decnd, nil
	case cid.Raw:
		return NewRawNode(b.RawData()), nil
	case cid.CBOR:
		return ipldcbor.Decode(b.RawData())
	default:
		return nil, fmt.Errorf("unrecognized object type: %s", c.Type())
	}
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:23,代码来源:merkledag.go


示例17: AddBlock

// AddBlock adds a particular block to the service, Putting it into the datastore.
// TODO pass a context into this if the remote.HasBlock is going to remain here.
func (s *blockService) AddBlock(o blocks.Block) (*cid.Cid, error) {
	c := o.Cid()
	if s.checkFirst {
		has, err := s.blockstore.Has(c)
		if err != nil {
			return nil, err
		}

		if has {
			return c, nil
		}
	}

	err := s.blockstore.Put(o)
	if err != nil {
		return nil, err
	}

	if err := s.exchange.HasBlock(o); err != nil {
		return nil, errors.New("blockservice is closed")
	}

	return c, nil
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:26,代码来源:blockservice.go


示例18: Put

func (b *bloomcache) Put(bl blocks.Block) error {
	if has, ok := b.hasCached(bl.Key()); ok && has {
		return nil
	}

	err := b.blockstore.Put(bl)
	if err == nil {
		b.bloom.AddTS([]byte(bl.Key()))
		b.arc.Add(bl.Key(), true)
	}
	return err
}
开发者ID:yanghongkjxy,项目名称:go-ipfs,代码行数:12,代码来源:bloom_cache.go


示例19: AddBlock

func (m *impl) AddBlock(b blocks.Block) {
	m.blocks[b.Cid().KeyString()] = b
}
开发者ID:tswindell,项目名称:go-ipfs,代码行数:3,代码来源:message.go


示例20: AddBlock

func (m *impl) AddBlock(b blocks.Block) {
	m.blocks[b.Key()] = b
}
开发者ID:ccsblueboy,项目名称:go-ipfs,代码行数:3,代码来源:message.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang blockstore.NewBlockstore函数代码示例发布时间:2022-05-23
下一篇:
Golang blocks.NewBlock函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap