msgprocessor

package
v1.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package msgprocessor provides the implementations for processing of the assorted message types which may arrive in the system through Broadcast.

Index

Constants

This section is empty.

Variables

View Source
var AcceptRule = Rule(acceptRule{})

AcceptRule always returns Accept as a result for Apply

View Source
var EmptyRejectRule = Rule(emptyRejectRule{})

EmptyRejectRule rejects empty messages

View Source
var ErrChannelDoesNotExist = errors.New("channel does not exist")

ErrChannelDoesNotExist 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

View Source
var ErrEmptyMessage = errors.New("Message was empty")

ErrEmptyMessage is returned by the empty message filter on rejection.

View Source
var ErrMaintenanceMode = errors.New("maintenance mode")

ErrMaintenanceMode 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.

View Source
var ErrPermissionDenied = errors.New("permission denied")

ErrPermissionDenied is returned by errors which are caused by transactions which are not permitted due to an authorization failure.

Functions

This section is empty.

Types

type ChainCreator

type ChainCreator interface {
	// NewChannelConfig returns a template config for a new channel.
	NewChannelConfig(envConfigUpdate *cb.Envelope) (channelconfig.Resources, error)

	// CreateBundle parses the config into resources
	CreateBundle(channelID string, config *cb.Config) (channelconfig.Resources, error)

	// ChannelsCount returns the count of channels which currently exist.
	ChannelsCount() int
}

ChainCreator defines the methods necessary to simulate channel creation.

type ChannelConfigTemplator

type ChannelConfigTemplator interface {
	// NewChannelConfig creates a new template configuration manager.
	NewChannelConfig(env *cb.Envelope) (channelconfig.Resources, error)
}

ChannelConfigTemplator can be used to generate config templates.

type Classification

type Classification int

Classification represents the possible message types for the system.

const (
	// NormalMsg is the class of standard (endorser or otherwise non-config) messages.
	// Messages of this type should be processed by ProcessNormalMsg.
	NormalMsg Classification = iota

	// ConfigUpdateMsg indicates messages of type CONFIG_UPDATE.
	// Messages of this type should be processed by ProcessConfigUpdateMsg.
	ConfigUpdateMsg

	// ConfigMsg indicates message of type ORDERER_TRANSACTION or CONFIG.
	// Messages of this type should be processed by ProcessConfigMsg
	ConfigMsg
)

type DefaultTemplator

type DefaultTemplator struct {
	// contains filtered or unexported fields
}

DefaultTemplator implements the ChannelConfigTemplator interface and is the one used in production deployments.

func NewDefaultTemplator

func NewDefaultTemplator(support DefaultTemplatorSupport) *DefaultTemplator

NewDefaultTemplator returns an instance of the DefaultTemplator.

func (*DefaultTemplator) NewChannelConfig

func (dt *DefaultTemplator) NewChannelConfig(envConfigUpdate *cb.Envelope) (channelconfig.Resources, error)

NewChannelConfig creates a new template channel configuration based on the current config in the ordering system channel.

type DefaultTemplatorSupport

type DefaultTemplatorSupport interface {
	// ConsortiumsConfig returns the ordering system channel's Consortiums config.
	ConsortiumsConfig() (channelconfig.Consortiums, bool)

	// OrdererConfig returns the ordering configuration and whether the configuration exists
	OrdererConfig() (channelconfig.Orderer, bool)

	// ConfigtxValidator returns the configtx manager corresponding to the system channel's current config.
	ConfigtxValidator() configtx.Validator

	// Signer returns the local signer suitable for signing forwarded messages.
	Signer() crypto.LocalSigner
}

DefaultTemplatorSupport is the subset of the channel config required by the DefaultTemplator.

type LimitedSupport

type LimitedSupport interface {
	OrdererConfig() (channelconfig.Orderer, bool)
}

LimitedSupport defines the subset of the channel resources required by the systemchannel filter.

type MaintenanceFilter added in v1.4.2

type MaintenanceFilter struct {
	// contains filtered or unexported fields
}

MaintenanceFilter 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.

func NewMaintenanceFilter added in v1.4.2

func NewMaintenanceFilter(support MaintenanceFilterSupport) *MaintenanceFilter

NewMaintenanceFilter 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.

func (*MaintenanceFilter) Apply added in v1.4.2

func (mf *MaintenanceFilter) Apply(message *cb.Envelope) error

Apply applies the maintenance filter on a CONFIG tx.

type MaintenanceFilterSupport added in v1.4.2

type MaintenanceFilterSupport interface {
	// OrdererConfig returns the config.Orderer for the channel and whether the Orderer config exists
	OrdererConfig() (channelconfig.Orderer, bool)

	ChainID() string
}

MaintenanceFilterSupport provides the resources required for the maintenance filter.

type MaxBytesRule

type MaxBytesRule struct {
	// contains filtered or unexported fields
}

MaxBytesRule implements the Rule interface.

func NewSizeFilter

func NewSizeFilter(resources SizeFilterResources) *MaxBytesRule

NewSizeFilter creates a size filter which rejects messages larger than maxBytes

func (*MaxBytesRule) Apply

func (r *MaxBytesRule) Apply(message *common.Envelope) error

Apply returns an error if the message exceeds the configured absolute max batch size.

type Processor

type Processor interface {
	// ClassifyMsg inspects the message header to determine which type of processing is necessary
	ClassifyMsg(chdr *cb.ChannelHeader) Classification

	// ProcessNormalMsg 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
	ProcessNormalMsg(env *cb.Envelope) (configSeq uint64, err error)

	// ProcessConfigUpdateMsg will attempt to apply the config update to the current configuration, and if successful
	// return the resulting config message and the configSeq the config was computed from.  If the config update message
	// is invalid, an error is returned.
	ProcessConfigUpdateMsg(env *cb.Envelope) (config *cb.Envelope, configSeq uint64, err error)

	// ProcessConfigMsg takes message of type `ORDERER_TX` or `CONFIG`, unpack the ConfigUpdate envelope embedded
	// in it, and call `ProcessConfigUpdateMsg` to produce new Config message of the same type as original message.
	// This method is used to re-validate and reproduce config message, if it's deemed not to be valid anymore.
	ProcessConfigMsg(env *cb.Envelope) (*cb.Envelope, uint64, error)
}

Processor provides the methods necessary to classify and process any message which arrives through the Broadcast interface.

type Rule

type Rule interface {
	// Apply applies the rule to the given Envelope, either successfully or returns error
	Apply(message *ab.Envelope) error
}

Rule defines a filter function which accepts, rejects, or forwards (to the next rule) an Envelope

func NewExpirationRejectRule

func NewExpirationRejectRule(filterSupport resources) Rule

NewExpirationRejectRule returns a rule that rejects messages signed by identities who's identities have expired, given the capability is active

type RuleSet

type RuleSet struct {
	// contains filtered or unexported fields
}

RuleSet is used to apply a collection of rules

func CreateStandardChannelFilters

func CreateStandardChannelFilters(filterSupport channelconfig.Resources, config localconfig.TopLevel) *RuleSet

CreateStandardChannelFilters creates the set of filters for a normal (non-system) chain.

In 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).

func CreateSystemChannelFilters

func CreateSystemChannelFilters(chainCreator ChainCreator, ledgerResources channelconfig.Resources, config localconfig.TopLevel) *RuleSet

CreateSystemChannelFilters creates the set of filters for the ordering system chain.

In 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).

func NewRuleSet

func NewRuleSet(rules []Rule) *RuleSet

NewRuleSet creates a new RuleSet with the given ordered list of Rules

func (*RuleSet) Apply

func (rs *RuleSet) Apply(message *ab.Envelope) error

Apply applies the rules given for this set in order, returning nil on valid or err on invalid

type SigFilter

type SigFilter struct {
	// contains filtered or unexported fields
}

SigFilter stores the name of the policy to apply to deliver requests to determine whether a client is authorized

func NewSigFilter

func NewSigFilter(normalPolicyName, maintenancePolicyName string, support SigFilterSupport) *SigFilter

NewSigFilter creates a new signature filter, at every evaluation, the policy manager is called to retrieve the latest version of the policy.

normalPolicyName is applied when Orderer/ConsensusType.State = NORMAL maintenancePolicyName is applied when Orderer/ConsensusType.State = MAINTENANCE

func (*SigFilter) Apply

func (sf *SigFilter) Apply(message *cb.Envelope) error

Apply applies the policy given, resulting in Reject or Forward, never Accept

type SigFilterSupport

type SigFilterSupport interface {
	// PolicyManager returns a reference to the current policy manager
	PolicyManager() policies.Manager
	// OrdererConfig returns the config.Orderer for the channel and whether the Orderer config exists
	OrdererConfig() (channelconfig.Orderer, bool)
}

SigFilterSupport provides the resources required for the signature filter

type SizeFilterResources added in v1.4.2

type SizeFilterResources interface {
	// OrdererConfig returns the config.Orderer for the channel and whether the Orderer config exists
	OrdererConfig() (channelconfig.Orderer, bool)
}

SizeFilterResources defines the subset of the channel resources required to create this filter

type StandardChannel

type StandardChannel struct {
	// contains filtered or unexported fields
}

StandardChannel implements the Processor interface for standard extant channels

func NewStandardChannel

func NewStandardChannel(support StandardChannelSupport, filters *RuleSet) *StandardChannel

NewStandardChannel creates a new standard message processor

func (*StandardChannel) ClassifyMsg

func (s *StandardChannel) ClassifyMsg(chdr *cb.ChannelHeader) Classification

ClassifyMsg inspects the message to determine which type of processing is necessary

func (*StandardChannel) ProcessConfigMsg

func (s *StandardChannel) ProcessConfigMsg(env *cb.Envelope) (config *cb.Envelope, configSeq uint64, err error)

ProcessConfigMsg takes an envelope of type `HeaderType_CONFIG`, unpacks the `ConfigEnvelope` from it extracts the `ConfigUpdate` from `LastUpdate` field, and calls `ProcessConfigUpdateMsg` on it.

func (*StandardChannel) ProcessConfigUpdateMsg

func (s *StandardChannel) ProcessConfigUpdateMsg(env *cb.Envelope) (config *cb.Envelope, configSeq uint64, err error)

ProcessConfigUpdateMsg 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.

func (*StandardChannel) ProcessNormalMsg

func (s *StandardChannel) ProcessNormalMsg(env *cb.Envelope) (configSeq uint64, err error)

ProcessNormalMsg 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

type StandardChannelSupport

type StandardChannelSupport interface {
	// Sequence should return the current configSeq
	Sequence() uint64

	// ChainID returns the ChannelID
	ChainID() string

	// Signer returns the signer for this orderer
	Signer() crypto.LocalSigner

	// ProposeConfigUpdate takes in an Envelope of type CONFIG_UPDATE and produces a
	// ConfigEnvelope to be used as the Envelope Payload Data of a CONFIG message
	ProposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigEnvelope, error)

	OrdererConfig() (channelconfig.Orderer, bool)
}

StandardChannelSupport includes the resources needed for the StandardChannel processor.

type SystemChainFilter

type SystemChainFilter struct {
	// contains filtered or unexported fields
}

SystemChainFilter implements the filter.Rule interface.

func NewSystemChannelFilter

func NewSystemChannelFilter(ls LimitedSupport, cc ChainCreator) *SystemChainFilter

NewSystemChannelFilter returns a new instance of a *SystemChainFilter.

func (*SystemChainFilter) Apply

func (scf *SystemChainFilter) Apply(env *cb.Envelope) error

Apply rejects bad messages with an error.

type SystemChannel

type SystemChannel struct {
	*StandardChannel
	// contains filtered or unexported fields
}

SystemChannel implements the Processor interface for the system channel.

func NewSystemChannel

func NewSystemChannel(support StandardChannelSupport, templator ChannelConfigTemplator, filters *RuleSet) *SystemChannel

NewSystemChannel creates a new system channel message processor.

func (*SystemChannel) ProcessConfigMsg

func (s *SystemChannel) ProcessConfigMsg(env *cb.Envelope) (*cb.Envelope, uint64, error)

ProcessConfigMsg takes envelope of following two types:

  • `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
  • `HeaderType_ORDERER_TRANSACTION`: it's a channel creation message, we unpack `ConfigUpdate` envelope and run `ProcessConfigUpdateMsg` on it

func (*SystemChannel) ProcessConfigUpdateMsg

func (s *SystemChannel) ProcessConfigUpdateMsg(envConfigUpdate *cb.Envelope) (config *cb.Envelope, configSeq uint64, err error)

ProcessConfigUpdateMsg 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

func (*SystemChannel) ProcessNormalMsg

func (s *SystemChannel) ProcessNormalMsg(msg *cb.Envelope) (configSeq uint64, err error)

ProcessNormalMsg handles normal messages, rejecting them if they are not bound for the system channel ID with ErrChannelDoesNotExist.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL