mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-25 23:21:54 +08:00
+ fs ds + thread safe
This commit is contained in:
@ -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")
|
||||
}
|
||||
|
Reference in New Issue
Block a user