Пример #1
0
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
0
// 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
}
Пример #3
0
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
}
Пример #4
0
func (m *impl) AddBlock(b *blocks.Block) {
	m.blocks[b.Key()] = b
}
Пример #5
0
func (ps *impl) Publish(block *blocks.Block) {
	topic := string(block.Key())
	ps.wrapped.Pub(block, topic)
}