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


Golang Block.Cid方法代码示例

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


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

示例1: 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

示例2: 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

示例3: getOrFail

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

示例4: 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

示例5: 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

示例6: 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

示例7: addBlock

func (e *Engine) addBlock(block blocks.Block) {
	work := false

	for _, l := range e.ledgerMap {
		l.lk.Lock()
		if entry, ok := l.WantListContains(block.Cid()); ok {
			e.peerRequestQueue.Push(entry, l.Partner)
			work = true
		}
		l.lk.Unlock()
	}

	if work {
		e.signalNewWork()
	}
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:16,代码来源:engine.go

示例8: 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

示例9: 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

示例10: 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

示例11: DeleteBlock

// DeleteBlock deletes a block in the blockservice from the datastore
func (s *blockService) DeleteBlock(o blocks.Block) error {
	return s.blockstore.DeleteBlock(o.Cid())
}
开发者ID:qnib,项目名称:go-ipfs,代码行数:4,代码来源:blockservice.go

示例12: Publish

func (ps *impl) Publish(block blocks.Block) {
	ps.wrapped.Pub(block, block.Cid().KeyString())
}
开发者ID:VictorBjelkholm,项目名称:go-ipfs,代码行数:3,代码来源:notifications.go

示例13: AddBlock

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


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