Skip to content

Commit

Permalink
Merge pull request #86 from gfanton/feat/bump-libp2p-17
Browse files Browse the repository at this point in the history
feat: bump to libp2p 0.17.0
  • Loading branch information
glouvigny authored Jan 21, 2022
2 parents 028fc94 + 9cbb682 commit eefbdde
Show file tree
Hide file tree
Showing 9 changed files with 463 additions and 208 deletions.
16 changes: 8 additions & 8 deletions baseorbitdb/orbitdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func NewOrbitDB(ctx context.Context, ipfs coreapi.CoreAPI, options *NewOrbitDBOp
}

if options.Identity == nil {
identity, err := idp.CreateIdentity(&idp.CreateIdentityOptions{
identity, err := idp.CreateIdentity(ctx, &idp.CreateIdentityOptions{
Keystore: options.Keystore,
Type: "orbitdb",
ID: *options.ID,
Expand Down Expand Up @@ -507,14 +507,14 @@ func (o *orbitDB) Create(ctx context.Context, name string, storeType string, opt
}

// Check if we have the database locally
haveDB := o.haveLocalData(c, dbAddress)
haveDB := o.haveLocalData(ctx, c, dbAddress)

if haveDB && (options.Overwrite == nil || !*options.Overwrite) {
return nil, errors.New(fmt.Sprintf("database %s already exists", dbAddress))
}

// Save the database locally
if err := o.addManifestToCache(o.directory, dbAddress); err != nil {
if err := o.addManifestToCache(ctx, o.directory, dbAddress); err != nil {
return nil, errors.Wrap(err, "unable to add manifest to cache")
}

Expand Down Expand Up @@ -582,7 +582,7 @@ func (o *orbitDB) Open(ctx context.Context, dbAddress string, options *CreateDBO
return nil, errors.Wrap(err, "unable to acquire cache")
}

haveDB := o.haveLocalData(dbCache, parsedDBAddress)
haveDB := o.haveLocalData(ctx, dbCache, parsedDBAddress)
if *options.LocalOnly && !haveDB {
return nil, errors.New(fmt.Sprintf("database %s doesn't exist!", dbAddress))
}
Expand Down Expand Up @@ -665,15 +665,15 @@ func (o *orbitDB) loadCache(directory string, dbAddress address.Address) (datast
return db, nil
}

func (o *orbitDB) haveLocalData(c datastore.Datastore, dbAddress address.Address) bool {
func (o *orbitDB) haveLocalData(ctx context.Context, c datastore.Datastore, dbAddress address.Address) bool {
if c == nil {
o.logger.Debug("haveLocalData: no cache provided")
return false
}

cacheKey := datastore.NewKey(path.Join(dbAddress.String(), "_manifest"))

data, err := c.Get(cacheKey)
data, err := c.Get(ctx, cacheKey)
if err != nil {
if err != datastore.ErrNotFound {
o.logger.Error("haveLocalData: error while getting value from cache", zap.Error(err))
Expand All @@ -685,15 +685,15 @@ func (o *orbitDB) haveLocalData(c datastore.Datastore, dbAddress address.Address
return data != nil
}

func (o *orbitDB) addManifestToCache(directory string, dbAddress address.Address) error {
func (o *orbitDB) addManifestToCache(ctx context.Context, directory string, dbAddress address.Address) error {
c, err := o.loadCache(directory, dbAddress)
if err != nil {
return errors.Wrap(err, "unable to load existing cache")
}

cacheKey := datastore.NewKey(path.Join(dbAddress.String(), "_manifest"))

if err := c.Put(cacheKey, []byte(dbAddress.GetRoot().String())); err != nil {
if err := c.Put(ctx, cacheKey, []byte(dbAddress.GetRoot().String())); err != nil {
return errors.Wrap(err, "unable to set cache")
}

Expand Down
29 changes: 15 additions & 14 deletions cache/cacheleveldown/leveldown.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cacheleveldown

import (
"context"
"os"
"path"
"sync"
Expand Down Expand Up @@ -29,32 +30,32 @@ type wrappedCache struct {
closed bool
}

func (w *wrappedCache) Get(key datastore.Key) (value []byte, err error) {
return w.wrappedCache.Get(key)
func (w *wrappedCache) Get(ctx context.Context, key datastore.Key) (value []byte, err error) {
return w.wrappedCache.Get(ctx, key)
}

func (w *wrappedCache) Has(key datastore.Key) (exists bool, err error) {
return w.wrappedCache.Has(key)
func (w *wrappedCache) Has(ctx context.Context, key datastore.Key) (exists bool, err error) {
return w.wrappedCache.Has(ctx, key)
}

func (w *wrappedCache) GetSize(key datastore.Key) (size int, err error) {
return w.wrappedCache.GetSize(key)
func (w *wrappedCache) GetSize(ctx context.Context, key datastore.Key) (size int, err error) {
return w.wrappedCache.GetSize(ctx, key)
}

func (w *wrappedCache) Query(q query.Query) (query.Results, error) {
return w.wrappedCache.Query(q)
func (w *wrappedCache) Query(ctx context.Context, q query.Query) (query.Results, error) {
return w.wrappedCache.Query(ctx, q)
}

func (w *wrappedCache) Put(key datastore.Key, value []byte) error {
return w.wrappedCache.Put(key, value)
func (w *wrappedCache) Put(ctx context.Context, key datastore.Key, value []byte) error {
return w.wrappedCache.Put(ctx, key, value)
}

func (w *wrappedCache) Delete(key datastore.Key) error {
return w.wrappedCache.Delete(key)
func (w *wrappedCache) Delete(ctx context.Context, key datastore.Key) error {
return w.wrappedCache.Delete(ctx, key)
}

func (w *wrappedCache) Sync(key datastore.Key) error {
return w.wrappedCache.Sync(key)
func (w *wrappedCache) Sync(ctx context.Context, key datastore.Key) error {
return w.wrappedCache.Sync(ctx, key)
}

func (w *wrappedCache) Close() error {
Expand Down
28 changes: 15 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ module berty.tech/go-orbit-db
go 1.16

require (
berty.tech/go-ipfs-log v1.5.0
berty.tech/go-ipfs-log v1.6.0
github.com/golang-collections/go-datastructures v0.0.0-20150211160725-59788d5eb259
github.com/golang/snappy v0.0.1 // indirect
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-datastore v0.4.5
github.com/ipfs/go-ds-leveldb v0.4.2
github.com/ipfs/go-ipfs v0.9.1
github.com/ipfs/go-ipfs-files v0.0.8
github.com/ipfs/go-ipld-cbor v0.0.5
github.com/ipfs/interface-go-ipfs-core v0.4.0
github.com/libp2p/go-libp2p v0.14.3
github.com/libp2p/go-libp2p-core v0.8.5
github.com/libp2p/go-libp2p-pubsub v0.4.2
github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f // indirect
github.com/ipfs/go-cid v0.1.0
github.com/ipfs/go-datastore v0.5.1
github.com/ipfs/go-ds-leveldb v0.5.0
github.com/ipfs/go-ipfs v0.11.0
github.com/ipfs/go-ipfs-files v0.0.9
github.com/ipfs/go-ipld-cbor v0.0.6
github.com/ipfs/interface-go-ipfs-core v0.5.2
github.com/libp2p/go-libp2p v0.17.0
github.com/libp2p/go-libp2p-core v0.13.0
github.com/libp2p/go-libp2p-pubsub v0.6.0
github.com/pkg/errors v0.9.1
github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/otel v0.20.0
go.opentelemetry.io/otel/trace v0.20.0
go.uber.org/goleak v1.1.10
go.uber.org/zap v1.16.0
go.uber.org/goleak v1.1.11
go.uber.org/zap v1.19.1
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
)
Loading

0 comments on commit eefbdde

Please sign in to comment.