github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/protos/orderer/configuration.go (about) 1 /* 2 Copyright IBM Corp. 2017 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package orderer 18 19 import ( 20 "fmt" 21 22 "github.com/hyperledger/fabric/protos/common" 23 "github.com/hyperledger/fabric/protos/msp" 24 25 "github.com/golang/protobuf/proto" 26 ) 27 28 func init() { 29 common.ChannelGroupMap["Orderer"] = DynamicOrdererGroupFactory{} 30 } 31 32 type DynamicOrdererGroupFactory struct{} 33 34 func (dogf DynamicOrdererGroupFactory) DynamicConfigGroup(cg *common.ConfigGroup) proto.Message { 35 return &DynamicOrdererGroup{ 36 ConfigGroup: cg, 37 } 38 } 39 40 type DynamicOrdererGroup struct { 41 *common.ConfigGroup 42 } 43 44 func (dcg *DynamicOrdererGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) { 45 switch name { 46 case "groups": 47 cg, ok := base.(*common.ConfigGroup) 48 if !ok { 49 return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigGroup messages") 50 } 51 52 return &DynamicOrdererOrgGroup{ 53 ConfigGroup: cg, 54 }, nil 55 case "values": 56 cv, ok := base.(*common.ConfigValue) 57 if !ok { 58 return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages") 59 } 60 return &DynamicOrdererConfigValue{ 61 ConfigValue: cv, 62 name: key, 63 }, nil 64 default: 65 return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name) 66 } 67 } 68 69 type DynamicOrdererOrgGroup struct { 70 *common.ConfigGroup 71 } 72 73 func (dcg *DynamicOrdererOrgGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) { 74 switch name { 75 case "groups": 76 return nil, fmt.Errorf("the orderer orgs do not support sub-groups") 77 case "values": 78 cv, ok := base.(*common.ConfigValue) 79 if !ok { 80 return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages") 81 } 82 83 return &DynamicOrdererOrgConfigValue{ 84 ConfigValue: cv, 85 name: key, 86 }, nil 87 default: 88 return nil, fmt.Errorf("not a dynamic orderer map field: %s", name) 89 } 90 } 91 92 type DynamicOrdererConfigValue struct { 93 *common.ConfigValue 94 name string 95 } 96 97 func (docv *DynamicOrdererConfigValue) VariablyOpaqueFieldProto(name string) (proto.Message, error) { 98 if name != docv.VariablyOpaqueFields()[0] { 99 return nil, fmt.Errorf("not a marshaled field: %s", name) 100 } 101 switch docv.name { 102 case "ConsensusType": 103 return &ConsensusType{}, nil 104 case "BatchSize": 105 return &BatchSize{}, nil 106 case "BatchTimeout": 107 return &BatchTimeout{}, nil 108 case "KafkaBrokers": 109 return &KafkaBrokers{}, nil 110 case "ChannelRestrictions": 111 return &ChannelRestrictions{}, nil 112 default: 113 return nil, fmt.Errorf("unknown Orderer ConfigValue name: %s", docv.name) 114 } 115 } 116 117 type DynamicOrdererOrgConfigValue struct { 118 *common.ConfigValue 119 name string 120 } 121 122 func (doocv *DynamicOrdererOrgConfigValue) VariablyOpaqueFieldProto(name string) (proto.Message, error) { 123 if name != doocv.VariablyOpaqueFields()[0] { 124 return nil, fmt.Errorf("not a marshaled field: %s", name) 125 } 126 switch doocv.name { 127 case "MSP": 128 return &msp.MSPConfig{}, nil 129 default: 130 return nil, fmt.Errorf("unknown Orderer Org ConfigValue name: %s", doocv.name) 131 } 132 }