From b09bccb932fd2f173f133455c58a8dfd44269267 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Tue, 22 Jan 2019 16:45:17 -0800 Subject: [PATCH 1/2] introduce universal message --- api/proto/message/gen.sh | 1 + api/proto/message/message.proto | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 api/proto/message/gen.sh create mode 100644 api/proto/message/message.proto diff --git a/api/proto/message/gen.sh b/api/proto/message/gen.sh new file mode 100644 index 000000000..27fdc96c8 --- /dev/null +++ b/api/proto/message/gen.sh @@ -0,0 +1 @@ +protoc -I ./ message.proto --go_out=./ diff --git a/api/proto/message/message.proto b/api/proto/message/message.proto new file mode 100644 index 000000000..aea07cf0e --- /dev/null +++ b/api/proto/message/message.proto @@ -0,0 +1,33 @@ +syntax = "proto3"; +package message; + +enum MessageType { + UNKNOWN = 0; + NEWNODE_BOOTNODE = 1; + BOOTNODE_NEWNODE = 2; + NEWNODE_BEACON = 3; + BEACON_NEWNODE = 4; +} + +// This is universal message for all communication protocols. +// There are different Requests for different message types. +// As we introduce a new type of message just add a new MessageType and new type of request in Message. +// +// The request field will be either one of the structure corresponding to the MessageType type. +message Message { + MessageType type = 1; + oneof request { + NewNodeBootNodeRequest newnode_bootnode_request = 2; + BootNodeNewNodeRequest bootnode_newnode_request = 3; + } +} + +// Message of NewNode talking to BootNode. +message NewNodeBootNodeRequest { +} + +// Message of BootNode talking to NewNode. +message BootNodeNewNodeRequest { +} + +// TODO(minhdoan): refactor and introduce consensus message as one of possible Message.request. \ No newline at end of file From dd214dbd8838266faed55372a1c67eee95d00c03 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Thu, 24 Jan 2019 14:33:21 -0800 Subject: [PATCH 2/2] add protobuf setup instruction and message generation script --- api/proto/message/message.pb.go | 241 ++++++++++++++++++++++++++++++++ scripts/message_gen.sh | 1 + scripts/protobuf_setup.md | 6 + 3 files changed, 248 insertions(+) create mode 100644 api/proto/message/message.pb.go create mode 100755 scripts/message_gen.sh create mode 100644 scripts/protobuf_setup.md diff --git a/api/proto/message/message.pb.go b/api/proto/message/message.pb.go new file mode 100644 index 000000000..083c2bb38 --- /dev/null +++ b/api/proto/message/message.pb.go @@ -0,0 +1,241 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: message.proto + +package message + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type MessageType int32 + +const ( + MessageType_UNKNOWN MessageType = 0 + MessageType_NEWNODE_BOOTNODE MessageType = 1 + MessageType_BOOTNODE_NEWNODE MessageType = 2 + MessageType_NEWNODE_BEACON MessageType = 3 + MessageType_BEACON_NEWNODE MessageType = 4 +) + +var MessageType_name = map[int32]string{ + 0: "UNKNOWN", + 1: "NEWNODE_BOOTNODE", + 2: "BOOTNODE_NEWNODE", + 3: "NEWNODE_BEACON", + 4: "BEACON_NEWNODE", +} + +var MessageType_value = map[string]int32{ + "UNKNOWN": 0, + "NEWNODE_BOOTNODE": 1, + "BOOTNODE_NEWNODE": 2, + "NEWNODE_BEACON": 3, + "BEACON_NEWNODE": 4, +} + +func (x MessageType) String() string { + return proto.EnumName(MessageType_name, int32(x)) +} + +func (MessageType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_33c57e4bae7b9afd, []int{0} +} + +// This is universal message for all communication protocols. +// There are different Requests for different message types. +// As we introduce a new type of message just add a new MessageType and new type of request in Message. +// +// The request field will be either one of the structure corresponding to the MessageType type. +type Message struct { + Type MessageType `protobuf:"varint,1,opt,name=type,proto3,enum=message.MessageType" json:"type,omitempty"` + // Types that are valid to be assigned to Request: + // *Message_NewnodeBootnodeRequest + // *Message_BootnodeNewnodeRequest + Request isMessage_Request `protobuf_oneof:"request"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Message) Reset() { *m = Message{} } +func (m *Message) String() string { return proto.CompactTextString(m) } +func (*Message) ProtoMessage() {} +func (*Message) Descriptor() ([]byte, []int) { + return fileDescriptor_33c57e4bae7b9afd, []int{0} +} + +func (m *Message) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Message.Unmarshal(m, b) +} +func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Message.Marshal(b, m, deterministic) +} +func (m *Message) XXX_Merge(src proto.Message) { + xxx_messageInfo_Message.Merge(m, src) +} +func (m *Message) XXX_Size() int { + return xxx_messageInfo_Message.Size(m) +} +func (m *Message) XXX_DiscardUnknown() { + xxx_messageInfo_Message.DiscardUnknown(m) +} + +var xxx_messageInfo_Message proto.InternalMessageInfo + +func (m *Message) GetType() MessageType { + if m != nil { + return m.Type + } + return MessageType_UNKNOWN +} + +type isMessage_Request interface { + isMessage_Request() +} + +type Message_NewnodeBootnodeRequest struct { + NewnodeBootnodeRequest *NewNodeBootNodeRequest `protobuf:"bytes,2,opt,name=newnode_bootnode_request,json=newnodeBootnodeRequest,proto3,oneof"` +} + +type Message_BootnodeNewnodeRequest struct { + BootnodeNewnodeRequest *BootNodeNewNodeRequest `protobuf:"bytes,3,opt,name=bootnode_newnode_request,json=bootnodeNewnodeRequest,proto3,oneof"` +} + +func (*Message_NewnodeBootnodeRequest) isMessage_Request() {} + +func (*Message_BootnodeNewnodeRequest) isMessage_Request() {} + +func (m *Message) GetRequest() isMessage_Request { + if m != nil { + return m.Request + } + return nil +} + +func (m *Message) GetNewnodeBootnodeRequest() *NewNodeBootNodeRequest { + if x, ok := m.GetRequest().(*Message_NewnodeBootnodeRequest); ok { + return x.NewnodeBootnodeRequest + } + return nil +} + +func (m *Message) GetBootnodeNewnodeRequest() *BootNodeNewNodeRequest { + if x, ok := m.GetRequest().(*Message_BootnodeNewnodeRequest); ok { + return x.BootnodeNewnodeRequest + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*Message) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*Message_NewnodeBootnodeRequest)(nil), + (*Message_BootnodeNewnodeRequest)(nil), + } +} + +// Message of NewNode talking to BootNode. +type NewNodeBootNodeRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *NewNodeBootNodeRequest) Reset() { *m = NewNodeBootNodeRequest{} } +func (m *NewNodeBootNodeRequest) String() string { return proto.CompactTextString(m) } +func (*NewNodeBootNodeRequest) ProtoMessage() {} +func (*NewNodeBootNodeRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_33c57e4bae7b9afd, []int{1} +} + +func (m *NewNodeBootNodeRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_NewNodeBootNodeRequest.Unmarshal(m, b) +} +func (m *NewNodeBootNodeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_NewNodeBootNodeRequest.Marshal(b, m, deterministic) +} +func (m *NewNodeBootNodeRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_NewNodeBootNodeRequest.Merge(m, src) +} +func (m *NewNodeBootNodeRequest) XXX_Size() int { + return xxx_messageInfo_NewNodeBootNodeRequest.Size(m) +} +func (m *NewNodeBootNodeRequest) XXX_DiscardUnknown() { + xxx_messageInfo_NewNodeBootNodeRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_NewNodeBootNodeRequest proto.InternalMessageInfo + +// Message of BootNode talking to NewNode. +type BootNodeNewNodeRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *BootNodeNewNodeRequest) Reset() { *m = BootNodeNewNodeRequest{} } +func (m *BootNodeNewNodeRequest) String() string { return proto.CompactTextString(m) } +func (*BootNodeNewNodeRequest) ProtoMessage() {} +func (*BootNodeNewNodeRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_33c57e4bae7b9afd, []int{2} +} + +func (m *BootNodeNewNodeRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_BootNodeNewNodeRequest.Unmarshal(m, b) +} +func (m *BootNodeNewNodeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_BootNodeNewNodeRequest.Marshal(b, m, deterministic) +} +func (m *BootNodeNewNodeRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_BootNodeNewNodeRequest.Merge(m, src) +} +func (m *BootNodeNewNodeRequest) XXX_Size() int { + return xxx_messageInfo_BootNodeNewNodeRequest.Size(m) +} +func (m *BootNodeNewNodeRequest) XXX_DiscardUnknown() { + xxx_messageInfo_BootNodeNewNodeRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_BootNodeNewNodeRequest proto.InternalMessageInfo + +func init() { + proto.RegisterEnum("message.MessageType", MessageType_name, MessageType_value) + proto.RegisterType((*Message)(nil), "message.Message") + proto.RegisterType((*NewNodeBootNodeRequest)(nil), "message.NewNodeBootNodeRequest") + proto.RegisterType((*BootNodeNewNodeRequest)(nil), "message.BootNodeNewNodeRequest") +} + +func init() { proto.RegisterFile("message.proto", fileDescriptor_33c57e4bae7b9afd) } + +var fileDescriptor_33c57e4bae7b9afd = []byte{ + // 253 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x41, 0x4b, 0xc3, 0x40, + 0x10, 0x85, 0xbb, 0x6d, 0x31, 0x38, 0xc1, 0xb2, 0x2c, 0xa5, 0xe4, 0x66, 0xe9, 0x29, 0x78, 0xe8, + 0xa1, 0xfe, 0x02, 0xa3, 0x01, 0x41, 0x9c, 0x85, 0x50, 0xe9, 0xc1, 0x43, 0xb0, 0x74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a8, 0x27, 0xbe, 0xd7, 0xe9, 0x3e, 0x37, 0xdd, 0x5f, 0xb5, 0xdf, 0x75, 0xff, + 0x17, 0x00, 0x00, 0xff, 0xff, 0x37, 0x30, 0xd0, 0xfb, 0xbf, 0x01, 0x00, 0x00, +} diff --git a/scripts/message_gen.sh b/scripts/message_gen.sh new file mode 100755 index 000000000..55f63881d --- /dev/null +++ b/scripts/message_gen.sh @@ -0,0 +1 @@ +protoc -I ./api/proto/message api/proto/message/message.proto --go_out=./api/proto/message diff --git a/scripts/protobuf_setup.md b/scripts/protobuf_setup.md new file mode 100644 index 000000000..30c3ca376 --- /dev/null +++ b/scripts/protobuf_setup.md @@ -0,0 +1,6 @@ +# Setup + +You need to install protoc (protobuf compiler) and protoc-gen-go. + +- For protoc-gen-go just simple install by `go get -u github.com/golang/protobuf/protoc-gen-go` +- For protoc, you install from the release https://github.com/protocolbuffers/protobuf/releases.