Skip to content

Commit

Permalink
feat: added tracer to orbitdb
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Louvigny <glouvigny@users.noreply.github.com>
  • Loading branch information
glouvigny authored and gfanton committed Jun 10, 2020
1 parent d39af6b commit 2e26044
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
5 changes: 5 additions & 0 deletions go/pkg/bertyprotocol/orbitdb.go
Expand Up @@ -14,6 +14,7 @@ import (
coreapi "github.com/ipfs/interface-go-ipfs-core"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/pkg/errors"
"go.opentelemetry.io/otel/api/trace"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -70,6 +71,10 @@ func newBertyOrbitDB(ctx context.Context, ipfs coreapi.CoreAPI, acc DeviceKeysto
options.Logger = zap.NewNop()
}

if options.Tracer == nil {
options.Tracer = trace.NoopTracer{}
}

ks := &BertySignedKeyStore{}
options.Keystore = ks
options.Identity = &identityprovider.Identity{}
Expand Down
35 changes: 30 additions & 5 deletions go/pkg/bertyprotocol/orbitdb_signed_entry_accesscontroller.go
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"encoding/json"

"sync"

"berty.tech/berty/v2/go/pkg/errcode"
logac "berty.tech/go-ipfs-log/accesscontroller"
"berty.tech/go-ipfs-log/identityprovider"
Expand All @@ -13,11 +15,28 @@ import (
cid "github.com/ipfs/go-cid"
mh "github.com/multiformats/go-multihash"
"github.com/pkg/errors"
"go.uber.org/zap"
)

type simpleAccessController struct {
events.EventEmitter
allowedKeys map[string][]string
logger *zap.Logger
lock sync.RWMutex
}

func (o *simpleAccessController) SetLogger(logger *zap.Logger) {
o.lock.Lock()
defer o.lock.Unlock()

o.logger = logger
}

func (o *simpleAccessController) Logger() *zap.Logger {
o.lock.RLock()
defer o.lock.RUnlock()

return o.logger
}

func (o *simpleAccessController) Grant(ctx context.Context, capability string, keyID string) error {
Expand Down Expand Up @@ -84,14 +103,20 @@ func (o *simpleAccessController) CanAppend(e logac.LogEntry, p identityprovider.
}

// NewSimpleAccessController Returns a non configurable access controller
func NewSimpleAccessController(_ context.Context, _ iface.BaseOrbitDB, options accesscontroller.ManifestParams) (accesscontroller.Interface, error) {
if options == nil {
func NewSimpleAccessController(_ context.Context, _ iface.BaseOrbitDB, params accesscontroller.ManifestParams, options ...accesscontroller.Option) (accesscontroller.Interface, error) {
if params == nil {
return &simpleAccessController{}, errors.New("an options object is required")
}

return &simpleAccessController{
allowedKeys: options.GetAllAccess(),
}, nil
ac := &simpleAccessController{
allowedKeys: params.GetAllAccess(),
}

for _, o := range options {
o(ac)
}

return ac, nil
}

var _ accesscontroller.Interface = &simpleAccessController{}
2 changes: 2 additions & 0 deletions go/pkg/bertyprotocol/service.go
Expand Up @@ -7,6 +7,7 @@ import (

"berty.tech/berty/v2/go/internal/ipfsutil"
"berty.tech/berty/v2/go/internal/tinder"
"berty.tech/berty/v2/go/internal/tracer"
"berty.tech/berty/v2/go/pkg/bertytypes"
"berty.tech/berty/v2/go/pkg/errcode"
orbitdb "berty.tech/go-orbit-db"
Expand Down Expand Up @@ -120,6 +121,7 @@ func New(opts Opts) (Service, error) {
Cache: opts.OrbitCache,
Directory: &orbitDirectory,
Logger: opts.Logger.Named("odb"),
Tracer: tracer.New("berty-orbitdb"),
})
if err != nil {
return nil, errcode.TODO.Wrap(err)
Expand Down

0 comments on commit 2e26044

Please sign in to comment.