Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions baseorbitdb/keystore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//go:build !js

package baseorbitdb

import (
"fmt"
"path"

"berty.tech/go-ipfs-log/keystore"
"berty.tech/go-orbit-db/cache/cacheleveldown"
leveldb "github.com/ipfs/go-ds-leveldb"
"github.com/libp2p/go-libp2p/core/peer"
)

func NewKeystore(id peer.ID, directory string) (*keystore.Keystore, func() error, error) {
var err error
var ds *leveldb.Datastore

// create new datastore
if directory == cacheleveldown.InMemoryDirectory {
ds, err = leveldb.NewDatastore("", nil)
} else {
ds, err = leveldb.NewDatastore(path.Join(directory, id.String(), "/keystore"), nil)
}

if err != nil {
return nil, nil, fmt.Errorf("unable to create data store used by keystore: %w", err)
}

ks, err := keystore.NewKeystore(ds)
if err != nil {
return nil, nil, fmt.Errorf("unable to create keystore: %w", err)
}

return ks, ds.Close, nil
}
14 changes: 14 additions & 0 deletions baseorbitdb/keystore_js.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build js

package baseorbitdb

import (
"errors"

"berty.tech/go-ipfs-log/keystore"
"github.com/libp2p/go-libp2p/core/peer"
)

func NewKeystore(id peer.ID, directory string) (*keystore.Keystore, func() error, error) {
return nil, nil, errors.New("can't create default keystore in js")
}
23 changes: 4 additions & 19 deletions baseorbitdb/orbitdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"berty.tech/go-orbit-db/utils"
cid "github.com/ipfs/go-cid"
datastore "github.com/ipfs/go-datastore"
leveldb "github.com/ipfs/go-ds-leveldb"

cbornode "github.com/ipfs/go-ipld-cbor"
coreapi "github.com/ipfs/interface-go-ipfs-core"
"github.com/libp2p/go-libp2p/core/event"
Expand Down Expand Up @@ -429,27 +429,12 @@ func NewOrbitDB(ctx context.Context, ipfs coreapi.CoreAPI, options *NewOrbitDBOp
}

if options.Keystore == nil {
var err error
var ds *leveldb.Datastore

// create new datastore
if *options.Directory == cacheleveldown.InMemoryDirectory {
ds, err = leveldb.NewDatastore("", nil)
} else {
ds, err = leveldb.NewDatastore(path.Join(*options.Directory, id.String(), "/keystore"), nil)
}

ks, closeKeystore, err := NewKeystore(id, *options.Directory)
if err != nil {
return nil, fmt.Errorf("unable to create data store used by keystore: %w", err)
}

ks, err := keystore.NewKeystore(ds)
if err != nil {
return nil, fmt.Errorf("unable to create keystore: %w", err)
return nil, err
}

options.Keystore = ks
options.CloseKeystore = ds.Close
options.CloseKeystore = closeKeystore
}

if options.ID == nil {
Expand Down
3 changes: 3 additions & 0 deletions cache/cacheleveldown/leveldown.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js

package cacheleveldown

import (
Expand All @@ -11,6 +13,7 @@ import (
"berty.tech/go-orbit-db/cache"
datastore "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/query"

leveldb "github.com/ipfs/go-ds-leveldb"
"go.uber.org/zap"
)
Expand Down
14 changes: 14 additions & 0 deletions cache/cacheleveldown/leveldown_js.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build js

package cacheleveldown

import (
"berty.tech/go-orbit-db/cache"
)

var InMemoryDirectory = ":memory:"

// New Creates a new leveldb data store
func New(opts *cache.Options) cache.Interface {
panic("cacheleveldown not implemented in js")
}
2 changes: 2 additions & 0 deletions tests/create_open_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js

package tests

import (
Expand Down
2 changes: 2 additions & 0 deletions tests/docs_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js

package tests

import (
Expand Down
2 changes: 2 additions & 0 deletions tests/eventlog_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js

package tests

import (
Expand Down
2 changes: 2 additions & 0 deletions tests/keyvalue_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js

package tests

import (
Expand Down
2 changes: 2 additions & 0 deletions tests/persistence_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js

package tests

import (
Expand Down
2 changes: 2 additions & 0 deletions tests/replicate_automatically_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js

package tests

import (
Expand Down
4 changes: 3 additions & 1 deletion tests/replicate_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js

package tests

import (
Expand All @@ -15,8 +17,8 @@ import (
"berty.tech/go-orbit-db/pubsub/pubsubraw"
orbitstores "berty.tech/go-orbit-db/stores"
"berty.tech/go-orbit-db/stores/operation"
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
"github.com/libp2p/go-libp2p/core/event"
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 2 additions & 0 deletions tests/replication_status_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js

package tests

import (
Expand Down
2 changes: 2 additions & 0 deletions tests/testing_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js

package tests

import (
Expand Down
2 changes: 2 additions & 0 deletions tests/write_permissions_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !js

package tests

import (
Expand Down