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


Golang Key.DsKey方法代碼示例

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


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

示例1: GetBlock

// GetBlock retrieves a particular block from the service,
// Getting it from the datastore using the key (hash).
func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, error) {
	log.Debugf("BlockService GetBlock: '%s'", k)
	datai, err := s.Datastore.Get(k.DsKey())
	if err == nil {
		log.Debug("Blockservice: Got data in datastore.")
		bdata, ok := datai.([]byte)
		if !ok {
			return nil, fmt.Errorf("data associated with %s is not a []byte", k)
		}
		return &blocks.Block{
			Multihash: mh.Multihash(k),
			Data:      bdata,
		}, nil
	} else if err == ds.ErrNotFound && s.Remote != nil {
		log.Debug("Blockservice: Searching bitswap.")
		blk, err := s.Remote.Block(ctx, k)
		if err != nil {
			return nil, err
		}
		return blk, nil
	} else {
		log.Debug("Blockservice GetBlock: Not found.")
		return nil, ErrNotFound
	}
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:27,代碼來源:blockservice.go

示例2: getLocal

// getLocal attempts to retrieve the value from the datastore
func (dht *IpfsDHT) getLocal(key u.Key) ([]byte, error) {
	dht.dslock.Lock()
	defer dht.dslock.Unlock()
	log.Debug("getLocal %s", key)
	v, err := dht.datastore.Get(key.DsKey())
	if err != nil {
		return nil, err
	}
	log.Debug("found in db")

	byt, ok := v.([]byte)
	if !ok {
		return nil, errors.New("value stored in datastore not []byte")
	}
	rec := new(pb.Record)
	err = proto.Unmarshal(byt, rec)
	if err != nil {
		return nil, err
	}

	// TODO: 'if paranoid'
	if u.Debug {
		err = dht.verifyRecord(rec)
		if err != nil {
			log.Errorf("local record verify failed: %s", err)
			return nil, err
		}
	}

	return rec.GetValue(), nil
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:32,代碼來源:dht.go

示例3: AddBlock

func (d *datastoreBlockSet) AddBlock(k util.Key) {
	err := d.dstore.Put(k.DsKey(), []byte{})
	if err != nil {
		log.Errorf("blockset put error: %s", err)
	}

	d.bset.AddBlock(k)
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:8,代碼來源:dbset.go

示例4: Get

func (bs *blockstore) Get(k u.Key) (*blocks.Block, error) {
	maybeData, err := bs.datastore.Get(k.DsKey())
	if err != nil {
		return nil, err
	}
	bdata, ok := maybeData.([]byte)
	if !ok {
		return nil, ValueTypeMismatch
	}

	return blocks.NewBlockWithHash(bdata, mh.Multihash(k))
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:12,代碼來源:blockstore.go

示例5: putLocal

// putLocal stores the key value pair in the datastore
func (dht *IpfsDHT) putLocal(key u.Key, value []byte) error {
	rec, err := dht.makePutRecord(key, value)
	if err != nil {
		return err
	}
	data, err := proto.Marshal(rec)
	if err != nil {
		return err
	}

	return dht.datastore.Put(key.DsKey(), data)
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:13,代碼來源:dht.go

示例6: GetValue

func (mr *MockRouter) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
	log.Debugf("GetValue: %s", key)
	v, err := mr.datastore.Get(key.DsKey())
	if err != nil {
		return nil, err
	}

	data, ok := v.([]byte)
	if !ok {
		return nil, errors.New("could not cast value from datastore")
	}

	return data, nil
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:14,代碼來源:routing.go

示例7: RemoveBlock

func (d *datastoreBlockSet) RemoveBlock(k util.Key) {
	d.bset.RemoveBlock(k)
	if !d.bset.HasKey(k) {
		d.dstore.Delete(k.DsKey())
	}
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:6,代碼來源:dbset.go

示例8: PutValue

func (mr *MockRouter) PutValue(ctx context.Context, key u.Key, val []byte) error {
	log.Debugf("PutValue: %s", key)
	return mr.datastore.Put(key.DsKey(), val)
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:4,代碼來源:routing.go

示例9: DeleteBlock

// DeleteBlock deletes a block in the blockservice from the datastore
func (s *BlockService) DeleteBlock(k u.Key) error {
	return s.Datastore.Delete(k.DsKey())
}
開發者ID:carriercomm,項目名稱:interplanetary,代碼行數:4,代碼來源:blockservice.go


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