Commit 2ce9415c authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

+ fs ds + thread safe

parent 88d804e3
......@@ -43,7 +43,7 @@ type IpfsNode struct {
Peerstore peer.Peerstore
// the local datastore
Datastore ds.Datastore
Datastore ds.ThreadSafeDatastore
// the network message stream
Network inet.Network
......
......@@ -4,11 +4,13 @@ import (
"fmt"
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"
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"
)
func makeDatastore(cfg config.Datastore) (ds.Datastore, error) {
func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
if len(cfg.Type) == 0 {
return nil, fmt.Errorf("config datastore.type required")
}
......@@ -16,14 +18,23 @@ func makeDatastore(cfg config.Datastore) (ds.Datastore, error) {
switch cfg.Type {
case "leveldb":
return makeLevelDBDatastore(cfg)
case "memory":
return ds.NewMapDatastore(), nil
return syncds.MutexWrap(ds.NewMapDatastore()), nil
case "fs":
log.Warning("using fs.Datastore at .datastore for testing.")
d, err := fsds.NewDatastore(".datastore") // for testing!!
if err != nil {
return nil, err
}
return syncds.MutexWrap(d), nil
}
return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type)
}
func makeLevelDBDatastore(cfg config.Datastore) (ds.Datastore, error) {
func makeLevelDBDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
if len(cfg.Path) == 0 {
return nil, fmt.Errorf("config datastore.path required for leveldb")
}
......
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