From 2290a08d5715434fd263cf3fd17fd5fb0e6a7e20 Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Thu, 22 Mar 2018 13:23:57 -0400 Subject: [PATCH 01/15] Introduce protobuf types under new pkg directory Barbershop: check it, we got a new 'do. 2 because sequels are sometimes better. This PR introduces very preliminary work regarding protobuf types. Protobufs allow us to solidify our types. This allows us to communicate across and within service boundaries. --- pkg/types/gossip/message.proto | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 pkg/types/gossip/message.proto diff --git a/pkg/types/gossip/message.proto b/pkg/types/gossip/message.proto new file mode 100644 index 0000000000..c0b4e42ce7 --- /dev/null +++ b/pkg/types/gossip/message.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +// Envelope contains a marshalled Message as the payload +// and a signature over the payload as signature. +message Envelope { + bytes payload = 1; + bytes signature = 2; +} From 1bcb6f77253a89c0ac0cc1de1b345c1ef981abb8 Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Fri, 23 Mar 2018 12:05:07 -0400 Subject: [PATCH 02/15] Introduce a mechanism to generate protobuf We leverage go generate, the protobuf compiler, and shell to take the proto files (in each directory), and then spit out *.pb.go files which is our generated code. --- pkg/types/gen.go | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pkg/types/gen.go 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" From abea7e2ec5431265b93466b0f28c0df20062185c Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Mon, 26 Mar 2018 09:39:12 -0400 Subject: [PATCH 03/15] Introduce Peer Identities and GossipMessages. Identities are how we communicate attestation and ownership across network and service boundaries. Groups at the network level care about PeerIDs (libp2p) and public keys (PKI). Within a group, we utilize BLS IDs, which are containers around peerIDs/public keys (tbd). --- pkg/types/gossip/message.proto | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/pkg/types/gossip/message.proto b/pkg/types/gossip/message.proto index c0b4e42ce7..6ddfd8aa3d 100644 --- a/pkg/types/gossip/message.proto +++ b/pkg/types/gossip/message.proto @@ -1,8 +1,36 @@ syntax = "proto3"; +option go_package = "gossip"; +package gossip; + // Envelope contains a marshalled Message as the payload // and a signature over the payload as signature. message Envelope { + // A Marshaled GossipMessage bytes payload = 1; - bytes signature = 2; + + // The PublicKey and BLS ID of the sender and receiver + Identity sender = 2; + Identity receiver = 3; + + // Signature of the message + bytes signature = 4; + + // TODO: this envelope needs an enum detailing which type of GossipMesssage it is. } + +message Identity { + bytes public_key = 1; + bytes bls_id = 2; +} + +message GossipMessage { + // Channel is isomorphic to the group name as well as the pubsub channel + // Channel names are HASH(PubKey1 || ... || PubKeyN) 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. +} \ No newline at end of file From 30b7ae1e2ad23b9ded5b571eb9481044935fd7ad Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Mon, 26 Mar 2018 09:46:17 -0400 Subject: [PATCH 04/15] Generate protobuf code with "go generate". Test that gen.go appropriately spits out generated code. Check in our inital stab at spec'ing out the basic relay types (Envelopes, Messages, and Identities). --- pkg/types/gossip/message.pb.go | 1026 ++++++++++++++++++++++++++++++++ 1 file changed, 1026 insertions(+) create mode 100644 pkg/types/gossip/message.pb.go diff --git a/pkg/types/gossip/message.pb.go b/pkg/types/gossip/message.pb.go new file mode 100644 index 0000000000..46617bdcaa --- /dev/null +++ b/pkg/types/gossip/message.pb.go @@ -0,0 +1,1026 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: gossip/message.proto + +/* + Package gossip is a generated protocol buffer package. + + It is generated from these files: + gossip/message.proto + + It has these top-level messages: + Envelope + Identity + GossipMessage +*/ +package gossip + +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" + +import bytes "bytes" + +import strings "strings" +import reflect "reflect" + +import io "io" + +// 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.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +// Envelope contains a marshalled Message as the payload +// and a signature over the payload as signature. +type Envelope struct { + // A Marshaled GossipMessage + Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` + // The PublicKey and BLS ID of the sender and receiver + Sender *Identity `protobuf:"bytes,2,opt,name=sender" json:"sender,omitempty"` + Receiver *Identity `protobuf:"bytes,3,opt,name=receiver" json:"receiver,omitempty"` + // Signature of the message + Signature []byte `protobuf:"bytes,4,opt,name=signature,proto3" json:"signature,omitempty"` +} + +func (m *Envelope) Reset() { *m = Envelope{} } +func (*Envelope) ProtoMessage() {} +func (*Envelope) Descriptor() ([]byte, []int) { return fileDescriptorMessage, []int{0} } + +func (m *Envelope) GetPayload() []byte { + if m != nil { + return m.Payload + } + return nil +} + +func (m *Envelope) GetSender() *Identity { + if m != nil { + return m.Sender + } + return nil +} + +func (m *Envelope) GetReceiver() *Identity { + if m != nil { + return m.Receiver + } + return nil +} + +func (m *Envelope) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + +type Identity struct { + PublicKey []byte `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + BlsId []byte `protobuf:"bytes,2,opt,name=bls_id,json=blsId,proto3" json:"bls_id,omitempty"` +} + +func (m *Identity) Reset() { *m = Identity{} } +func (*Identity) ProtoMessage() {} +func (*Identity) Descriptor() ([]byte, []int) { return fileDescriptorMessage, []int{1} } + +func (m *Identity) GetPublicKey() []byte { + if m != nil { + return m.PublicKey + } + return nil +} + +func (m *Identity) GetBlsId() []byte { + if m != nil { + return m.BlsId + } + return nil +} + +type GossipMessage struct { + // Channel is isomorphic to the group name as well as the pubsub channel + // Channel names are HASH(PubKey1 || ... || PubKeyN) of all valid group members. + Channel []byte `protobuf:"bytes,1,opt,name=channel,proto3" json:"channel,omitempty"` + // Proof that the peer that sent this message knows the channel's name. + Channel_MAC []byte `protobuf:"bytes,2,opt,name=channel_MAC,json=channelMAC,proto3" json:"channel_MAC,omitempty"` +} + +func (m *GossipMessage) Reset() { *m = GossipMessage{} } +func (*GossipMessage) ProtoMessage() {} +func (*GossipMessage) Descriptor() ([]byte, []int) { return fileDescriptorMessage, []int{2} } + +func (m *GossipMessage) GetChannel() []byte { + if m != nil { + return m.Channel + } + return nil +} + +func (m *GossipMessage) GetChannel_MAC() []byte { + if m != nil { + return m.Channel_MAC + } + return nil +} + +func init() { + proto.RegisterType((*Envelope)(nil), "gossip.Envelope") + proto.RegisterType((*Identity)(nil), "gossip.Identity") + proto.RegisterType((*GossipMessage)(nil), "gossip.GossipMessage") +} +func (this *Envelope) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Envelope) + if !ok { + that2, ok := that.(Envelope) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.Payload, that1.Payload) { + return false + } + if !this.Sender.Equal(that1.Sender) { + return false + } + if !this.Receiver.Equal(that1.Receiver) { + return false + } + if !bytes.Equal(this.Signature, that1.Signature) { + return false + } + return true +} +func (this *Identity) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Identity) + if !ok { + that2, ok := that.(Identity) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.PublicKey, that1.PublicKey) { + return false + } + if !bytes.Equal(this.BlsId, that1.BlsId) { + return false + } + return true +} +func (this *GossipMessage) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*GossipMessage) + if !ok { + that2, ok := that.(GossipMessage) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.Channel, that1.Channel) { + return false + } + if !bytes.Equal(this.Channel_MAC, that1.Channel_MAC) { + return false + } + return true +} +func (this *Envelope) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 8) + s = append(s, "&gossip.Envelope{") + s = append(s, "Payload: "+fmt.Sprintf("%#v", this.Payload)+",\n") + if this.Sender != nil { + s = append(s, "Sender: "+fmt.Sprintf("%#v", this.Sender)+",\n") + } + if this.Receiver != nil { + s = append(s, "Receiver: "+fmt.Sprintf("%#v", this.Receiver)+",\n") + } + s = append(s, "Signature: "+fmt.Sprintf("%#v", this.Signature)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func (this *Identity) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&gossip.Identity{") + s = append(s, "PublicKey: "+fmt.Sprintf("%#v", this.PublicKey)+",\n") + s = append(s, "BlsId: "+fmt.Sprintf("%#v", this.BlsId)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func (this *GossipMessage) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&gossip.GossipMessage{") + s = append(s, "Channel: "+fmt.Sprintf("%#v", this.Channel)+",\n") + s = append(s, "Channel_MAC: "+fmt.Sprintf("%#v", this.Channel_MAC)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringMessage(v interface{}, typ string) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) +} +func (m *Envelope) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Envelope) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Payload) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintMessage(dAtA, i, uint64(len(m.Payload))) + i += copy(dAtA[i:], m.Payload) + } + if m.Sender != nil { + dAtA[i] = 0x12 + i++ + i = encodeVarintMessage(dAtA, i, uint64(m.Sender.Size())) + n1, err := m.Sender.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n1 + } + if m.Receiver != nil { + dAtA[i] = 0x1a + i++ + i = encodeVarintMessage(dAtA, i, uint64(m.Receiver.Size())) + n2, err := m.Receiver.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n2 + } + if len(m.Signature) > 0 { + dAtA[i] = 0x22 + i++ + i = encodeVarintMessage(dAtA, i, uint64(len(m.Signature))) + i += copy(dAtA[i:], m.Signature) + } + return i, nil +} + +func (m *Identity) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Identity) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.PublicKey) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintMessage(dAtA, i, uint64(len(m.PublicKey))) + i += copy(dAtA[i:], m.PublicKey) + } + if len(m.BlsId) > 0 { + dAtA[i] = 0x12 + i++ + i = encodeVarintMessage(dAtA, i, uint64(len(m.BlsId))) + i += copy(dAtA[i:], m.BlsId) + } + return i, nil +} + +func (m *GossipMessage) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GossipMessage) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Channel) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintMessage(dAtA, i, uint64(len(m.Channel))) + i += copy(dAtA[i:], m.Channel) + } + if len(m.Channel_MAC) > 0 { + dAtA[i] = 0x12 + i++ + i = encodeVarintMessage(dAtA, i, uint64(len(m.Channel_MAC))) + i += copy(dAtA[i:], m.Channel_MAC) + } + return i, nil +} + +func encodeVarintMessage(dAtA []byte, offset int, v uint64) int { + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return offset + 1 +} +func (m *Envelope) Size() (n int) { + var l int + _ = l + l = len(m.Payload) + if l > 0 { + n += 1 + l + sovMessage(uint64(l)) + } + if m.Sender != nil { + l = m.Sender.Size() + n += 1 + l + sovMessage(uint64(l)) + } + if m.Receiver != nil { + l = m.Receiver.Size() + n += 1 + l + sovMessage(uint64(l)) + } + l = len(m.Signature) + if l > 0 { + n += 1 + l + sovMessage(uint64(l)) + } + return n +} + +func (m *Identity) Size() (n int) { + var l int + _ = l + l = len(m.PublicKey) + if l > 0 { + n += 1 + l + sovMessage(uint64(l)) + } + l = len(m.BlsId) + if l > 0 { + n += 1 + l + sovMessage(uint64(l)) + } + return n +} + +func (m *GossipMessage) Size() (n int) { + var l int + _ = l + l = len(m.Channel) + if l > 0 { + n += 1 + l + sovMessage(uint64(l)) + } + l = len(m.Channel_MAC) + if l > 0 { + n += 1 + l + sovMessage(uint64(l)) + } + return n +} + +func sovMessage(x uint64) (n int) { + for { + n++ + x >>= 7 + if x == 0 { + break + } + } + return n +} +func sozMessage(x uint64) (n int) { + return sovMessage(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *Envelope) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Envelope{`, + `Payload:` + fmt.Sprintf("%v", this.Payload) + `,`, + `Sender:` + strings.Replace(fmt.Sprintf("%v", this.Sender), "Identity", "Identity", 1) + `,`, + `Receiver:` + strings.Replace(fmt.Sprintf("%v", this.Receiver), "Identity", "Identity", 1) + `,`, + `Signature:` + fmt.Sprintf("%v", this.Signature) + `,`, + `}`, + }, "") + return s +} +func (this *Identity) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Identity{`, + `PublicKey:` + fmt.Sprintf("%v", this.PublicKey) + `,`, + `BlsId:` + fmt.Sprintf("%v", this.BlsId) + `,`, + `}`, + }, "") + return s +} +func (this *GossipMessage) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&GossipMessage{`, + `Channel:` + fmt.Sprintf("%v", this.Channel) + `,`, + `Channel_MAC:` + fmt.Sprintf("%v", this.Channel_MAC) + `,`, + `}`, + }, "") + return s +} +func valueToStringMessage(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *Envelope) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Envelope: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Envelope: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthMessage + } + postIndex := iNdEx + byteLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Payload = append(m.Payload[:0], dAtA[iNdEx:postIndex]...) + if m.Payload == nil { + m.Payload = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthMessage + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Sender == nil { + m.Sender = &Identity{} + } + if err := m.Sender.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Receiver", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthMessage + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Receiver == nil { + m.Receiver = &Identity{} + } + if err := m.Receiver.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthMessage + } + postIndex := iNdEx + byteLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...) + if m.Signature == nil { + m.Signature = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipMessage(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthMessage + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Identity) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Identity: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Identity: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthMessage + } + postIndex := iNdEx + byteLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PublicKey = append(m.PublicKey[:0], dAtA[iNdEx:postIndex]...) + if m.PublicKey == nil { + m.PublicKey = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlsId", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthMessage + } + postIndex := iNdEx + byteLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BlsId = append(m.BlsId[:0], dAtA[iNdEx:postIndex]...) + if m.BlsId == nil { + m.BlsId = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipMessage(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthMessage + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *GossipMessage) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GossipMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GossipMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Channel", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthMessage + } + postIndex := iNdEx + byteLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Channel = append(m.Channel[:0], dAtA[iNdEx:postIndex]...) + if m.Channel == nil { + m.Channel = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Channel_MAC", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMessage + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthMessage + } + postIndex := iNdEx + byteLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Channel_MAC = append(m.Channel_MAC[:0], dAtA[iNdEx:postIndex]...) + if m.Channel_MAC == nil { + m.Channel_MAC = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipMessage(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthMessage + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipMessage(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMessage + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMessage + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + return iNdEx, nil + case 1: + iNdEx += 8 + return iNdEx, nil + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMessage + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + iNdEx += length + if length < 0 { + return 0, ErrInvalidLengthMessage + } + return iNdEx, nil + case 3: + for { + var innerWire uint64 + var start int = iNdEx + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowMessage + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + innerWire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + innerWireType := int(innerWire & 0x7) + if innerWireType == 4 { + break + } + next, err := skipMessage(dAtA[start:]) + if err != nil { + return 0, err + } + iNdEx = start + next + } + return iNdEx, nil + case 4: + return iNdEx, nil + case 5: + iNdEx += 4 + return iNdEx, nil + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + } + panic("unreachable") +} + +var ( + ErrInvalidLengthMessage = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowMessage = fmt.Errorf("proto: integer overflow") +) + +func init() { proto.RegisterFile("gossip/message.proto", fileDescriptorMessage) } + +var fileDescriptorMessage = []byte{ + // 300 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x49, 0xcf, 0x2f, 0x2e, + 0xce, 0x2c, 0xd0, 0xcf, 0x4d, 0x2d, 0x2e, 0x4e, 0x4c, 0x4f, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x62, 0x83, 0x88, 0x2a, 0xcd, 0x62, 0xe4, 0xe2, 0x70, 0xcd, 0x2b, 0x4b, 0xcd, 0xc9, 0x2f, + 0x48, 0x15, 0x92, 0xe0, 0x62, 0x2f, 0x48, 0xac, 0xcc, 0xc9, 0x4f, 0x4c, 0x91, 0x60, 0x54, 0x60, + 0xd4, 0xe0, 0x09, 0x82, 0x71, 0x85, 0x34, 0xb8, 0xd8, 0x8a, 0x53, 0xf3, 0x52, 0x52, 0x8b, 0x24, + 0x98, 0x14, 0x18, 0x35, 0xb8, 0x8d, 0x04, 0xf4, 0x20, 0xfa, 0xf5, 0x3c, 0x53, 0x52, 0xf3, 0x4a, + 0x32, 0x4b, 0x2a, 0x83, 0xa0, 0xf2, 0x42, 0x3a, 0x5c, 0x1c, 0x45, 0xa9, 0xc9, 0xa9, 0x99, 0x65, + 0xa9, 0x45, 0x12, 0xcc, 0x38, 0xd4, 0xc2, 0x55, 0x08, 0xc9, 0x70, 0x71, 0x16, 0x67, 0xa6, 0xe7, + 0x25, 0x96, 0x94, 0x16, 0xa5, 0x4a, 0xb0, 0x80, 0xed, 0x44, 0x08, 0x28, 0x39, 0x70, 0x71, 0xc0, + 0xf4, 0x08, 0xc9, 0x72, 0x71, 0x15, 0x94, 0x26, 0xe5, 0x64, 0x26, 0xc7, 0x67, 0xa7, 0x56, 0x42, + 0x9d, 0xc7, 0x09, 0x11, 0xf1, 0x4e, 0xad, 0x14, 0x12, 0xe5, 0x62, 0x4b, 0xca, 0x29, 0x8e, 0xcf, + 0x4c, 0x01, 0x3b, 0x90, 0x27, 0x88, 0x35, 0x29, 0xa7, 0xd8, 0x33, 0x45, 0xc9, 0x8b, 0x8b, 0xd7, + 0x1d, 0x6c, 0xb9, 0x2f, 0xc4, 0xf7, 0x20, 0x2f, 0x26, 0x67, 0x24, 0xe6, 0xe5, 0xa5, 0xe6, 0xc0, + 0xbc, 0x08, 0xe5, 0x0a, 0xc9, 0x73, 0x71, 0x43, 0x99, 0xf1, 0xbe, 0x8e, 0xce, 0x50, 0x63, 0xb8, + 0xa0, 0x42, 0xbe, 0x8e, 0xce, 0x4e, 0x26, 0x17, 0x1e, 0xca, 0x31, 0xdc, 0x78, 0x28, 0xc7, 0xf0, + 0xe1, 0xa1, 0x1c, 0x63, 0xc3, 0x23, 0x39, 0xc6, 0x15, 0x8f, 0xe4, 0x18, 0x4f, 0x3c, 0x92, 0x63, + 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x17, 0x8f, 0xe4, 0x18, 0x3e, 0x3c, 0x92, + 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0x21, 0x0a, 0x1a, 0xc0, 0x49, 0x6c, 0xe0, 0xf0, 0x36, 0x06, 0x04, + 0x00, 0x00, 0xff, 0xff, 0x11, 0x77, 0xaf, 0x79, 0x87, 0x01, 0x00, 0x00, +} From 62b803818a385f9d68466aad8b173dd5f60723fd Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Mon, 26 Mar 2018 10:56:40 -0400 Subject: [PATCH 05/15] Add protobuf dependency with dep. This was initalized by running `dep init` in the `pkg` directory. Of note, this duplicates our vendored dependencies between `go/` and `pkg/`, but for all intents and purposes, they are separate. --- pkg/Gopkg.lock | 15 +++++++++++++++ pkg/Gopkg.toml | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 pkg/Gopkg.lock create mode 100644 pkg/Gopkg.toml diff --git a/pkg/Gopkg.lock b/pkg/Gopkg.lock new file mode 100644 index 0000000000..621ea373c9 --- /dev/null +++ b/pkg/Gopkg.lock @@ -0,0 +1,15 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + name = "github.com/gogo/protobuf" + packages = ["proto"] + revision = "1adfc126b41513cc696b209667c8656ea7aac67c" + version = "v1.0.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "bd0ed53b262770bb1b2f69e54c1edbdf8cede43019cfdaf964ba457444a62c54" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/pkg/Gopkg.toml b/pkg/Gopkg.toml new file mode 100644 index 0000000000..75a0222516 --- /dev/null +++ b/pkg/Gopkg.toml @@ -0,0 +1,34 @@ +# Gopkg.toml example +# +# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true + + +[[constraint]] + name = "github.com/gogo/protobuf" + version = "1.0.0" + +[prune] + go-tests = true + unused-packages = true From 1e71aec7fb74a359ca8bd7089c3469ba33bdc352 Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Mon, 26 Mar 2018 10:57:47 -0400 Subject: [PATCH 06/15] Add Makefile and Readme to simplify dev experience The Makefile contains an install command to install the entire protobuf toolchain for the relay. As an aside, if the user already has the compiler, we expose the `proto-gogo` installation command to just grab those dependencies. Much work is needed here. --- pkg/types/Makefile | 15 +++++++++++++++ pkg/types/README.md | 9 +++++++++ 2 files changed, 24 insertions(+) create mode 100644 pkg/types/Makefile create mode 100644 pkg/types/README.md diff --git a/pkg/types/Makefile b/pkg/types/Makefile new file mode 100644 index 0000000000..0f3c8ba749 --- /dev/null +++ b/pkg/types/Makefile @@ -0,0 +1,15 @@ +.PHONY: install proto-gogo + +install: proto-darwin proto-gogo + +proto-darwin: + brew install protobuf + @echo "Installed protobuf compiler for Darwin" + +proto-gogo: + go get github.com/gogo/protobuf/proto \ + github.com/gogo/protobuf/jsonpb \ + github.com/gogo/protobuf/protoc-gen-gogo \ + github.com/gogo/protobuf/gogoproto + + @echo "Installed gogo deps" diff --git a/pkg/types/README.md b/pkg/types/README.md new file mode 100644 index 0000000000..76f2017686 --- /dev/null +++ b/pkg/types/README.md @@ -0,0 +1,9 @@ +1. Run `make install` to grab the protobuf compiler and `protoc-gen-gogo`. + + a. If this fails for any reason...congratulations! You have the protobuf compiler installed. + Instead run `make proto-gogo` to install the `protoc-gen-gogo` toolchain. + +2. If you add or update types, you'll need to autogenerate protobuf code: + + In `$GOPATH/src/github.com/keep-network/keep-core/pkg/types/`, run `go generate`. + Notice a new file, `*.pb.go`. This is your generated code. Ensure it's right and check it in. From 57df3f217acdb1c3cedff584d1e65ed574faa4bf Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Mon, 26 Mar 2018 11:00:34 -0400 Subject: [PATCH 07/15] Remove weird spacing in Makefile --- pkg/types/Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/types/Makefile b/pkg/types/Makefile index 0f3c8ba749..60c43935d9 100644 --- a/pkg/types/Makefile +++ b/pkg/types/Makefile @@ -7,9 +7,6 @@ proto-darwin: @echo "Installed protobuf compiler for Darwin" proto-gogo: - go get github.com/gogo/protobuf/proto \ - github.com/gogo/protobuf/jsonpb \ - github.com/gogo/protobuf/protoc-gen-gogo \ - github.com/gogo/protobuf/gogoproto + go get github.com/gogo/protobuf/proto \ github.com/gogo/protobuf/jsonpb \ github.com/gogo/protobuf/protoc-gen-gogo \ github.com/gogo/protobuf/gogoproto @echo "Installed gogo deps" From ca1913cd1e26d6a44929da9a5b3e9925bcd71d97 Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Mon, 26 Mar 2018 16:34:10 -0400 Subject: [PATCH 08/15] Point our protobuf dependency to a commit. Previously pointed to a tag. This is not great as tags are mutable. --- pkg/Gopkg.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/Gopkg.toml b/pkg/Gopkg.toml index 75a0222516..ac4a620ab5 100644 --- a/pkg/Gopkg.toml +++ b/pkg/Gopkg.toml @@ -27,7 +27,7 @@ [[constraint]] name = "github.com/gogo/protobuf" - version = "1.0.0" + revision = "49944b4a4b085da44c43d4b233ea40787396371f" [prune] go-tests = true From c7228d19e8739812466afc918b541dc0f9a994bf Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Mon, 26 Mar 2018 16:35:48 -0400 Subject: [PATCH 09/15] Remove generated code and dependency. As our policy is to not check in generated code, we no longer need the dependency. --- pkg/Gopkg.lock | 15 - pkg/Gopkg.toml | 34 -- pkg/types/gossip/message.pb.go | 1026 -------------------------------- 3 files changed, 1075 deletions(-) delete mode 100644 pkg/Gopkg.lock delete mode 100644 pkg/Gopkg.toml delete mode 100644 pkg/types/gossip/message.pb.go diff --git a/pkg/Gopkg.lock b/pkg/Gopkg.lock deleted file mode 100644 index 621ea373c9..0000000000 --- a/pkg/Gopkg.lock +++ /dev/null @@ -1,15 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - name = "github.com/gogo/protobuf" - packages = ["proto"] - revision = "1adfc126b41513cc696b209667c8656ea7aac67c" - version = "v1.0.0" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "bd0ed53b262770bb1b2f69e54c1edbdf8cede43019cfdaf964ba457444a62c54" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/pkg/Gopkg.toml b/pkg/Gopkg.toml deleted file mode 100644 index ac4a620ab5..0000000000 --- a/pkg/Gopkg.toml +++ /dev/null @@ -1,34 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - - -[[constraint]] - name = "github.com/gogo/protobuf" - revision = "49944b4a4b085da44c43d4b233ea40787396371f" - -[prune] - go-tests = true - unused-packages = true diff --git a/pkg/types/gossip/message.pb.go b/pkg/types/gossip/message.pb.go deleted file mode 100644 index 46617bdcaa..0000000000 --- a/pkg/types/gossip/message.pb.go +++ /dev/null @@ -1,1026 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: gossip/message.proto - -/* - Package gossip is a generated protocol buffer package. - - It is generated from these files: - gossip/message.proto - - It has these top-level messages: - Envelope - Identity - GossipMessage -*/ -package gossip - -import proto "github.com/gogo/protobuf/proto" -import fmt "fmt" -import math "math" - -import bytes "bytes" - -import strings "strings" -import reflect "reflect" - -import io "io" - -// 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.GoGoProtoPackageIsVersion2 // please upgrade the proto package - -// Envelope contains a marshalled Message as the payload -// and a signature over the payload as signature. -type Envelope struct { - // A Marshaled GossipMessage - Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` - // The PublicKey and BLS ID of the sender and receiver - Sender *Identity `protobuf:"bytes,2,opt,name=sender" json:"sender,omitempty"` - Receiver *Identity `protobuf:"bytes,3,opt,name=receiver" json:"receiver,omitempty"` - // Signature of the message - Signature []byte `protobuf:"bytes,4,opt,name=signature,proto3" json:"signature,omitempty"` -} - -func (m *Envelope) Reset() { *m = Envelope{} } -func (*Envelope) ProtoMessage() {} -func (*Envelope) Descriptor() ([]byte, []int) { return fileDescriptorMessage, []int{0} } - -func (m *Envelope) GetPayload() []byte { - if m != nil { - return m.Payload - } - return nil -} - -func (m *Envelope) GetSender() *Identity { - if m != nil { - return m.Sender - } - return nil -} - -func (m *Envelope) GetReceiver() *Identity { - if m != nil { - return m.Receiver - } - return nil -} - -func (m *Envelope) GetSignature() []byte { - if m != nil { - return m.Signature - } - return nil -} - -type Identity struct { - PublicKey []byte `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` - BlsId []byte `protobuf:"bytes,2,opt,name=bls_id,json=blsId,proto3" json:"bls_id,omitempty"` -} - -func (m *Identity) Reset() { *m = Identity{} } -func (*Identity) ProtoMessage() {} -func (*Identity) Descriptor() ([]byte, []int) { return fileDescriptorMessage, []int{1} } - -func (m *Identity) GetPublicKey() []byte { - if m != nil { - return m.PublicKey - } - return nil -} - -func (m *Identity) GetBlsId() []byte { - if m != nil { - return m.BlsId - } - return nil -} - -type GossipMessage struct { - // Channel is isomorphic to the group name as well as the pubsub channel - // Channel names are HASH(PubKey1 || ... || PubKeyN) of all valid group members. - Channel []byte `protobuf:"bytes,1,opt,name=channel,proto3" json:"channel,omitempty"` - // Proof that the peer that sent this message knows the channel's name. - Channel_MAC []byte `protobuf:"bytes,2,opt,name=channel_MAC,json=channelMAC,proto3" json:"channel_MAC,omitempty"` -} - -func (m *GossipMessage) Reset() { *m = GossipMessage{} } -func (*GossipMessage) ProtoMessage() {} -func (*GossipMessage) Descriptor() ([]byte, []int) { return fileDescriptorMessage, []int{2} } - -func (m *GossipMessage) GetChannel() []byte { - if m != nil { - return m.Channel - } - return nil -} - -func (m *GossipMessage) GetChannel_MAC() []byte { - if m != nil { - return m.Channel_MAC - } - return nil -} - -func init() { - proto.RegisterType((*Envelope)(nil), "gossip.Envelope") - proto.RegisterType((*Identity)(nil), "gossip.Identity") - proto.RegisterType((*GossipMessage)(nil), "gossip.GossipMessage") -} -func (this *Envelope) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*Envelope) - if !ok { - that2, ok := that.(Envelope) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !bytes.Equal(this.Payload, that1.Payload) { - return false - } - if !this.Sender.Equal(that1.Sender) { - return false - } - if !this.Receiver.Equal(that1.Receiver) { - return false - } - if !bytes.Equal(this.Signature, that1.Signature) { - return false - } - return true -} -func (this *Identity) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*Identity) - if !ok { - that2, ok := that.(Identity) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !bytes.Equal(this.PublicKey, that1.PublicKey) { - return false - } - if !bytes.Equal(this.BlsId, that1.BlsId) { - return false - } - return true -} -func (this *GossipMessage) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*GossipMessage) - if !ok { - that2, ok := that.(GossipMessage) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !bytes.Equal(this.Channel, that1.Channel) { - return false - } - if !bytes.Equal(this.Channel_MAC, that1.Channel_MAC) { - return false - } - return true -} -func (this *Envelope) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 8) - s = append(s, "&gossip.Envelope{") - s = append(s, "Payload: "+fmt.Sprintf("%#v", this.Payload)+",\n") - if this.Sender != nil { - s = append(s, "Sender: "+fmt.Sprintf("%#v", this.Sender)+",\n") - } - if this.Receiver != nil { - s = append(s, "Receiver: "+fmt.Sprintf("%#v", this.Receiver)+",\n") - } - s = append(s, "Signature: "+fmt.Sprintf("%#v", this.Signature)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func (this *Identity) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 6) - s = append(s, "&gossip.Identity{") - s = append(s, "PublicKey: "+fmt.Sprintf("%#v", this.PublicKey)+",\n") - s = append(s, "BlsId: "+fmt.Sprintf("%#v", this.BlsId)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func (this *GossipMessage) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 6) - s = append(s, "&gossip.GossipMessage{") - s = append(s, "Channel: "+fmt.Sprintf("%#v", this.Channel)+",\n") - s = append(s, "Channel_MAC: "+fmt.Sprintf("%#v", this.Channel_MAC)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func valueToGoStringMessage(v interface{}, typ string) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) -} -func (m *Envelope) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Envelope) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Payload) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintMessage(dAtA, i, uint64(len(m.Payload))) - i += copy(dAtA[i:], m.Payload) - } - if m.Sender != nil { - dAtA[i] = 0x12 - i++ - i = encodeVarintMessage(dAtA, i, uint64(m.Sender.Size())) - n1, err := m.Sender.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n1 - } - if m.Receiver != nil { - dAtA[i] = 0x1a - i++ - i = encodeVarintMessage(dAtA, i, uint64(m.Receiver.Size())) - n2, err := m.Receiver.MarshalTo(dAtA[i:]) - if err != nil { - return 0, err - } - i += n2 - } - if len(m.Signature) > 0 { - dAtA[i] = 0x22 - i++ - i = encodeVarintMessage(dAtA, i, uint64(len(m.Signature))) - i += copy(dAtA[i:], m.Signature) - } - return i, nil -} - -func (m *Identity) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Identity) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.PublicKey) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintMessage(dAtA, i, uint64(len(m.PublicKey))) - i += copy(dAtA[i:], m.PublicKey) - } - if len(m.BlsId) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintMessage(dAtA, i, uint64(len(m.BlsId))) - i += copy(dAtA[i:], m.BlsId) - } - return i, nil -} - -func (m *GossipMessage) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *GossipMessage) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Channel) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintMessage(dAtA, i, uint64(len(m.Channel))) - i += copy(dAtA[i:], m.Channel) - } - if len(m.Channel_MAC) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintMessage(dAtA, i, uint64(len(m.Channel_MAC))) - i += copy(dAtA[i:], m.Channel_MAC) - } - return i, nil -} - -func encodeVarintMessage(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *Envelope) Size() (n int) { - var l int - _ = l - l = len(m.Payload) - if l > 0 { - n += 1 + l + sovMessage(uint64(l)) - } - if m.Sender != nil { - l = m.Sender.Size() - n += 1 + l + sovMessage(uint64(l)) - } - if m.Receiver != nil { - l = m.Receiver.Size() - n += 1 + l + sovMessage(uint64(l)) - } - l = len(m.Signature) - if l > 0 { - n += 1 + l + sovMessage(uint64(l)) - } - return n -} - -func (m *Identity) Size() (n int) { - var l int - _ = l - l = len(m.PublicKey) - if l > 0 { - n += 1 + l + sovMessage(uint64(l)) - } - l = len(m.BlsId) - if l > 0 { - n += 1 + l + sovMessage(uint64(l)) - } - return n -} - -func (m *GossipMessage) Size() (n int) { - var l int - _ = l - l = len(m.Channel) - if l > 0 { - n += 1 + l + sovMessage(uint64(l)) - } - l = len(m.Channel_MAC) - if l > 0 { - n += 1 + l + sovMessage(uint64(l)) - } - return n -} - -func sovMessage(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozMessage(x uint64) (n int) { - return sovMessage(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *Envelope) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Envelope{`, - `Payload:` + fmt.Sprintf("%v", this.Payload) + `,`, - `Sender:` + strings.Replace(fmt.Sprintf("%v", this.Sender), "Identity", "Identity", 1) + `,`, - `Receiver:` + strings.Replace(fmt.Sprintf("%v", this.Receiver), "Identity", "Identity", 1) + `,`, - `Signature:` + fmt.Sprintf("%v", this.Signature) + `,`, - `}`, - }, "") - return s -} -func (this *Identity) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Identity{`, - `PublicKey:` + fmt.Sprintf("%v", this.PublicKey) + `,`, - `BlsId:` + fmt.Sprintf("%v", this.BlsId) + `,`, - `}`, - }, "") - return s -} -func (this *GossipMessage) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&GossipMessage{`, - `Channel:` + fmt.Sprintf("%v", this.Channel) + `,`, - `Channel_MAC:` + fmt.Sprintf("%v", this.Channel_MAC) + `,`, - `}`, - }, "") - return s -} -func valueToStringMessage(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} -func (m *Envelope) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMessage - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Envelope: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Envelope: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMessage - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthMessage - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Payload = append(m.Payload[:0], dAtA[iNdEx:postIndex]...) - if m.Payload == nil { - m.Payload = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMessage - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthMessage - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Sender == nil { - m.Sender = &Identity{} - } - if err := m.Sender.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Receiver", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMessage - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthMessage - } - postIndex := iNdEx + msglen - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Receiver == nil { - m.Receiver = &Identity{} - } - if err := m.Receiver.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMessage - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthMessage - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...) - if m.Signature == nil { - m.Signature = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipMessage(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthMessage - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Identity) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMessage - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Identity: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Identity: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMessage - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthMessage - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PublicKey = append(m.PublicKey[:0], dAtA[iNdEx:postIndex]...) - if m.PublicKey == nil { - m.PublicKey = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BlsId", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMessage - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthMessage - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BlsId = append(m.BlsId[:0], dAtA[iNdEx:postIndex]...) - if m.BlsId == nil { - m.BlsId = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipMessage(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthMessage - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *GossipMessage) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMessage - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: GossipMessage: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: GossipMessage: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Channel", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMessage - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthMessage - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Channel = append(m.Channel[:0], dAtA[iNdEx:postIndex]...) - if m.Channel == nil { - m.Channel = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Channel_MAC", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMessage - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthMessage - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Channel_MAC = append(m.Channel_MAC[:0], dAtA[iNdEx:postIndex]...) - if m.Channel_MAC == nil { - m.Channel_MAC = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipMessage(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthMessage - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipMessage(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowMessage - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowMessage - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowMessage - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthMessage - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowMessage - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipMessage(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthMessage = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowMessage = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("gossip/message.proto", fileDescriptorMessage) } - -var fileDescriptorMessage = []byte{ - // 300 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x49, 0xcf, 0x2f, 0x2e, - 0xce, 0x2c, 0xd0, 0xcf, 0x4d, 0x2d, 0x2e, 0x4e, 0x4c, 0x4f, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, - 0x17, 0x62, 0x83, 0x88, 0x2a, 0xcd, 0x62, 0xe4, 0xe2, 0x70, 0xcd, 0x2b, 0x4b, 0xcd, 0xc9, 0x2f, - 0x48, 0x15, 0x92, 0xe0, 0x62, 0x2f, 0x48, 0xac, 0xcc, 0xc9, 0x4f, 0x4c, 0x91, 0x60, 0x54, 0x60, - 0xd4, 0xe0, 0x09, 0x82, 0x71, 0x85, 0x34, 0xb8, 0xd8, 0x8a, 0x53, 0xf3, 0x52, 0x52, 0x8b, 0x24, - 0x98, 0x14, 0x18, 0x35, 0xb8, 0x8d, 0x04, 0xf4, 0x20, 0xfa, 0xf5, 0x3c, 0x53, 0x52, 0xf3, 0x4a, - 0x32, 0x4b, 0x2a, 0x83, 0xa0, 0xf2, 0x42, 0x3a, 0x5c, 0x1c, 0x45, 0xa9, 0xc9, 0xa9, 0x99, 0x65, - 0xa9, 0x45, 0x12, 0xcc, 0x38, 0xd4, 0xc2, 0x55, 0x08, 0xc9, 0x70, 0x71, 0x16, 0x67, 0xa6, 0xe7, - 0x25, 0x96, 0x94, 0x16, 0xa5, 0x4a, 0xb0, 0x80, 0xed, 0x44, 0x08, 0x28, 0x39, 0x70, 0x71, 0xc0, - 0xf4, 0x08, 0xc9, 0x72, 0x71, 0x15, 0x94, 0x26, 0xe5, 0x64, 0x26, 0xc7, 0x67, 0xa7, 0x56, 0x42, - 0x9d, 0xc7, 0x09, 0x11, 0xf1, 0x4e, 0xad, 0x14, 0x12, 0xe5, 0x62, 0x4b, 0xca, 0x29, 0x8e, 0xcf, - 0x4c, 0x01, 0x3b, 0x90, 0x27, 0x88, 0x35, 0x29, 0xa7, 0xd8, 0x33, 0x45, 0xc9, 0x8b, 0x8b, 0xd7, - 0x1d, 0x6c, 0xb9, 0x2f, 0xc4, 0xf7, 0x20, 0x2f, 0x26, 0x67, 0x24, 0xe6, 0xe5, 0xa5, 0xe6, 0xc0, - 0xbc, 0x08, 0xe5, 0x0a, 0xc9, 0x73, 0x71, 0x43, 0x99, 0xf1, 0xbe, 0x8e, 0xce, 0x50, 0x63, 0xb8, - 0xa0, 0x42, 0xbe, 0x8e, 0xce, 0x4e, 0x26, 0x17, 0x1e, 0xca, 0x31, 0xdc, 0x78, 0x28, 0xc7, 0xf0, - 0xe1, 0xa1, 0x1c, 0x63, 0xc3, 0x23, 0x39, 0xc6, 0x15, 0x8f, 0xe4, 0x18, 0x4f, 0x3c, 0x92, 0x63, - 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x17, 0x8f, 0xe4, 0x18, 0x3e, 0x3c, 0x92, - 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0x21, 0x0a, 0x1a, 0xc0, 0x49, 0x6c, 0xe0, 0xf0, 0x36, 0x06, 0x04, - 0x00, 0x00, 0xff, 0xff, 0x11, 0x77, 0xaf, 0x79, 0x87, 0x01, 0x00, 0x00, -} From bd88baffb498695c5786c7b8dc09de1db787dfdf Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Mon, 26 Mar 2018 18:19:00 -0400 Subject: [PATCH 10/15] Remove Makefile, note dependencies in Readme. --- docs/development/README.md | 14 ++++++++++++++ pkg/types/Makefile | 12 ------------ 2 files changed, 14 insertions(+), 12 deletions(-) delete mode 100644 pkg/types/Makefile 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/Makefile b/pkg/types/Makefile deleted file mode 100644 index 60c43935d9..0000000000 --- a/pkg/types/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -.PHONY: install proto-gogo - -install: proto-darwin proto-gogo - -proto-darwin: - brew install protobuf - @echo "Installed protobuf compiler for Darwin" - -proto-gogo: - go get github.com/gogo/protobuf/proto \ github.com/gogo/protobuf/jsonpb \ github.com/gogo/protobuf/protoc-gen-gogo \ github.com/gogo/protobuf/gogoproto - - @echo "Installed gogo deps" From 8cc74d63aa202f4c2f653875821c7417e37ba011 Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Mon, 26 Mar 2018 18:20:07 -0400 Subject: [PATCH 11/15] Add EncryptedEnvelope, update GossipMsg doc. An EncryptedEnvelope is a special envelope needed for certain phases of DKG. Update document for the channel field in GossipMessage; note that we use keccak as the has function, and that pub keys are specifically StakingPubKeys. --- pkg/types/gossip/message.proto | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/types/gossip/message.proto b/pkg/types/gossip/message.proto index 6ddfd8aa3d..fb8d2bea45 100644 --- a/pkg/types/gossip/message.proto +++ b/pkg/types/gossip/message.proto @@ -5,6 +5,8 @@ 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. +// Optionally may contain an encrypted Envelope (in which case the payload will be empty). message Envelope { // A Marshaled GossipMessage bytes payload = 1; @@ -16,21 +18,32 @@ message Envelope { // Signature of the message bytes signature = 4; + 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 HASH(PubKey1 || ... || PubKeyN) of all valid group members. + // 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. -} \ No newline at end of file +} From 19d4a445f32f936a37adf85e67c9ab5ece299bdb Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Mon, 26 Mar 2018 18:21:40 -0400 Subject: [PATCH 12/15] Remove unnecessary readme. --- pkg/types/README.md | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 pkg/types/README.md diff --git a/pkg/types/README.md b/pkg/types/README.md deleted file mode 100644 index 76f2017686..0000000000 --- a/pkg/types/README.md +++ /dev/null @@ -1,9 +0,0 @@ -1. Run `make install` to grab the protobuf compiler and `protoc-gen-gogo`. - - a. If this fails for any reason...congratulations! You have the protobuf compiler installed. - Instead run `make proto-gogo` to install the `protoc-gen-gogo` toolchain. - -2. If you add or update types, you'll need to autogenerate protobuf code: - - In `$GOPATH/src/github.com/keep-network/keep-core/pkg/types/`, run `go generate`. - Notice a new file, `*.pb.go`. This is your generated code. Ensure it's right and check it in. From c8b128d30423a26183d8260918847d4482a20f14 Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Mon, 26 Mar 2018 18:33:02 -0400 Subject: [PATCH 13/15] Move payload and signature fiedls in GossipMessage Move closer to EncryptedMessage to show that there is a relation between the fields. --- pkg/types/gossip/message.proto | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/types/gossip/message.proto b/pkg/types/gossip/message.proto index fb8d2bea45..cb559d258d 100644 --- a/pkg/types/gossip/message.proto +++ b/pkg/types/gossip/message.proto @@ -5,25 +5,26 @@ 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. +// It also contains the (optional) Identities of the sender and receiver. // Optionally may contain an encrypted Envelope (in which case the payload will be empty). message Envelope { - // A Marshaled GossipMessage - bytes payload = 1; - // The PublicKey and BLS ID of the sender and receiver - Identity sender = 2; - Identity receiver = 3; + 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. +// EncryptedEnvelope is a marshalled, encrypted message. message EncryptedEnvelope { bytes payload = 1; bytes signature = 4; From 94adfc7f0a8768f86a7594d86b4f052e2cc413ab Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Tue, 27 Mar 2018 10:21:11 -0400 Subject: [PATCH 14/15] Update Dockerfile with proto dependencies We introduce the protobuf compiler, gogo/proto toolchain, and introduce the pkg/ directory. This will be the directory from which future changes are made. --- Dockerfile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 && \ From e81b9dd01517e930d0ea11bfa8ed122fb959b483 Mon Sep 17 00:00:00 2001 From: Raghav Gulati Date: Tue, 27 Mar 2018 10:29:06 -0400 Subject: [PATCH 15/15] Note that only the receiver is optional, not sender --- pkg/types/gossip/message.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/types/gossip/message.proto b/pkg/types/gossip/message.proto index cb559d258d..3fb276dc62 100644 --- a/pkg/types/gossip/message.proto +++ b/pkg/types/gossip/message.proto @@ -5,7 +5,7 @@ package gossip; // Envelope contains a marshalled Message as the payload // and a signature over the payload as signature. -// It also contains the (optional) Identities of the sender and receiver. +// 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