mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-26 23:53:19 +08:00
+ fs ds + thread safe
This commit is contained in:
@ -43,7 +43,7 @@ type IpfsNode struct {
|
|||||||
Peerstore peer.Peerstore
|
Peerstore peer.Peerstore
|
||||||
|
|
||||||
// the local datastore
|
// the local datastore
|
||||||
Datastore ds.Datastore
|
Datastore ds.ThreadSafeDatastore
|
||||||
|
|
||||||
// the network message stream
|
// the network message stream
|
||||||
Network inet.Network
|
Network inet.Network
|
||||||
|
@ -4,11 +4,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
|
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"
|
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"
|
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 {
|
if len(cfg.Type) == 0 {
|
||||||
return nil, fmt.Errorf("config datastore.type required")
|
return nil, fmt.Errorf("config datastore.type required")
|
||||||
}
|
}
|
||||||
@ -16,14 +18,23 @@ func makeDatastore(cfg config.Datastore) (ds.Datastore, error) {
|
|||||||
switch cfg.Type {
|
switch cfg.Type {
|
||||||
case "leveldb":
|
case "leveldb":
|
||||||
return makeLevelDBDatastore(cfg)
|
return makeLevelDBDatastore(cfg)
|
||||||
|
|
||||||
case "memory":
|
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)
|
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 {
|
if len(cfg.Path) == 0 {
|
||||||
return nil, fmt.Errorf("config datastore.path required for leveldb")
|
return nil, fmt.Errorf("config datastore.path required for leveldb")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user