From 2ce9415c6934ba882f16302620c2ac5f93c2a9a3 Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Fri, 3 Oct 2014 14:45:15 -0700 Subject: [PATCH] + fs ds + thread safe --- core/core.go | 2 +- core/datastore.go | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/core.go b/core/core.go index decec6307..8fa209bba 100644 --- a/core/core.go +++ b/core/core.go @@ -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 diff --git a/core/datastore.go b/core/datastore.go index 9105adaab..30f92c8e8 100644 --- a/core/datastore.go +++ b/core/datastore.go @@ -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") }