diff --git a/Dockerfile b/Dockerfile index 2821b04c27..bf06bc0f15 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,6 +45,7 @@ ENV GOPATH=/go \ RUN apk add --update --no-cache \ g++ \ + protobuf \ git && \ rm -rf /var/cache/apk/ && mkdir /var/cache/apk/ && \ rm -rf /usr/share/man @@ -53,6 +54,11 @@ RUN mkdir -p $APP_DIR/go WORKDIR $APP_DIR/go +RUN go get github.com/gogo/protobuf/proto +RUN go get github.com/gogo/protobuf/jsonpb +RUN go get github.com/gogo/protobuf/protoc-gen-gogoslick +RUN go get github.com/gogo/protobuf/gogoproto + RUN go get -u github.com/golang/dep/cmd/dep COPY ./go/Gopkg.toml ./go/Gopkg.lock ./ RUN dep ensure --vendor-only @@ -61,6 +67,16 @@ COPY --from=cbuild $LIB_DIR $LIB_DIR COPY --from=cbuild $INCLUDE_DIR $INCLUDE_DIR COPY ./go/ $APP_DIR/go/ +COPY ./pkg/ $APP_DIR/pkg/ + +WORKDIR $APP_DIR/pkg/types +RUN go generate + +WORKDIR $APP_DIR/pkg/ +RUN dep init +RUN dep ensure --vendor-only + +WORKDIR $APP_DIR/go/ RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o $APP_NAME ./ && \ mv $APP_NAME $BIN_PATH && \ diff --git a/docs/development/README.md b/docs/development/README.md index ccbb979ff3..a978015970 100644 --- a/docs/development/README.md +++ b/docs/development/README.md @@ -15,6 +15,20 @@ work that the formula will explain when you install it. Once you've installed `bn`, you can run `dep ensure` in the `go/` directory of this repository and then you are ready to build. +#### Protobufs + +In addition to installing `bn` and `dep`, you'll also need to install the protobuf compiler. +On OSX, this will be `brew install protobuf` (requirement: need `homebrew installed first`). + +Lastly, you'll need to get the protoc-gen-gogo toolchain: + + ``` + go get github.com/gogo/protobuf/proto + go get github.com/gogo/protobuf/jsonpb + go get github.com/gogo/protobuf/protoc-gen-gogo + go get github.com/gogo/protobuf/gogoproto + ``` + ### Relay States There is a set of threshold relay state diagrams auto-generated from this diff --git a/pkg/types/gen.go b/pkg/types/gen.go new file mode 100644 index 0000000000..c6ea9fda99 --- /dev/null +++ b/pkg/types/gen.go @@ -0,0 +1,3 @@ +package types + +//go:generate sh -c "protoc --proto_path=$GOPATH/src:. --gogoslick_out=. */*.proto" diff --git a/pkg/types/gossip/message.proto b/pkg/types/gossip/message.proto new file mode 100644 index 0000000000..3fb276dc62 --- /dev/null +++ b/pkg/types/gossip/message.proto @@ -0,0 +1,50 @@ +syntax = "proto3"; + +option go_package = "gossip"; +package gossip; + +// Envelope contains a marshalled Message as the payload +// and a signature over the payload as signature. +// It also contains the Identities of the sender and receiver (optional). +// Optionally may contain an encrypted Envelope (in which case the payload will be empty). +message Envelope { + // The PublicKey and BLS ID of the sender and receiver + Identity sender = 1; + Identity receiver = 2; + + // A Marshaled GossipMessage + bytes payload = 3; + + // Signature of the message + bytes signature = 4; + + // A marshalled, encrypted message; if this exists, payload is empty + EncryptedEnvelope encrypted_envelope = 5; + + // TODO: this envelope needs an enum detailing which type of GossipMesssage it is. +} + +// EncryptedEnvelope is a marshalled, encrypted message. +message EncryptedEnvelope { + bytes payload = 1; + bytes signature = 4; +} + +message Identity { + // TODO: consolidate and remove redundant + bytes public_key = 1; + bytes bls_id = 2; + bytes peer_id = 3; +} + +message GossipMessage { + // Channel is isomorphic to the group name as well as the pubsub channel + // Channel names are Keccak(StakingPubKey1 || ... || StakingPubKeyN) of + // all valid group members. + bytes channel = 1; + + // Proof that the peer that sent this message knows the channel's name. + bytes channel_MAC = 2; + + // TODO: define various messages this GossipMessage can be. Use oneof. +}