本文整理汇总了Golang中github.com/ipfs/go-ipfs/blocks.Block.Key方法的典型用法代码示例。如果您正苦于以下问题:Golang Block.Key方法的具体用法?Golang Block.Key怎么用?Golang Block.Key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ipfs/go-ipfs/blocks.Block
的用法示例。
在下文中一共展示了Block.Key方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例2: 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")
}
}
示例3: 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()
}
示例4: 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
}
}
示例5: 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)
}
示例6: 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)
}
示例7: 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
}
示例8: 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
}
示例9: updateReceiveCounters
func (bs *Bitswap) updateReceiveCounters(b *blocks.Block) error {
bs.counterLk.Lock()
defer bs.counterLk.Unlock()
bs.blocksRecvd++
has, err := bs.blockstore.Has(b.Key())
if err != nil {
log.Infof("blockstore.Has error: %s", err)
return err
}
if err == nil && has {
bs.dupBlocksRecvd++
bs.dupDataRecvd += uint64(len(b.Data))
}
if has {
return ErrAlreadyHaveBlock
}
return nil
}
示例10: 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
}
示例11: AddBlock
func (m *impl) AddBlock(b blocks.Block) {
m.blocks[b.Key()] = b
}
示例12: Publish
func (ps *impl) Publish(block *blocks.Block) {
topic := string(block.Key())
ps.wrapped.Pub(block, topic)
}