Commit dc6fdd39 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

use encoded (pretty) keys only on fs ds

parent 0ffc2038
......@@ -5,9 +5,12 @@ import (
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
fsds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/fs"
ktds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/keytransform"
lds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/leveldb"
syncds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/sync"
config "github.com/jbenet/go-ipfs/config"
u "github.com/jbenet/go-ipfs/util"
)
func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
......@@ -28,7 +31,8 @@ func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
if err != nil {
return nil, err
}
return syncds.MutexWrap(d), nil
ktd := ktds.WrapDatastore(d, u.DsKeyB58Encode)
return syncds.MutexWrap(ktd), nil
}
return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type)
......
......@@ -55,14 +55,34 @@ func (k Key) Pretty() string {
// DsKey returns a Datastore key
func (k Key) DsKey() ds.Key {
return ds.NewKey(k.Pretty())
return ds.NewKey(string(k))
}
// KeyFromDsKey returns a Datastore key
func KeyFromDsKey(dsk ds.Key) Key {
l := dsk.List()
enc := l[len(l)-1]
return Key(b58.Decode(enc))
return Key(dsk.BaseNamespace())
}
// DsKeyB58Encode returns a B58 encoded Datastore key
// TODO: this is hacky because it encodes every path component. some
// path components may be proper strings already...
func DsKeyB58Encode(dsk ds.Key) ds.Key {
k := ds.NewKey("/")
for _, n := range dsk.Namespaces() {
k = k.Child(b58.Encode([]byte(n)))
}
return k
}
// DsKeyB58Decode returns a b58 decoded Datastore key
// TODO: this is hacky because it encodes every path component. some
// path components may be proper strings already...
func DsKeyB58Decode(dsk ds.Key) ds.Key {
k := ds.NewKey("/")
for _, n := range dsk.Namespaces() {
k = k.Child(string(b58.Decode(n)))
}
return k
}
// Hash is the global IPFS hash function. uses multihash SHA2_256, 256 bits
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment