本文整理汇总了Golang中github.com/djbarber/ipfs-hack/blocks.Block类的典型用法代码示例。如果您正苦于以下问题:Golang Block类的具体用法?Golang Block怎么用?Golang Block使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Block类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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:djbarber,项目名称:ipfs-hack,代码行数:7,代码来源:write_cache.go
示例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")
}
}
开发者ID:djbarber,项目名称:ipfs-hack,代码行数: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.Key()); err != nil {
_, err := bitswap.Exchange.GetBlock(context.Background(), b.Key())
if err != nil {
t.Fatal(err)
}
}
wg.Done()
}
开发者ID:djbarber,项目名称:ipfs-hack,代码行数:9,代码来源:bitswap_test.go
示例4: 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:djbarber,项目名称:ipfs-hack,代码行数:10,代码来源:blockstore.go
示例5: 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.Exchange.HasBlock(b); err != nil {
return "", errors.New("blockservice is closed")
}
return k, nil
}
开发者ID:djbarber,项目名称:ipfs-hack,代码行数:13,代码来源:blockservice.go
示例6: 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:djbarber,项目名称:ipfs-hack,代码行数:20,代码来源:merkledag.go
示例7: 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
}
开发者ID:djbarber,项目名称:ipfs-hack,代码行数:19,代码来源:bitswap.go
示例8: AddBlock
func (m *impl) AddBlock(b *blocks.Block) {
m.blocks[b.Key()] = b
}
开发者ID:djbarber,项目名称:ipfs-hack,代码行数:3,代码来源:message.go
示例9: Publish
func (ps *impl) Publish(block *blocks.Block) {
topic := string(block.Key())
ps.wrapped.Pub(block, topic)
}
开发者ID:djbarber,项目名称:ipfs-hack,代码行数:4,代码来源:notifications.go
注:本文中的github.com/djbarber/ipfs-hack/blocks.Block类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论