From 46f7af051a98e93ef93effb0d77e728e3330733e Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Thu, 15 Dec 2016 15:46:46 -0500 Subject: [PATCH] [FAB-1416] Make Policy message more generic Today, the Policy message uses a oneof construct to enumerate the allowable values. This makes coding somewhat more convenient, but it makes extending things with additional types more difficult. This changeset switches the Policy message to use the more traditional integer enumerate type with marshaled bytes construct. Change-Id: Ic8e51ce4d1fa5e7fa99352e7dcb456a5b51f6e39 Signed-off-by: Jason Yellick --- common/policies/policy.go | 15 +-- common/policies/policy_test.go | 20 ++-- protos/common/configuration.pb.go | 182 +++++++++++------------------ protos/common/configuration.proto | 10 +- protos/orderer/ab.pb.go | 1 + protos/utils/configurationutils.go | 25 ++-- 6 files changed, 105 insertions(+), 148 deletions(-) diff --git a/common/policies/policy.go b/common/policies/policy.go index 36a36055ad8..83d962e18af 100644 --- a/common/policies/policy.go +++ b/common/policies/policy.go @@ -22,8 +22,8 @@ import ( "github.com/hyperledger/fabric/common/cauthdsl" cb "github.com/hyperledger/fabric/protos/common" - "github.com/golang/protobuf/proto" "errors" + "github.com/golang/protobuf/proto" ) // Policy is used to determine if a signature is valid @@ -46,18 +46,15 @@ type policy struct { } func newPolicy(policySource *cb.Policy, ch cauthdsl.CryptoHelper) (*policy, error) { - envelopeWrapper, ok := policySource.Type.(*cb.Policy_SignaturePolicy) - - if !ok { - return nil, fmt.Errorf("Unknown policy type: %T", policySource.Type) + if policySource.Type != int32(cb.Policy_SIGNATURE) { + return nil, fmt.Errorf("Unknown policy type: %v", policySource.Type) } - if envelopeWrapper.SignaturePolicy == nil { - return nil, errors.New("Nil signature policy received") + sigPolicy := &cb.SignaturePolicyEnvelope{} + if err := proto.Unmarshal(policySource.Policy, sigPolicy); err != nil { + return nil, fmt.Errorf("Error unmarshaling to SignaturePolicy: %s", err) } - sigPolicy := envelopeWrapper.SignaturePolicy - evaluator, err := cauthdsl.NewSignaturePolicyEvaluator(sigPolicy, ch) if err != nil { return nil, err diff --git a/common/policies/policy_test.go b/common/policies/policy_test.go index 8b74996a458..0f6c43c39c8 100644 --- a/common/policies/policy_test.go +++ b/common/policies/policy_test.go @@ -17,6 +17,7 @@ limitations under the License. package policies import ( + "fmt" "testing" "github.com/hyperledger/fabric/common/cauthdsl" @@ -39,6 +40,15 @@ func init() { rejectAllPolicy = makePolicySource(false) } +// The proto utils has become a dumping ground of cyclic imports, it's easier to define this locally +func marshalOrPanic(msg proto.Message) []byte { + data, err := proto.Marshal(msg) + if err != nil { + panic(fmt.Errorf("Error marshaling messages: %s, %s", msg, err)) + } + return data +} + func makePolicySource(policyResult bool) []byte { var policyData *cb.SignaturePolicyEnvelope if policyResult { @@ -46,14 +56,10 @@ func makePolicySource(policyResult bool) []byte { } else { policyData = cauthdsl.RejectAllPolicy } - marshaledPolicy, err := proto.Marshal(&cb.Policy{ - Type: &cb.Policy_SignaturePolicy{ - SignaturePolicy: policyData, - }, + marshaledPolicy := marshalOrPanic(&cb.Policy{ + Type: int32(cb.Policy_SIGNATURE), + Policy: marshalOrPanic(policyData), }) - if err != nil { - panic("Error marshaling policy") - } return marshaledPolicy } diff --git a/protos/common/configuration.pb.go b/protos/common/configuration.pb.go index f7e87613d3c..78462d30307 100644 --- a/protos/common/configuration.pb.go +++ b/protos/common/configuration.pb.go @@ -42,6 +42,30 @@ func (ConfigurationItem_ConfigurationType) EnumDescriptor() ([]byte, []int) { return fileDescriptor1, []int{2, 0} } +type Policy_PolicyType int32 + +const ( + Policy_UNKNOWN Policy_PolicyType = 0 + Policy_SIGNATURE Policy_PolicyType = 1 + Policy_MSP Policy_PolicyType = 2 +) + +var Policy_PolicyType_name = map[int32]string{ + 0: "UNKNOWN", + 1: "SIGNATURE", + 2: "MSP", +} +var Policy_PolicyType_value = map[string]int32{ + "UNKNOWN": 0, + "SIGNATURE": 1, + "MSP": 2, +} + +func (x Policy_PolicyType) String() string { + return proto.EnumName(Policy_PolicyType_name, int32(x)) +} +func (Policy_PolicyType) EnumDescriptor() ([]byte, []int) { return fileDescriptor1, []int{4, 0} } + // ConfigurationEnvelope is designed to contain _all_ configuration for a chain with no dependency // on previous configuration transactions. // @@ -131,9 +155,8 @@ func (*ConfigurationSignature) Descriptor() ([]byte, []int) { return fileDescrip // Policy expresses a policy which the orderer can evaluate, because there has been some desire expressed to support // multiple policy engines, this is typed as a oneof for now type Policy struct { - // Types that are valid to be assigned to Type: - // *Policy_SignaturePolicy - Type isPolicy_Type `protobuf_oneof:"Type"` + Type int32 `protobuf:"varint,1,opt,name=type" json:"type,omitempty"` + Policy []byte `protobuf:"bytes,2,opt,name=policy,proto3" json:"policy,omitempty"` } func (m *Policy) Reset() { *m = Policy{} } @@ -141,85 +164,6 @@ func (m *Policy) String() string { return proto.CompactTextString(m) func (*Policy) ProtoMessage() {} func (*Policy) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{4} } -type isPolicy_Type interface { - isPolicy_Type() -} - -type Policy_SignaturePolicy struct { - SignaturePolicy *SignaturePolicyEnvelope `protobuf:"bytes,1,opt,name=SignaturePolicy,oneof"` -} - -func (*Policy_SignaturePolicy) isPolicy_Type() {} - -func (m *Policy) GetType() isPolicy_Type { - if m != nil { - return m.Type - } - return nil -} - -func (m *Policy) GetSignaturePolicy() *SignaturePolicyEnvelope { - if x, ok := m.GetType().(*Policy_SignaturePolicy); ok { - return x.SignaturePolicy - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*Policy) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _Policy_OneofMarshaler, _Policy_OneofUnmarshaler, _Policy_OneofSizer, []interface{}{ - (*Policy_SignaturePolicy)(nil), - } -} - -func _Policy_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*Policy) - // Type - switch x := m.Type.(type) { - case *Policy_SignaturePolicy: - b.EncodeVarint(1<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.SignaturePolicy); err != nil { - return err - } - case nil: - default: - return fmt.Errorf("Policy.Type has unexpected type %T", x) - } - return nil -} - -func _Policy_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*Policy) - switch tag { - case 1: // Type.SignaturePolicy - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(SignaturePolicyEnvelope) - err := b.DecodeMessage(msg) - m.Type = &Policy_SignaturePolicy{msg} - return true, err - default: - return false, nil - } -} - -func _Policy_OneofSizer(msg proto.Message) (n int) { - m := msg.(*Policy) - // Type - switch x := m.Type.(type) { - case *Policy_SignaturePolicy: - s := proto.Size(x.SignaturePolicy) - n += proto.SizeVarint(1<<3 | proto.WireBytes) - n += proto.SizeVarint(uint64(s)) - n += s - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - // SignaturePolicyEnvelope wraps a SignaturePolicy and includes a version for future enhancements type SignaturePolicyEnvelope struct { Version int32 `protobuf:"varint,1,opt,name=Version" json:"Version,omitempty"` @@ -388,44 +332,48 @@ func init() { proto.RegisterType((*SignaturePolicy)(nil), "common.SignaturePolicy") proto.RegisterType((*SignaturePolicy_NOutOf)(nil), "common.SignaturePolicy.NOutOf") proto.RegisterEnum("common.ConfigurationItem_ConfigurationType", ConfigurationItem_ConfigurationType_name, ConfigurationItem_ConfigurationType_value) + proto.RegisterEnum("common.Policy_PolicyType", Policy_PolicyType_name, Policy_PolicyType_value) } func init() { proto.RegisterFile("common/configuration.proto", fileDescriptor1) } var fileDescriptor1 = []byte{ - // 540 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x74, 0x54, 0xdf, 0x8f, 0xd2, 0x40, - 0x10, 0x66, 0x29, 0xed, 0xdd, 0x0d, 0x8d, 0x87, 0x73, 0xea, 0x35, 0xe4, 0x82, 0x4d, 0x9f, 0x9a, - 0xa0, 0x90, 0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x3f, - 0x62, 0x37, 0x37, 0xa5, 0xfc, 0xd6, 0x7b, 0xd7, 0x27, 0x1c, 0xd0, 0xdc, 0x7b, 0x0b, 0xe0, 0x21, - 0x64, 0x51, 0xc2, 0x13, 0xce, 0x62, 0xc7, 0x70, 0x0d, 0xdf, 0xa6, 0x3b, 0x88, 0xf7, 0x87, 0x1c, - 0x35, 0x87, 0x37, 0x70, 0xae, 0xff, 0x94, 0xbe, 0x6e, 0xd4, 0x1c, 0x54, 0x68, 0x81, 0xe0, 0x1b, - 0xa8, 0xdd, 0x4b, 0xb1, 0xca, 0x0c, 0xb4, 0x4e, 0x18, 0xe8, 0x8c, 0xc6, 0x9b, 0x64, 0x3c, 0x1b, - 0x54, 0xa8, 0x62, 0x37, 0x87, 0x60, 0x69, 0x04, 0x6d, 0x20, 0xa3, 0xac, 0x2d, 0x32, 0xc2, 0x5b, - 0x38, 0x57, 0x02, 0x5e, 0xfc, 0x4a, 0x27, 0x5b, 0x2a, 0x88, 0xf9, 0x0c, 0xfb, 0xaf, 0xbf, 0xb5, - 0xe7, 0x3c, 0x59, 0x6c, 0x26, 0xa9, 0xa4, 0xbb, 0xd8, 0xae, 0x99, 0x5c, 0xb2, 0x70, 0xce, 0x64, - 0x77, 0xa6, 0xf6, 0xa4, 0xab, 0xae, 0x92, 0x38, 0xbb, 0x58, 0x26, 0x96, 0x3a, 0xde, 0xfe, 0x0b, - 0x00, 0x00, 0xff, 0xff, 0x71, 0x39, 0xd4, 0x0c, 0x94, 0x04, 0x00, 0x00, + // 579 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x74, 0x54, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0xcd, 0xc6, 0x89, 0xd3, 0x4c, 0x0c, 0x35, 0x53, 0x68, 0xad, 0xaa, 0x2a, 0x96, 0x4f, 0x96, + 0x0a, 0x89, 0x48, 0xe1, 0x0a, 0xa2, 0x55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, 0x04, 0x1b, 0xa0, 0xdd, 0xf6, 0xef, 0xcc, 0xaa, 0xf3, 0x2b, 0xbb, + 0x99, 0xb2, 0xad, 0x12, 0x17, 0x97, 0xdd, 0x82, 0xc6, 0x23, 0x13, 0x31, 0x8f, 0xc2, 0xac, 0x7b, + 0x1e, 0x62, 0x27, 0xb7, 0x27, 0x0d, 0xb4, 0xba, 0x07, 0xe5, 0x77, 0x50, 0x2a, 0x45, 0xf3, 0x29, + 0x8e, 0x01, 0xae, 0x03, 0x16, 0x26, 0x3c, 0xe1, 0x2c, 0xb6, 0x34, 0x5b, 0x73, 0x0d, 0x5a, 0x42, + 0x9c, 0x3f, 0x04, 0x76, 0xd7, 0xb4, 0x78, 0x04, 0x3b, 0xea, 0xcd, 0x9c, 0x2d, 0x55, 0xff, 0xab, + 0x0a, 0x2d, 0x10, 0x7c, 0x0f, 0xb5, 0x4b, 0x11, 0xcd, 0x32, 0x03, 0xc7, 0x5b, 0x0c, 0xb4, 0xbd, + 0xde, 0x22, 0xe9, 0x8d, 0xae, 0x2a, 0x54, 0xb2, 0x0f, 0x6f, 0x40, 0x57, 0x08, 0x1a, 0x40, 0xbc, + 0x6c, 0x2c, 0xe2, 0xe1, 0x29, 0xec, 0x48, 0x01, 0x2f, 0x1e, 0xd5, 0xd6, 0x91, 0x0a, 0xe2, 0x99, + 0xae, 0x1e, 0xc2, 0xd9, 0xdb, 0xef, 0x27, 0x63, 0x9e, 0x4c, 0x16, 0x83, 0x54, 0xd2, 0x99, 0x2c, + 0xe7, 0x4c, 0x4c, 0x59, 0x30, 0x66, 0xa2, 0x33, 0x92, 0x37, 0xa6, 0x23, 0x7f, 0x2a, 0x71, 0xf6, + 0x8b, 0x19, 0xe8, 0x32, 0x3c, 0xfd, 0x17, 0x00, 0x00, 0xff, 0xff, 0x3c, 0x15, 0xbd, 0x99, 0x9e, + 0x04, 0x00, 0x00, } diff --git a/protos/common/configuration.proto b/protos/common/configuration.proto index 5409a8b4d60..a3ddfb58b93 100644 --- a/protos/common/configuration.proto +++ b/protos/common/configuration.proto @@ -73,12 +73,18 @@ message ConfigurationSignature { bytes signature = 2; // Signature over the concatenation of configurationItem bytes and signatureHeader bytes } +// + // Policy expresses a policy which the orderer can evaluate, because there has been some desire expressed to support // multiple policy engines, this is typed as a oneof for now message Policy { - oneof Type { - SignaturePolicyEnvelope SignaturePolicy = 1; + enum PolicyType { + UNKNOWN = 0; // Reserved to check for proper initialization + SIGNATURE = 1; + MSP = 2; } + int32 type = 1; // For outside implementors, consider the first 1000 types reserved, otherwise one of PolicyType + bytes policy = 2; } // SignaturePolicyEnvelope wraps a SignaturePolicy and includes a version for future enhancements diff --git a/protos/orderer/ab.pb.go b/protos/orderer/ab.pb.go index d1b9f04961d..5bf48646e59 100644 --- a/protos/orderer/ab.pb.go +++ b/protos/orderer/ab.pb.go @@ -20,6 +20,7 @@ It has these top-level messages: DeliverResponse ConsensusType BatchSize + BatchTimeout CreationPolicy ChainCreators KafkaBrokers diff --git a/protos/utils/configurationutils.go b/protos/utils/configurationutils.go index 3c02f74c47a..965533c4f88 100644 --- a/protos/utils/configurationutils.go +++ b/protos/utils/configurationutils.go @@ -20,6 +20,8 @@ import ( "fmt" cb "github.com/hyperledger/fabric/protos/common" + + "github.com/golang/protobuf/proto" ) // MakeConfigurationItem makes a ConfigurationItem. @@ -40,18 +42,12 @@ func MakeConfigurationEnvelope(items ...*cb.SignedConfigurationItem) *cb.Configu } // MakePolicyOrPanic creates a Policy proto message out of a SignaturePolicyEnvelope, and panics if this operation fails. -// NOTE Expand this as more policy types as supported. func MakePolicyOrPanic(policyEnvelope interface{}) *cb.Policy { - switch pe := policyEnvelope.(type) { - case *cb.SignaturePolicyEnvelope: - return &cb.Policy{ - Type: &cb.Policy_SignaturePolicy{ - SignaturePolicy: pe, - }, - } - default: - panic("Unknown policy envelope type given") + policy, err := MakePolicy(policyEnvelope) + if err != nil { + panic(err) } + return policy } // MakePolicy creates a Policy proto message out of a SignaturePolicyEnvelope. @@ -59,10 +55,13 @@ func MakePolicyOrPanic(policyEnvelope interface{}) *cb.Policy { func MakePolicy(policyEnvelope interface{}) (*cb.Policy, error) { switch pe := policyEnvelope.(type) { case *cb.SignaturePolicyEnvelope: + m, err := proto.Marshal(pe) + if err != nil { + return nil, err + } return &cb.Policy{ - Type: &cb.Policy_SignaturePolicy{ - SignaturePolicy: pe, - }, + Type: int32(cb.Policy_SIGNATURE), + Policy: m, }, nil default: return nil, fmt.Errorf("Unknown policy envelope type given")