@cryptotaxi247 / kubo / commits / 2ce9415c6

+ fs ds + thread safe

Juan Batiz-Benet committed Oct 3, 2014 at 14:45 UTC 2ce9415c6934ba882f16302620c2ac5f93c2a9a3
2 files changed +15 -4
core/core.go
+1 -1
@@ -43,7 +43,7 @@ type IpfsNode struct {
43 Peerstore peer.Peerstore
44
45 // the local datastore
46 - Datastore ds.Datastore
46 + Datastore ds.ThreadSafeDatastore
47
48 // the network message stream
49 Network inet.Network
core/datastore.go
+14 -3
@@ -4,11 +4,13 @@ import (
4 "fmt"
5
6 ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
7 + fsds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/fs"
8 lds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/leveldb"
9 + syncds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/sync"
10 config "github.com/jbenet/go-ipfs/config"
11 )
12
11 -func makeDatastore(cfg config.Datastore) (ds.Datastore, error) {
13 +func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
14 if len(cfg.Type) == 0 {
15 return nil, fmt.Errorf("config datastore.type required")
16 }
@@ -16,14 +18,23 @@ func makeDatastore(cfg config.Datastore) (ds.Datastore, error) {
18 switch cfg.Type {
19 case "leveldb":
20 return makeLevelDBDatastore(cfg)
21 +
22 case "memory":
20 - return ds.NewMapDatastore(), nil
23 + return syncds.MutexWrap(ds.NewMapDatastore()), nil
24 +
25 + case "fs":
26 + log.Warning("using fs.Datastore at .datastore for testing.")
27 + d, err := fsds.NewDatastore(".datastore") // for testing!!
28 + if err != nil {
29 + return nil, err
30 + }
31 + return syncds.MutexWrap(d), nil
32 }
33
34 return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type)
35 }
36
26 -func makeLevelDBDatastore(cfg config.Datastore) (ds.Datastore, error) {
37 +func makeLevelDBDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
38 if len(cfg.Path) == 0 {
39 return nil, fmt.Errorf("config datastore.path required for leveldb")
40 }