Skip to content

Commit

Permalink
feat(core): complete implementation of the basic contact flow
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jul 30, 2018
1 parent f28f6aa commit c425c7a
Show file tree
Hide file tree
Showing 19 changed files with 1,122 additions and 182 deletions.
17 changes: 13 additions & 4 deletions core/Makefile
Expand Up @@ -5,13 +5,18 @@ SOURCES = $(call rwildcard, $(CODE_PATHS), *.go)
CODE_PATHS = $(filter-out node_modules/,$(wildcard */))
PROTOS = $(call rwildcard, $(CODE_PATHS), *.proto)
SERVICE_PROTOS = $(call rwildcard, api, *.proto)
GENERATED_FILES = $(patsubst %.proto,%.pb.go,$(PROTOS)) client/berty.node.service.gen.go $(call rwildcard $(CODE_PATHS), *.gen.go)
GENERATED_FILES = \
$(patsubst %.proto,%.pb.go,$(PROTOS)) \
client/berty.node.service.gen.go \
$(call rwildcard $(CODE_PATHS), *.gen.go) \
api/p2p/kind.gen.go
PROTOC_OPTS = --proto_path=../vendor:../vendor/github.com/gogo/protobuf:.
CGO_LDFLAGS ?= -L/usr/local/opt/openssl/lib
CGO_CPPFLAGS ?= -I/usr/local/opt/openssl/include
BUILD_ENV ?= CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CPPFLAGS="$(CGO_CPPFLAGS)"
RUN_DAEMON_OPTS ?= --log-level=debug
TEST_PATHS ?= ./...
TEST_CMD ?= $(BUILD_ENV) go test -test.timeout 30s -v $(TEST_PATHS)

##
## phonies
Expand All @@ -34,12 +39,12 @@ $(BIN): generate $(SOURCES)
testwatch:
@if ! command -v watchman &>/dev/null; then brew install watchman; fi
trap 'kill $$(jobs -p) 2>/dev/null; exit 0' INT; \
make test || true; \
while true; do watchman-wait . -p "**/*.go"; make test; sleep .3; done
clear; $(TEST_CMD); \
while true; do watchman-wait . -p "**/*.go"; clear; $(TEST_CMD); sleep .3; done

.PHONY: test
test: generate
$(BUILD_ENV) go test -test.timeout 30s -v $(TEST_PATHS)
$(TEST_CMD)

.PHONY: lint
lint: generate
Expand Down Expand Up @@ -71,3 +76,7 @@ client/berty.node.service.gen.go: $(PROTOS)
protoc $(PROTOC_OPTS) --gotemplate_out=debug=false,all=false,single-package-mode=true,template_dir=./client:./client $$protodir/*.proto; \
); done
goimports -w ./client/

api/p2p/kind.gen.go: $(PROTOS)
protoc $(PROTOC_OPTS) --gotemplate_out=debug=false,single-package-mode=true,all=true,template_dir=./api/p2p:./api/p2p ./api/p2p/kind.proto
goimports -w ./api/p2p
64 changes: 32 additions & 32 deletions core/api/node/service.pb.go

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

31 changes: 29 additions & 2 deletions core/api/p2p/event.go
@@ -1,6 +1,9 @@
package p2p

import "time"
import (
"strings"
"time"
)

func NewOutgoingEvent(sender, receiver string, kind Kind) *Event {
return &Event{
Expand All @@ -13,7 +16,31 @@ func NewOutgoingEvent(sender, receiver string, kind Kind) *Event {
}
}

func (e *Event) Validate() error {
func (e Event) Validate() error {
// FIXME: generate validation
return nil
}

func (e Event) Copy() *Event {
return &Event{
ID: e.ID,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
DeletedAt: e.DeletedAt,
SenderID: e.SenderID,
Direction: e.Direction,
SenderAPIVersion: e.SenderAPIVersion,
ReceiverAPIVersion: e.ReceiverAPIVersion,
ReceiverID: e.ReceiverID,
Kind: e.Kind,
SentAt: e.SentAt,
ReceivedAt: e.ReceivedAt,
AckedAt: e.AckedAt,
ConversationID: e.ConversationID,
Attributes: e.Attributes,
}
}

func (e Event) Author() string {
return strings.Split(e.ID, ":")[0]
}

0 comments on commit c425c7a

Please sign in to comment.