Skip to content

Commit

Permalink
Merge pull request #2050 from gfanton/glouvigny/odb-tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jun 11, 2020
2 parents 3535bd0 + 0a24f9e commit f105d26
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 26 deletions.
2 changes: 1 addition & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions go/pkg/bertyprotocol/orbitdb.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
23 changes: 21 additions & 2 deletions js/packages/components/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,15 @@ const CreateYourAccount: React.FC<{
}> = ({ next }) => {
const [name, setName] = useState('')
const [nodeConfig, setNodeConfig] = useState(
__DEV__ ? defaultExternalBridgeConfig : defaultEmbeddedConfig,
__DEV__
? defaultExternalBridgeConfig
: {
...defaultEmbeddedConfig,
opts: {
...defaultEmbeddedConfig.opts,
tracingPrefix: name,
},
},
)
const [{ text, padding, margin, background, border }] = useStyles()
const createAccount = Chat.useAccountCreate()
Expand All @@ -362,7 +370,18 @@ const CreateYourAccount: React.FC<{
<TextInput
autoCapitalize='none'
autoCorrect={false}
onChangeText={setName}
onChangeText={(name) => {
setName(name)
if (nodeConfig.type === 'embedded') {
setNodeConfig({
...nodeConfig,
opts: {
...nodeConfig.opts,
tracingPrefix: name,
},
})
}
}}
placeholder={t('onboarding.create-account.placeholder')}
style={[
margin.top.medium,
Expand Down
27 changes: 18 additions & 9 deletions js/packages/go-bridge/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ export PATH := $(PWD)/node_modules/.bin:$(PATH)
BAZEL_FRAMEWORK := $(PWD)/bazel-bin/ios/gobridge_framework.tar.gz
FRAMEWORK_DIR := $(PWD)/ios/Frameworks
FRAMEWORK := $(FRAMEWORK_DIR)/Bertybridge.framework
FRAMEWORK_TARGETS := $(addsuffix .ios, $(shell \
find $(addprefix $(GOPATH)/src/berty.tech/berty/,vendor go) -name '*.go' -newer "$(FRAMEWORK_DIR)" || echo "$(FRAMEWORK_DIR).go") \
)

BAZEL_AAR := $(PWD)/bazel-bin/android/gobridge_library.aar
AAR_DIR := $(PWD)/android/libs
AAR := $(PWD)/android/libs/gobridge.aar
AAR_TARGETS := $(addsuffix .android, $(shell \
find $(addprefix $(GOPATH)/src/berty.tech/berty/,vendor go) -name '*.go' -newer "$(AAR_DIR)" || echo "$(AAR_DIR).go") \
)

GO_VENDOR := $(GOPATH)/src/berty.tech/berty/vendor
GOMOBILE := $(GOPATH)/bin/gomobile
Expand All @@ -28,19 +34,22 @@ $(GOBIND):

build.gobridge: build.gobridge.ios build.gobridge.android

build.gobridge.ios: $(FRAMEWORK_DIR)
touch $<
$(FRAMEWORK_TARGETS):%.go.ios: deps.gobridge build.framework # TODO: add go prerequisits
build.gobridge.ios: $(FRAMEWORK_TARGETS)

$(FRAMEWORK_DIR): deps.gobridge # TODO: add go prerequisits
mkdir -p $(FRAMEWORK_DIR)
GO111MODULE=off gomobile bind -o $(FRAMEWORK) -v -target ios berty.tech/berty/go/framework/bertybridge
$(AAR_TARGETS):%.go.android: deps.gobridge build.aar # TODO: add go prerequisits
build.gobridge.android: $(AAR_TARGETS)

build.gobridge.android: $(AAR)
touch $<
build.framework:
@mkdir -p "$(FRAMEWORK_DIR)"
GO111MODULE=off gomobile bind -o $(FRAMEWORK) -v -target ios berty.tech/berty/go/framework/bertybridge
touch "$(FRAMEWORK_DIR)"

$(AAR): deps.gobridge # TODO: add go prerequisits
mkdir -p $(AAR_DIR)
build.aar:
@mkdir -p "$(AAR_DIR)"
GO111MODULE=off gomobile bind -o $(AAR) -v -target android berty.tech/berty/go/framework/bertybridge
touch "$(AAR_DIR)"


bazel.build.gobridge: bazel.build.gobridge.ios bazel.build.gobridge.android

Expand Down
23 changes: 16 additions & 7 deletions js/packages/go-bridge/ios/GoBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
import Foundation
import Bertybridge

extension NSDictionary {
func get(bool: String, defaultValue: Bool = false) -> Bool { return self[bool] as? Bool ?? defaultValue }
func get(string: String, defaultValue: String = "") -> String { return self[string] as? String ?? defaultValue }
func get(int: String, defaultValue: Int = 0) -> Int { return self[int] as? Int ?? defaultValue }
func get(array: String, defaultValue: NSArray = []) -> NSArray { return self[array] as? NSArray ?? defaultValue }
func get(object: NSDictionary, defaultValue: NSDictionary = [:]) -> NSDictionary { return self[object] as? NSDictionary ?? defaultValue }
}

@objc(GoBridge)
class GoBridge: NSObject {
static let rnlogger = LoggerDriver("tech.berty", "react")
Expand Down Expand Up @@ -65,12 +73,13 @@ class GoBridge: NSObject {
throw NSError(domain: "already started", code: 1)
}

// get opts
let optTracing = opts["tracing"] as? Bool ?? false
let optPersistance = opts["persistance"] as? Bool ?? false
let optLog = opts["logLevel"] as? String ?? "info"
let optGrpcListeners = opts["grpcListeners"] as? NSArray ?? ["/ip4/127.0.0.1/tcp/0/grpcws"]
let optSwarmListeners = opts["swarmListeners"] as? NSArray ?? ["/ip4/0.0.0.0/tcp/0", "/ip6/0.0.0.0/tcp/0"]
// gather opts
let optPersistance = opts.get(bool: "persistance")
let optLog = opts.get(string: "logLevel", defaultValue: "info")
let optGrpcListeners = opts.get(array: "grpcListeners", defaultValue: ["/ip4/127.0.0.1/tcp/0/grpcws"])
let optSwarmListeners = opts.get(array: "swarmListeners", defaultValue: ["/ip4/0.0.0.0/tcp/0", "/ip6/0.0.0.0/tcp/0"])
let optTracing = opts.get(bool: "tracing")
let optTracingPrefix = opts.get(string: "tracingPrefix")

var err: NSError?
guard let config = BertybridgeNewProtocolConfig() else {
Expand Down Expand Up @@ -115,7 +124,7 @@ class GoBridge: NSObject {

if optTracing {
config.enableTracing()
config.setTracingPrefix("changeme")
config.setTracingPrefix(optTracingPrefix)
}

let bridgeProtocol = BertybridgeNewProtocolBridge(config, &err)
Expand Down
1 change: 1 addition & 0 deletions js/packages/go-bridge/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type GoBridgeOpts = {
persistance?: boolean
logLevel?: GoLogLevel
tracing?: boolean
tracingPrefix?: string
}

export type GoLoggerOpts = {
Expand Down
1 change: 1 addition & 0 deletions js/packages/store/protocol/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export const defaultBridgeOpts = {
logLevel: 'debug',
persistance: true,
tracing: true,
tracingPrefix: '',
}

export const transactions: Transactions = {
Expand Down

0 comments on commit f105d26

Please sign in to comment.