Skip to content

Commit

Permalink
chore: use threadsafe p2p datastore to avoid race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Sep 12, 2018
1 parent 8c36b70 commit ad6b071
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/network/p2p/p2p.go
Expand Up @@ -8,6 +8,7 @@ import (

cid "github.com/ipfs/go-cid"
datastore "github.com/ipfs/go-datastore"
syncdatastore "github.com/ipfs/go-datastore/sync"
ipfsaddr "github.com/ipfs/go-ipfs-addr"
libp2p "github.com/libp2p/go-libp2p"
host "github.com/libp2p/go-libp2p-host"
Expand Down Expand Up @@ -73,7 +74,8 @@ func newDriver(ctx context.Context, cfg driverConfig) (*Driver, error) {
host: host,
}

ds := datastore.NewMapDatastore()
ds := syncdatastore.MutexWrap(datastore.NewMapDatastore())

if len(cfg.dhtOpts) == 0 {
cfg.dhtOpts = []dhtopt.Option{dhtopt.Datastore(ds)}
}
Expand Down

0 comments on commit ad6b071

Please sign in to comment.