Skip to content

Commit

Permalink
feat: emit node (internal) events
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Nov 24, 2018
1 parent 61ed34b commit 00d9362
Show file tree
Hide file tree
Showing 37 changed files with 3,217 additions and 365 deletions.
24 changes: 24 additions & 0 deletions client/react-native/common/graphql/enums.gen.js
Expand Up @@ -102,6 +102,26 @@ export const ValueGoogleProtobufMethodOptionsInputIdempotencyLevel = {
2: 'IDEMPOTENT',
}

export const BertyNodeKindInputKind = {
Unknown: 0,
NodeStarted: 1,
NodeStopped: 2,
NodeIsAlive: 3,
BackgroundError: 4,
BackgroundWarn: 5,
Debug: 6,
}

export const ValueBertyNodeKindInputKind = {
0: 'Unknown',
1: 'NodeStarted',
2: 'NodeStopped',
3: 'NodeIsAlive',
4: 'BackgroundError',
5: 'BackgroundWarn',
6: 'Debug',
}

export const BertyEntityDeviceInputStatus = {
Unknown: 0,
Connected: 1,
Expand Down Expand Up @@ -179,6 +199,7 @@ export const BertyP2pKindInputKind = {
ConversationNewMessage: 302,
DevtoolsMapset: 401,
SenderAliasUpdate: 501,
Node: 99,
}

export const ValueBertyP2pKindInputKind = {
Expand All @@ -194,18 +215,21 @@ export const ValueBertyP2pKindInputKind = {
302: 'ConversationNewMessage',
401: 'DevtoolsMapset',
501: 'SenderAliasUpdate',
99: 'Node',
}

export const BertyP2pEventInputDirection = {
UnknownDirection: 0,
Incoming: 1,
Outgoing: 2,
Node: 99,
}

export const ValueBertyP2pEventInputDirection = {
0: 'UnknownDirection',
1: 'Incoming',
2: 'Outgoing',
99: 'Node',
}

export const BertyP2pMetricsTypeInputMetricsType = {
Expand Down
33 changes: 32 additions & 1 deletion client/react-native/common/schema.graphql

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

13 changes: 6 additions & 7 deletions core/Makefile
Expand Up @@ -94,7 +94,6 @@ lint: generate
generate: .generated

.generated: $(PROTOS)
rm -f $(GENERATED_FILES) $(GENERATION_TARGETS) $@
make generate_prepare
docker run \
--user="$(shell id -u)" \
Expand Down Expand Up @@ -148,15 +147,15 @@ dev-deps:
.client.generated: $(PROTOS)
@# FIXME: implement `uniq` in make
@set -e; for protodir in `echo $(dir $(SERVICE_PROTOS)) | tr " " "\n" | uniq`; do (set -xe; \
$(PROTOC) $(PROTOC_OPTS) --gotemplate_out=debug=true,all=false,single-package-mode=true,template_dir=./api/client:./api/client $$protodir/*.proto; \
$(PROTOC) $(PROTOC_OPTS) --gotemplate_out=debug=false,all=false,single-package-mode=true,template_dir=./api/client:./api/client $$protodir/*.proto; \
); done

@# FIXME: the following hack is due to goimports -w not deleting duplicated imports
goimports -w ./api/client
goimports -w ./api/client/
sed -i'' '/^$$/d' api/client/*.gen.go api/client/jsonclient/*.gen.go
goimports -w ./api/client
goimports -w ./api/client/*.gen.go ./api/client/jsonclient/*.gen.go
sed -i'' '/^$$/d' api/client/*.gen.go api/client/jsonclient/*.gen.go
goimports -w ./api/client
goimports -w ./api/client/*.gen.go ./api/client/jsonclient/*.gen.go
touch $@

.kind.generated: $(PROTOS)
Expand All @@ -166,8 +165,8 @@ dev-deps:

.gql.generated: $(PROTOS) .pb.generated
mkdir -p ./api/node/graphql
$(PROTOC) $(PROTOC_OPTS) --gotemplate_out=debug=false,all=true,template_dir=./api/node:./api/node/graphql ./api/node/service.proto
goimports -w ./api/node/graphql
$(PROTOC) $(PROTOC_OPTS) --gotemplate_out=debug=false,all=true,template_dir=./api/node:./api/node ./api/node/*.proto
goimports -w ./api/node/*.gen.go ./api/node/graphql/*.gen.go
cd ./api/node/graphql && $(GQLGEN) -c gqlgen.gen.yml -v gen
cp ./api/node/graphql/service.gen.graphql ../client/react-native/common/schema.graphql
prettier-eslint --trailing-comma all --single-quote --no-semi --write ./api/node/graphql/enums.gen.js
Expand Down
44 changes: 44 additions & 0 deletions core/api/node/event.go
@@ -0,0 +1,44 @@
package node

import (
"encoding/json"
"time"

"berty.tech/core/api/p2p"
"github.com/gogo/protobuf/proto"
)

func GetNodeEvent(event *p2p.Event) (*NodeEvent, error) {
var nodeEvent NodeEvent
return &nodeEvent, proto.Unmarshal(event.Attributes, &nodeEvent)
}

func NewEvent(kind Kind, attributes proto.Message) (*p2p.Event, error) {
nodeEvent, err := NewNodeEvent(kind, attributes)
if err != nil {
return nil, err
}

attrs, err := proto.Marshal(nodeEvent)
if err != nil {
return nil, err
}

return &p2p.Event{
CreatedAt: time.Now().UTC(),
Direction: p2p.Event_Node,
Kind: p2p.Kind_Node,
Attributes: attrs,
}, nil
}

func NewNodeEvent(kind Kind, attributes proto.Message) (*NodeEvent, error) {
attrs, err := json.Marshal(attributes)
if err != nil {
return nil, err
}
return &NodeEvent{
Kind: kind,
Attributes: attrs,
}, nil
}
24 changes: 24 additions & 0 deletions core/api/node/graphql/enums.gen.js
Expand Up @@ -102,6 +102,26 @@ export const ValueGoogleProtobufMethodOptionsInputIdempotencyLevel = {
2: 'IDEMPOTENT',
}

export const BertyNodeKindInputKind = {
Unknown: 0,
NodeStarted: 1,
NodeStopped: 2,
NodeIsAlive: 3,
BackgroundError: 4,
BackgroundWarn: 5,
Debug: 6,
}

export const ValueBertyNodeKindInputKind = {
0: 'Unknown',
1: 'NodeStarted',
2: 'NodeStopped',
3: 'NodeIsAlive',
4: 'BackgroundError',
5: 'BackgroundWarn',
6: 'Debug',
}

export const BertyEntityDeviceInputStatus = {
Unknown: 0,
Connected: 1,
Expand Down Expand Up @@ -179,6 +199,7 @@ export const BertyP2pKindInputKind = {
ConversationNewMessage: 302,
DevtoolsMapset: 401,
SenderAliasUpdate: 501,
Node: 99,
}

export const ValueBertyP2pKindInputKind = {
Expand All @@ -194,18 +215,21 @@ export const ValueBertyP2pKindInputKind = {
302: 'ConversationNewMessage',
401: 'DevtoolsMapset',
501: 'SenderAliasUpdate',
99: 'Node',
}

export const BertyP2pEventInputDirection = {
UnknownDirection: 0,
Incoming: 1,
Outgoing: 2,
Node: 99,
}

export const ValueBertyP2pEventInputDirection = {
0: 'UnknownDirection',
1: 'Incoming',
2: 'Outgoing',
99: 'Node',
}

export const BertyP2pMetricsTypeInputMetricsType = {
Expand Down
File renamed without changes.

0 comments on commit 00d9362

Please sign in to comment.