當前位置: 首頁>>代碼示例>>Golang>>正文


Golang blocks.Block類代碼示例

本文整理匯總了Golang中github.com/maybebtc/interplanetary/Godeps/_workspace/src/github.com/jbenet/go-ipfs/blocks.Block的典型用法代碼示例。如果您正苦於以下問題:Golang Block類的具體用法?Golang Block怎麽用?Golang Block使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Block類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: AddBlock

// AddBlock adds a particular block to the service, Putting it into the datastore.
func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
	k := b.Key()
	log.Debugf("blockservice: storing [%s] in datastore", k)
	// TODO(brian): define a block datastore with a Put method which accepts a
	// block parameter

	// check if we have it before adding. this is an extra read, but large writes
	// are more expensive.
	// TODO(jbenet) cheaper has. https://github.com/jbenet/go-datastore/issues/6
	has, err := s.Datastore.Has(k.DsKey())
	if err != nil {
		return k, err
	}
	if has {
		log.Debugf("blockservice: storing [%s] in datastore (already stored)", k)
	} else {
		log.Debugf("blockservice: storing [%s] in datastore", k)
		err := s.Datastore.Put(k.DsKey(), b.Data)
		if err != nil {
			return k, err
		}
	}

	if s.Remote != nil {
		ctx := context.TODO()
		err = s.Remote.HasBlock(ctx, *b)
	}
	return k, err
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:30,代碼來源:blockservice.go

示例2: assertBlocksEqual

func assertBlocksEqual(t *testing.T, a, b blocks.Block) {
	if !bytes.Equal(a.Data, b.Data) {
		t.Fail()
	}
	if a.Key() != b.Key() {
		t.Fail()
	}
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數: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.Block(context.Background(), b.Key())
		if err != nil {
			t.Fatal(err)
		}
	}
	wg.Done()
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:9,代碼來源:bitswap_test.go

示例4: Add

// Add adds a node to the dagService, storing the block in the BlockService
func (n *dagService) Add(nd *Node) (u.Key, error) {
	k, _ := nd.Key()
	log.Debugf("DagService Add [%s]", k)
	if n == nil {
		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:carriercomm,項目名稱:interplanetary,代碼行數:22,代碼來源:merkledag.go

示例5: sendToPeersThatWant

func (bs *bitswap) sendToPeersThatWant(ctx context.Context, block blocks.Block) {
	log.Debugf("Sending %v to peers that want it", block.Key())

	for _, p := range bs.strategy.Peers() {
		if bs.strategy.BlockIsWantedByPeer(block.Key(), p) {
			log.Debugf("%v wants %v", p, block.Key())
			if bs.strategy.ShouldSendBlockToPeer(block.Key(), p) {
				message := bsmsg.New()
				message.AddBlock(block)
				for _, wanted := range bs.wantlist.Keys() {
					message.AddWanted(wanted)
				}
				bs.send(ctx, p, message)
			}
		}
	}
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:17,代碼來源:bitswap.go

示例6: Put

func (bs *blockstore) Put(block *blocks.Block) error {
	return bs.datastore.Put(block.Key().DsKey(), block.Data)
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:3,代碼來源:blockstore.go

示例7: HasBlock

// HasBlock announces the existance of a block to this bitswap service. The
// service will potentially notify its peers.
func (bs *bitswap) HasBlock(ctx context.Context, blk blocks.Block) error {
	log.Debugf("Has Block %v", blk.Key())
	bs.wantlist.Remove(blk.Key())
	bs.sendToPeersThatWant(ctx, blk)
	return bs.routing.Provide(ctx, blk.Key())
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:8,代碼來源:bitswap.go

示例8: Publish

func (ps *impl) Publish(block blocks.Block) {
	topic := string(block.Key())
	ps.wrapped.Pub(block, topic)
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:4,代碼來源:notifications.go

示例9: AddBlock

func (m *impl) AddBlock(b blocks.Block) {
	m.blocks[b.Key()] = b
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:3,代碼來源:message.go


注:本文中的github.com/maybebtc/interplanetary/Godeps/_workspace/src/github.com/jbenet/go-ipfs/blocks.Block類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。