func testNotHas(t *testing.T, d ds.Datastore, k ds.Key) { if _, err := d.Get(k); err == nil { t.Error("should not have it", d, k) } if has, err := d.Has(k); err != nil { t.Error(err) } else if has { t.Error("should not have it", d, k) } }
func loadSet(d ds.Datastore, k ds.Key, val interface{}) error { buf, err := d.Get(k) if err != nil { return err } bf, ok := buf.([]byte) if !ok { return errors.New("invalid pin set value in datastore") } return json.Unmarshal(bf, val) }
func testHas(t *testing.T, d ds.Datastore, k ds.Key, v interface{}) { if v2, err := d.Get(k); err != nil { t.Error(err) } else if v2 != v { t.Error("value incorrect", d, k, v, v2) } if has, err := d.Has(k); err != nil { t.Error(err) } else if !has { t.Error("should have it", d, k, v) } }
func getRoutingProviders(ds datastore.Datastore, k key.Key) ([]*dhtpb.Message_Peer, error) { e := log.EventBegin(context.Background(), "getProviders", &k) defer e.Done() var providers []*dhtpb.Message_Peer if v, err := ds.Get(providerKey(k)); err == nil { if data, ok := v.([]byte); ok { var msg dhtpb.Message if err := proto.Unmarshal(data, &msg); err != nil { return nil, err } providers = append(providers, msg.GetProviderPeers()...) } } return providers, nil }
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 }