{"modulePath":"github.com/2lambda123/hyperledger-fabric","version":"v2.1.1+incompatible","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package msgprocessor\n\nPackage msgprocessor provides the implementations for processing of the assorted message types which may arrive in the system through Broadcast.\n\n## Variables\n\n```go\nvar AcceptRule = Rule(acceptRule{})\n```\nAcceptRule always returns Accept as a result for Apply\n\n```go\nvar EmptyRejectRule = Rule(emptyRejectRule{})\n```\nEmptyRejectRule rejects empty messages\n\n```go\nvar ErrChannelDoesNotExist = errors.New(\"channel does not exist\")\n```\nErrChannelDoesNotExist is returned by the system channel for transactions which are not for the system channel ID and are not attempting to create a new channel\n\n```go\nvar ErrEmptyMessage = errors.New(\"Message was empty\")\n```\nErrEmptyMessage is returned by the empty message filter on rejection.\n\n```go\nvar ErrMaintenanceMode = errors.New(\"maintenance mode\")\n```\nErrMaintenanceMode is returned when transactions are rejected because the orderer is in \"maintenance mode\", as defined by ConsensusType.State != NORMAL. This typically happens during consensus-type migration.\n\n```go\nvar ErrPermissionDenied = errors.New(\"permission denied\")\n```\nErrPermissionDenied is returned by errors which are caused by transactions which are not permitted due to an authorization failure.\n\n## Types\n\n```go\ntype ChainCreator interface {\n\t// NewChannelConfig returns a template config for a new channel.\n\tNewChannelConfig(envConfigUpdate *cb.Envelope) (channelconfig.Resources, error)\n\n\t// CreateBundle parses the config into resources\n\tCreateBundle(channelID string, config *cb.Config) (channelconfig.Resources, error)\n\n\t// ChannelsCount returns the count of channels which currently exist.\n\tChannelsCount() int\n}\n```\nChainCreator defines the methods necessary to simulate channel creation.\n\n```go\ntype ChannelConfigTemplator interface {\n\t// NewChannelConfig creates a new template configuration manager.\n\tNewChannelConfig(env *cb.Envelope) (channelconfig.Resources, error)\n}\n```\nChannelConfigTemplator can be used to generate config templates.\n\n```go\ntype Classification int\n```\nClassification represents the possible message types for the system.\n\n```go\nconst (\n\t// NormalMsg is the class of standard (endorser or otherwise non-config) messages.\n\t// Messages of this type should be processed by ProcessNormalMsg.\n\tNormalMsg Classification = iota\n\n\t// ConfigUpdateMsg indicates messages of type CONFIG_UPDATE.\n\t// Messages of this type should be processed by ProcessConfigUpdateMsg.\n\tConfigUpdateMsg\n\n\t// ConfigMsg indicates message of type ORDERER_TRANSACTION or CONFIG.\n\t// Messages of this type should be processed by ProcessConfigMsg\n\tConfigMsg\n)\n```\n\n```go\ntype DefaultTemplator struct {\n\t// contains filtered or unexported fields\n}\n```\nDefaultTemplator implements the ChannelConfigTemplator interface and is the one used in production deployments.\n\n```go\nfunc NewDefaultTemplator(support DefaultTemplatorSupport, bccsp bccsp.BCCSP) *DefaultTemplator\n```\nNewDefaultTemplator returns an instance of the DefaultTemplator.\n\n```go\nfunc (dt *DefaultTemplator) NewChannelConfig(envConfigUpdate *cb.Envelope) (channelconfig.Resources, error)\n```\nNewChannelConfig creates a new template channel configuration based on the current config in the ordering system channel.\n\n```go\ntype DefaultTemplatorSupport interface {\n\t// ConsortiumsConfig returns the ordering system channel's Consortiums config.\n\tConsortiumsConfig() (channelconfig.Consortiums, bool)\n\n\t// OrdererConfig returns the ordering configuration and whether the configuration exists\n\tOrdererConfig() (channelconfig.Orderer, bool)\n\n\t// ConfigtxValidator returns the configtx manager corresponding to the system channel's current config.\n\tConfigtxValidator() configtx.Validator\n\n\t// Signer returns the local signer suitable for signing forwarded messages.\n\tSigner() identity.SignerSerializer\n}\n```\nDefaultTemplatorSupport is the subset of the channel config required by the DefaultTemplator.\n\n```go\ntype LimitedSupport interface {\n\tOrdererConfig() (channelconfig.Orderer, bool)\n}\n```\nLimitedSupport defines the subset of the channel resources required by the systemchannel filter.\n\n```go\ntype MaintenanceFilter struct {\n\t// contains filtered or unexported fields\n}\n```\nMaintenanceFilter checks whether the orderer config ConsensusType is in maintenance mode, and if it is, validates that the transaction is signed by the orderer org admin.\n\n```go\nfunc NewMaintenanceFilter(support MaintenanceFilterSupport, bccsp bccsp.BCCSP) *MaintenanceFilter\n```\nNewMaintenanceFilter creates a new maintenance filter, at every evaluation, the policy manager and orderer config are called to retrieve the latest version of the policy and config.\n\n```go\nfunc (mf *MaintenanceFilter) Apply(message *cb.Envelope) error\n```\nApply applies the maintenance filter on a CONFIG tx.\n\n```go\ntype MaintenanceFilterSupport interface {\n\t// OrdererConfig returns the config.Orderer for the channel and whether the Orderer config exists\n\tOrdererConfig() (channelconfig.Orderer, bool)\n\t// ChannelID returns the ChannelID\n\tChannelID() string\n}\n```\nMaintenanceFilterSupport provides the resources required for the maintenance filter.\n\n```go\ntype MaxBytesRule struct {\n\t// contains filtered or unexported fields\n}\n```\nMaxBytesRule implements the Rule interface.\n\n```go\nfunc NewSizeFilter(resources SizeFilterResources) *MaxBytesRule\n```\nNewSizeFilter creates a size filter which rejects messages larger than maxBytes\n\n```go\nfunc (r *MaxBytesRule) Apply(message *common.Envelope) error\n```\nApply returns an error if the message exceeds the configured absolute max batch size.\n\n```go\ntype MetadataValidator interface {\n\tValidateConsensusMetadata(oldMetadata, newMetadata []byte, newChannel bool) error\n}\n```\nMetadataValidator can be used to validate updates to the consensus-specific metadata.\n\n```go\ntype Processor interface {\n\t// ClassifyMsg inspects the message header to determine which type of processing is necessary\n\tClassifyMsg(chdr *cb.ChannelHeader) Classification\n\n\t// ProcessNormalMsg will check the validity of a message based on the current configuration.  It returns the current\n\t// configuration sequence number and nil on success, or an error if the message is not valid\n\tProcessNormalMsg(env *cb.Envelope) (configSeq uint64, err error)\n\n\t// ProcessConfigUpdateMsg will attempt to apply the config update to the current configuration, and if successful\n\t// return the resulting config message and the configSeq the config was computed from.  If the config update message\n\t// is invalid, an error is returned.\n\tProcessConfigUpdateMsg(env *cb.Envelope) (config *cb.Envelope, configSeq uint64, err error)\n\n\t// ProcessConfigMsg takes message of type `ORDERER_TX` or `CONFIG`, unpack the ConfigUpdate envelope embedded\n\t// in it, and call `ProcessConfigUpdateMsg` to produce new Config message of the same type as original message.\n\t// This method is used to re-validate and reproduce config message, if it's deemed not to be valid anymore.\n\tProcessConfigMsg(env *cb.Envelope) (*cb.Envelope, uint64, error)\n}\n```\nProcessor provides the methods necessary to classify and process any message which arrives through the Broadcast interface.\n\n```go\ntype Rule interface {\n\t// Apply applies the rule to the given Envelope, either successfully or returns error\n\tApply(message *ab.Envelope) error\n}\n```\nRule defines a filter function which accepts, rejects, or forwards (to the next rule) an Envelope\n\n```go\nfunc NewExpirationRejectRule(filterSupport resources) Rule\n```\nNewExpirationRejectRule returns a rule that rejects messages signed by identities who's identities have expired, given the capability is active\n\n```go\ntype RuleSet struct {\n\t// contains filtered or unexported fields\n}\n```\nRuleSet is used to apply a collection of rules\n\n```go\nfunc CreateStandardChannelFilters(filterSupport channelconfig.Resources, config localconfig.TopLevel) *RuleSet\n```\nCreateStandardChannelFilters creates the set of filters for a normal (non-system) chain.\n\nIn maintenance mode, require the signature of /Channel/Orderer/Writer. This will filter out configuration changes that are not related to consensus-type migration (e.g on /Channel/Application).\n\n```go\nfunc CreateSystemChannelFilters(\n\tconfig localconfig.TopLevel,\n\tchainCreator ChainCreator,\n\tledgerResources channelconfig.Resources,\n\tvalidator MetadataValidator,\n) *RuleSet\n```\nCreateSystemChannelFilters creates the set of filters for the ordering system chain.\n\nIn maintenance mode, require the signature of /Channel/Orderer/Writers. This will filter out configuration changes that are not related to consensus-type migration (e.g on /Channel/Application).\n\n```go\nfunc NewRuleSet(rules []Rule) *RuleSet\n```\nNewRuleSet creates a new RuleSet with the given ordered list of Rules\n\n```go\nfunc (rs *RuleSet) Apply(message *ab.Envelope) error\n```\nApply applies the rules given for this set in order, returning nil on valid or err on invalid\n\n```go\ntype SigFilter struct {\n\t// contains filtered or unexported fields\n}\n```\nSigFilter stores the name of the policy to apply to deliver requests to determine whether a client is authorized\n\n```go\nfunc NewSigFilter(normalPolicyName, maintenancePolicyName string, support SigFilterSupport) *SigFilter\n```\nNewSigFilter creates a new signature filter, at every evaluation, the policy manager is called to retrieve the latest version of the policy.\n\nnormalPolicyName is applied when Orderer/ConsensusType.State = NORMAL maintenancePolicyName is applied when Orderer/ConsensusType.State = MAINTENANCE\n\n```go\nfunc (sf *SigFilter) Apply(message *cb.Envelope) error\n```\nApply applies the policy given, resulting in Reject or Forward, never Accept\n\n```go\ntype SigFilterSupport interface {\n\t// PolicyManager returns a reference to the current policy manager\n\tPolicyManager() policies.Manager\n\t// OrdererConfig returns the config.Orderer for the channel and whether the Orderer config exists\n\tOrdererConfig() (channelconfig.Orderer, bool)\n}\n```\nSigFilterSupport provides the resources required for the signature filter\n\n```go\ntype SizeFilterResources interface {\n\t// OrdererConfig returns the config.Orderer for the channel and whether the Orderer config exists\n\tOrdererConfig() (channelconfig.Orderer, bool)\n}\n```\nSizeFilterResources defines the subset of the channel resources required to create this filter\n\n```go\ntype StandardChannel struct {\n\t// contains filtered or unexported fields\n}\n```\nStandardChannel implements the Processor interface for standard extant channels\n\n```go\nfunc NewStandardChannel(support StandardChannelSupport, filters *RuleSet, bccsp bccsp.BCCSP) *StandardChannel\n```\nNewStandardChannel creates a new standard message processor\n\n```go\nfunc (s *StandardChannel) ClassifyMsg(chdr *cb.ChannelHeader) Classification\n```\nClassifyMsg inspects the message to determine which type of processing is necessary\n\n```go\nfunc (s *StandardChannel) ProcessConfigMsg(env *cb.Envelope) (config *cb.Envelope, configSeq uint64, err error)\n```\nProcessConfigMsg takes an envelope of type \\`HeaderType\\_CONFIG\\`, unpacks the \\`ConfigEnvelope\\` from it extracts the \\`ConfigUpdate\\` from \\`LastUpdate\\` field, and calls \\`ProcessConfigUpdateMsg\\` on it.\n\n```go\nfunc (s *StandardChannel) ProcessConfigUpdateMsg(env *cb.Envelope) (config *cb.Envelope, configSeq uint64, err error)\n```\nProcessConfigUpdateMsg will attempt to apply the config impetus msg to the current configuration, and if successful return the resulting config message and the configSeq the config was computed from.  If the config impetus message is invalid, an error is returned.\n\n```go\nfunc (s *StandardChannel) ProcessNormalMsg(env *cb.Envelope) (configSeq uint64, err error)\n```\nProcessNormalMsg will check the validity of a message based on the current configuration.  It returns the current configuration sequence number and nil on success, or an error if the message is not valid\n\n```go\ntype StandardChannelSupport interface {\n\t// Sequence should return the current configSeq\n\tSequence() uint64\n\n\t// ChannelID returns the ChannelID\n\tChannelID() string\n\n\t// Signer returns the signer for this orderer\n\tSigner() identity.SignerSerializer\n\n\t// ProposeConfigUpdate takes in an Envelope of type CONFIG_UPDATE and produces a\n\t// ConfigEnvelope to be used as the Envelope Payload Data of a CONFIG message\n\tProposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigEnvelope, error)\n\n\tOrdererConfig() (channelconfig.Orderer, bool)\n}\n```\nStandardChannelSupport includes the resources needed for the StandardChannel processor.\n\n```go\ntype SystemChainFilter struct {\n\t// contains filtered or unexported fields\n}\n```\nSystemChainFilter implements the filter.Rule interface.\n\n```go\nfunc NewSystemChannelFilter(ls LimitedSupport, cc ChainCreator, validator MetadataValidator) *SystemChainFilter\n```\nNewSystemChannelFilter returns a new instance of a \\*SystemChainFilter.\n\n```go\nfunc (scf *SystemChainFilter) Apply(env *cb.Envelope) error\n```\nApply rejects bad messages with an error.\n\n```go\ntype SystemChannel struct {\n\t*StandardChannel\n\t// contains filtered or unexported fields\n}\n```\nSystemChannel implements the Processor interface for the system channel.\n\n```go\nfunc NewSystemChannel(support StandardChannelSupport, templator ChannelConfigTemplator, filters *RuleSet, bccsp bccsp.BCCSP) *SystemChannel\n```\nNewSystemChannel creates a new system channel message processor.\n\n```go\nfunc (s *SystemChannel) ProcessConfigMsg(env *cb.Envelope) (*cb.Envelope, uint64, error)\n```\nProcessConfigMsg takes envelope of following two types:\n\n  - \\`HeaderType\\_CONFIG\\`: system channel itself is the target of config, we simply unpack \\`ConfigUpdate\\` envelope from \\`LastUpdate\\` field and call \\`ProcessConfigUpdateMsg\\` on the underlying standard channel\n  - \\`HeaderType\\_ORDERER\\_TRANSACTION\\`: it's a channel creation message, we unpack \\`ConfigUpdate\\` envelope and run \\`ProcessConfigUpdateMsg\\` on it\n\n```go\nfunc (s *SystemChannel) ProcessConfigUpdateMsg(envConfigUpdate *cb.Envelope) (config *cb.Envelope, configSeq uint64, err error)\n```\nProcessConfigUpdateMsg handles messages of type CONFIG\\_UPDATE either for the system channel itself or, for channel creation.  In the channel creation case, the CONFIG\\_UPDATE is wrapped into a resulting ORDERER\\_TRANSACTION, and in the standard CONFIG\\_UPDATE case, a resulting CONFIG message\n\n```go\nfunc (s *SystemChannel) ProcessNormalMsg(msg *cb.Envelope) (configSeq uint64, err error)\n```\nProcessNormalMsg handles normal messages, rejecting them if they are not bound for the system channel ID with ErrChannelDoesNotExist.\n\n","path":"github.com/2lambda123/hyperledger-fabric/orderer/common/msgprocessor","name":"msgprocessor","synopsis":"Package msgprocessor provides the implementations for processing of the assorted message types which may arrive in the system through Broadcast.","isRedistributable":true}
