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


Golang Key.DsKey方法代碼示例

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


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

示例1: AddBlock

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

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

示例2: putRoutingRecord

func putRoutingRecord(ds datastore.Datastore, k key.Key, value *dhtpb.Record) error {
	data, err := proto.Marshal(value)
	if err != nil {
		return err
	}
	dskey := k.DsKey()
	// TODO namespace
	if err := ds.Put(dskey, data); err != nil {
		return err
	}
	return nil
}
開發者ID:djbarber,項目名稱:ipfs-hack,代碼行數:12,代碼來源:server.go

示例3: Get

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

	return blocks.NewBlockWithHash(bdata, mh.Multihash(k))
}
開發者ID:djbarber,項目名稱:ipfs-hack,代碼行數:15,代碼來源:blockstore.go

示例4: getRoutingRecord

func getRoutingRecord(ds datastore.Datastore, k key.Key) (*dhtpb.Record, error) {
	dskey := k.DsKey()
	val, err := ds.Get(dskey)
	if err != nil {
		return nil, err
	}
	recordBytes, ok := val.([]byte)
	if !ok {
		return nil, fmt.Errorf("datastore had non byte-slice value for %v", dskey)
	}
	var record dhtpb.Record
	if err := proto.Unmarshal(recordBytes, &record); err != nil {
		return nil, errors.New("failed to unmarshal dht record from datastore")
	}
	return &record, nil
}
開發者ID:djbarber,項目名稱:ipfs-hack,代碼行數:16,代碼來源:server.go

示例5: getLocal

// getLocal attempts to retrieve the value from the datastore
func (dht *IpfsDHT) getLocal(key key.Key) ([]byte, error) {

	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.verifyRecordLocally(rec)
		if err != nil {
			log.Debugf("local record verify failed: %s (discarded)", err)
			return nil, err
		}
	}

	return rec.GetValue(), nil
}
開發者ID:djbarber,項目名稱:ipfs-hack,代碼行數:31,代碼來源:dht.go

示例6: putLocal

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

	return dht.datastore.Put(key.DsKey(), data)
}
開發者ID:djbarber,項目名稱:ipfs-hack,代碼行數:9,代碼來源:dht.go

示例7: PutValue

func (c *offlineRouting) PutValue(ctx context.Context, key key.Key, val []byte) error {
	rec, err := record.MakePutRecord(c.sk, key, val, false)
	if err != nil {
		return err
	}
	data, err := proto.Marshal(rec)
	if err != nil {
		return err
	}

	return c.datastore.Put(key.DsKey(), data)
}
開發者ID:djbarber,項目名稱:ipfs-hack,代碼行數:12,代碼來源:offline.go

示例8: GetValue

// FIXME(brian): is this method meant to simulate getting a value from the network?
func (c *client) GetValue(ctx context.Context, key key.Key) ([]byte, error) {
	log.Debugf("GetValue: %s", key)
	v, err := c.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:djbarber,項目名稱:ipfs-hack,代碼行數:15,代碼來源:centralized_client.go

示例9: GetValue

func (c *offlineRouting) GetValue(ctx context.Context, key key.Key) ([]byte, error) {
	v, err := c.datastore.Get(key.DsKey())
	if err != nil {
		return nil, err
	}

	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
	}

	return rec.GetValue(), nil
}
開發者ID:djbarber,項目名稱:ipfs-hack,代碼行數:18,代碼來源:offline.go

示例10: RemoveBlock

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

示例11: Has

func (bs *blockstore) Has(k key.Key) (bool, error) {
	return bs.datastore.Has(k.DsKey())
}
開發者ID:djbarber,項目名稱:ipfs-hack,代碼行數:3,代碼來源:blockstore.go

示例12: DeleteBlock

func (s *blockstore) DeleteBlock(k key.Key) error {
	return s.datastore.Delete(k.DsKey())
}
開發者ID:djbarber,項目名稱:ipfs-hack,代碼行數:3,代碼來源:blockstore.go

示例13: PutValue

// FIXME(brian): is this method meant to simulate putting a value into the network?
func (c *client) PutValue(ctx context.Context, key key.Key, val []byte) error {
	log.Debugf("PutValue: %s", key)
	return c.datastore.Put(key.DsKey(), val)
}
開發者ID:djbarber,項目名稱:ipfs-hack,代碼行數:5,代碼來源:centralized_client.go


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