Skip to content

Commit

Permalink
[FAB-6627] MSPConfigHandler to support idemix MSPs
Browse files Browse the repository at this point in the history
This change set introduces support for the generation of idemix MSPs from
config transactions.

Change-Id: Ib1f82826a916eb9be9bc1a4337899a5a58281f2a
Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
  • Loading branch information
ale-linux committed Nov 1, 2017
1 parent a47bf65 commit 21539ef
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions common/channelconfig/msp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ package channelconfig
import (
"fmt"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/msp/cache"
mspprotos "github.com/hyperledger/fabric/protos/msp"

"github.com/golang/protobuf/proto"
"github.com/pkg/errors"
)

type pendingMSPConfig struct {
Expand All @@ -36,44 +36,54 @@ func NewMSPConfigHandler(mspVersion msp.MSPVersion) *MSPConfigHandler {

// ProposeValue called when an org defines an MSP
func (bh *MSPConfigHandler) ProposeMSP(mspConfig *mspprotos.MSPConfig) (msp.MSP, error) {
// check that the type for that MSP is supported
if mspConfig.Type != int32(msp.FABRIC) {
return nil, fmt.Errorf("Setup error: unsupported msp type %d", mspConfig.Type)
}

// create the msp instance
mspInst, err := msp.New(&msp.BCCSPNewOpts{NewBaseOpts: msp.NewBaseOpts{Version: bh.version}})
if err != nil {
return nil, fmt.Errorf("Creating the MSP manager failed, err %s", err)
}
var theMsp msp.MSP
var err error

switch mspConfig.Type {
case int32(msp.FABRIC):
// create the bccsp msp instance
mspInst, err := msp.New(&msp.BCCSPNewOpts{NewBaseOpts: msp.NewBaseOpts{Version: bh.version}})
if err != nil {
return nil, errors.WithMessage(err, "creating the MSP manager failed")
}

casheMSP, err := cache.New(mspInst)
if err != nil {
return nil, fmt.Errorf("Creating the MSP manager failed, err %s", err)
// add a cache layer on top
theMsp, err = cache.New(mspInst)
if err != nil {
return nil, errors.WithMessage(err, "creating the MSP cache failed")
}
case int32(msp.IDEMIX):
// create the idemix msp instance
theMsp, err = msp.New(&msp.IdemixNewOpts{msp.NewBaseOpts{Version: bh.version}})
if err != nil {
return nil, errors.WithMessage(err, "creating the MSP manager failed")
}
default:
return nil, errors.New(fmt.Sprintf("Setup error: unsupported msp type %d", mspConfig.Type))
}

// set it up
err = casheMSP.Setup(mspConfig)
err = theMsp.Setup(mspConfig)
if err != nil {
return nil, fmt.Errorf("Setting up the MSP manager failed, err %s", err)
return nil, errors.WithMessage(err, "setting up the MSP manager failed")
}

// add the MSP to the map of pending MSPs
mspID, _ := casheMSP.GetIdentifier()
mspID, _ := theMsp.GetIdentifier()

existingPendingMSPConfig, ok := bh.idMap[mspID]
if ok && !proto.Equal(existingPendingMSPConfig.mspConfig, mspConfig) {
return nil, fmt.Errorf("Attempted to define two different versions of MSP: %s", mspID)
return nil, errors.New(fmt.Sprintf("Attempted to define two different versions of MSP: %s", mspID))
}

if !ok {
bh.idMap[mspID] = &pendingMSPConfig{
mspConfig: mspConfig,
msp: casheMSP,
msp: theMsp,
}
}

return casheMSP, nil
return theMsp, nil
}

func (bh *MSPConfigHandler) CreateMSPManager() (msp.MSPManager, error) {
Expand Down

0 comments on commit 21539ef

Please sign in to comment.