Skip to content

Commit d139cae

Browse files
author
Jason Yellick
committed
[FAB-5317] Cleanup filters package cruft
The filters package has been changed significantly over the course of development, and especially so with the recent removal of the committers concept. This has left a lot of cruft which actually makes the package less usable and less testable. This CR removes all that cruft, resulting in a significant decrease in lines of code, while improving the quality of the tests. Change-Id: I3dc131b5775bde3b198b6f33438a076041a38ed0 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 6506805 commit d139cae

File tree

13 files changed

+150
-495
lines changed

13 files changed

+150
-495
lines changed

orderer/common/deliver/deliver.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
"github.com/hyperledger/fabric/common/policies"
2323
"github.com/hyperledger/fabric/orderer/common/ledger"
24-
"github.com/hyperledger/fabric/orderer/common/msgprocessor/filter"
2524
"github.com/hyperledger/fabric/orderer/common/msgprocessor/sigfilter"
2625
cb "github.com/hyperledger/fabric/protos/common"
2726
ab "github.com/hyperledger/fabric/protos/orderer"
@@ -131,8 +130,8 @@ func (ds *deliverServer) deliverBlocks(srv ab.AtomicBroadcast_DeliverServer, env
131130
lastConfigSequence := chain.Sequence()
132131

133132
sf := sigfilter.New(policies.ChannelReaders, chain.PolicyManager())
134-
if sf.Apply(envelope) != filter.Forward {
135-
logger.Warningf("[channel: %s] Received unauthorized deliver request", chdr.ChannelId)
133+
if err := sf.Apply(envelope); err != nil {
134+
logger.Warningf("[channel: %s] Received unauthorized deliver request: %s", chdr.ChannelId, err)
136135
return sendStatusReply(srv, cb.Status_FORBIDDEN)
137136
}
138137

@@ -185,8 +184,8 @@ func (ds *deliverServer) deliverBlocks(srv ab.AtomicBroadcast_DeliverServer, env
185184
if currentConfigSequence > lastConfigSequence {
186185
lastConfigSequence = currentConfigSequence
187186
sf := sigfilter.New(policies.ChannelReaders, chain.PolicyManager())
188-
if sf.Apply(envelope) != filter.Forward {
189-
logger.Warningf("[channel: %s] Client authorization revoked for deliver request", chdr.ChannelId)
187+
if err := sf.Apply(envelope); err != nil {
188+
logger.Warningf("[channel: %s] Client authorization revoked for deliver request: %s", chdr.ChannelId, err)
190189
return sendStatusReply(srv, cb.Status_FORBIDDEN)
191190
}
192191
}

orderer/common/msgprocessor/configtxfilter/filter.go

Lines changed: 0 additions & 69 deletions
This file was deleted.

orderer/common/msgprocessor/configtxfilter/filter_test.go

Lines changed: 0 additions & 123 deletions
This file was deleted.
Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,45 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
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.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package filter
188

199
import (
20-
"fmt"
10+
"errors"
2111

2212
ab "github.com/hyperledger/fabric/protos/common"
2313
)
2414

25-
// Action is used to express the output of a rule
26-
type Action int
27-
28-
const (
29-
// Accept indicates that the message should be processed
30-
Accept = iota
31-
// Reject indicates that the message should not be processed
32-
Reject
33-
// Forward indicates that the rule could not determine the correct course of action
34-
Forward
35-
)
15+
// ErrEmptyMessage is returned by the empty message filter on rejection.
16+
var ErrEmptyMessage = errors.New("Message was empty")
3617

3718
// Rule defines a filter function which accepts, rejects, or forwards (to the next rule) an Envelope
3819
type Rule interface {
39-
// Apply applies the rule to the given Envelope, replying with the Action to take for the message
40-
Apply(message *ab.Envelope) Action
20+
// Apply applies the rule to the given Envelope, either successfully or returns error
21+
Apply(message *ab.Envelope) error
4122
}
4223

4324
// EmptyRejectRule rejects empty messages
4425
var EmptyRejectRule = Rule(emptyRejectRule{})
4526

4627
type emptyRejectRule struct{}
4728

48-
func (a emptyRejectRule) Apply(message *ab.Envelope) Action {
29+
func (a emptyRejectRule) Apply(message *ab.Envelope) error {
4930
if message.Payload == nil {
50-
return Reject
31+
return ErrEmptyMessage
5132
}
52-
return Forward
33+
return nil
5334
}
5435

5536
// AcceptRule always returns Accept as a result for Apply
5637
var AcceptRule = Rule(acceptRule{})
5738

5839
type acceptRule struct{}
5940

60-
func (a acceptRule) Apply(message *ab.Envelope) Action {
61-
return Accept
41+
func (a acceptRule) Apply(message *ab.Envelope) error {
42+
return nil
6243
}
6344

6445
// RuleSet is used to apply a collection of rules
@@ -76,14 +57,10 @@ func NewRuleSet(rules []Rule) *RuleSet {
7657
// Apply applies the rules given for this set in order, returning nil on valid or err on invalid
7758
func (rs *RuleSet) Apply(message *ab.Envelope) error {
7859
for _, rule := range rs.rules {
79-
action := rule.Apply(message)
80-
switch action {
81-
case Accept:
82-
return nil
83-
case Reject:
84-
return fmt.Errorf("Rejected by rule: %T", rule)
85-
default:
60+
err := rule.Apply(message)
61+
if err != nil {
62+
return err
8663
}
8764
}
88-
return fmt.Errorf("No matching filter found")
65+
return nil
8966
}

0 commit comments

Comments
 (0)