-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hook configuration manager into solo broadcast
With the completion of the broadcast filtering framework, the configuration manager, the policy manager, and the genesis block creation, it is now possible for the orderer to filter and apply configuration received over the wire as a transaction. This changeset adds that functionality for the solo ordering service. https://jira.hyperledger.org/browse/FAB-593 Change-Id: I4e50c1f811d8cff02f67de7de278fbffe230f882 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
- Loading branch information
Jason Yellick
committed
Oct 27, 2016
1 parent
c883319
commit 73ea179
Showing
8 changed files
with
423 additions
and
59 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
orderer/common/broadcastfilter/configfilter/configfilter.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package configfilter | ||
|
||
import ( | ||
ab "github.com/hyperledger/fabric/orderer/atomicbroadcast" | ||
"github.com/hyperledger/fabric/orderer/common/broadcastfilter" | ||
"github.com/hyperledger/fabric/orderer/common/configtx" | ||
|
||
"github.com/golang/protobuf/proto" | ||
) | ||
|
||
type configFilter struct { | ||
configManager configtx.Manager | ||
} | ||
|
||
func New(manager configtx.Manager) broadcastfilter.Rule { | ||
return &configFilter{ | ||
configManager: manager, | ||
} | ||
} | ||
|
||
// Apply applies the rule to the given BroadcastMessage, replying with the Action to take for the message | ||
func (cf *configFilter) Apply(message *ab.BroadcastMessage) broadcastfilter.Action { | ||
config := &ab.ConfigurationEnvelope{} | ||
|
||
err := proto.Unmarshal(message.Data, config) | ||
if err != nil { | ||
return broadcastfilter.Forward | ||
} | ||
|
||
err = cf.configManager.Validate(config) | ||
if err != nil { | ||
return broadcastfilter.Reject | ||
} | ||
|
||
return broadcastfilter.Reconfigure | ||
} |
73 changes: 73 additions & 0 deletions
73
orderer/common/broadcastfilter/configfilter/configfilter_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package configfilter | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
ab "github.com/hyperledger/fabric/orderer/atomicbroadcast" | ||
"github.com/hyperledger/fabric/orderer/common/broadcastfilter" | ||
|
||
"github.com/golang/protobuf/proto" | ||
) | ||
|
||
type mockConfigManager struct { | ||
err error | ||
} | ||
|
||
func (mcm *mockConfigManager) Validate(configtx *ab.ConfigurationEnvelope) error { | ||
return mcm.err | ||
} | ||
|
||
func (mcm *mockConfigManager) Apply(configtx *ab.ConfigurationEnvelope) error { | ||
return mcm.err | ||
} | ||
|
||
func TestForwardNonConfig(t *testing.T) { | ||
cf := New(&mockConfigManager{}) | ||
result := cf.Apply(&ab.BroadcastMessage{ | ||
Data: []byte("Opaque"), | ||
}) | ||
if result != broadcastfilter.Forward { | ||
t.Fatalf("Should have forwarded opaque message") | ||
} | ||
} | ||
|
||
func TestAcceptGoodConfig(t *testing.T) { | ||
cf := New(&mockConfigManager{}) | ||
config := &ab.ConfigurationEnvelope{} | ||
configBytes, _ := proto.Marshal(config) | ||
result := cf.Apply(&ab.BroadcastMessage{ | ||
Data: configBytes, | ||
}) | ||
if result != broadcastfilter.Reconfigure { | ||
t.Fatalf("Should have indiated a good config message causes a reconfiguration") | ||
} | ||
} | ||
|
||
func TestRejectBadConfig(t *testing.T) { | ||
cf := New(&mockConfigManager{err: fmt.Errorf("Error")}) | ||
config := &ab.ConfigurationEnvelope{} | ||
configBytes, _ := proto.Marshal(config) | ||
result := cf.Apply(&ab.BroadcastMessage{ | ||
Data: configBytes, | ||
}) | ||
if result != broadcastfilter.Reject { | ||
t.Fatalf("Should have rejected bad config message") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.