本文整理匯總了Golang中github.com/hyperledger/fabric/core/crypto.InitValidator函數的典型用法代碼示例。如果您正苦於以下問題:Golang InitValidator函數的具體用法?Golang InitValidator怎麽用?Golang InitValidator使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了InitValidator函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getSecHelper
//this should be called exactly once and the result cached
//NOTE- this crypto func might rightly belong in a crypto package
//and universally accessed
func getSecHelper() (crypto.Peer, error) {
var secHelper crypto.Peer
var err error
once.Do(func() {
if core.SecurityEnabled() {
enrollID := viper.GetString("security.enrollID")
enrollSecret := viper.GetString("security.enrollSecret")
if peer.ValidatorEnabled() {
logger.Debugf("Registering validator with enroll ID: %s", enrollID)
if err = crypto.RegisterValidator(enrollID, nil, enrollID, enrollSecret); nil != err {
return
}
logger.Debugf("Initializing validator with enroll ID: %s", enrollID)
secHelper, err = crypto.InitValidator(enrollID, nil)
if nil != err {
return
}
} else {
logger.Debugf("Registering non-validator with enroll ID: %s", enrollID)
if err = crypto.RegisterPeer(enrollID, nil, enrollID, enrollSecret); nil != err {
return
}
logger.Debugf("Initializing non-validator with enroll ID: %s", enrollID)
secHelper, err = crypto.InitPeer(enrollID, nil)
if nil != err {
return
}
}
}
})
return secHelper, err
}
示例2: getSecHelper
func getSecHelper() (crypto.Peer, error) {
var secHelper crypto.Peer
var err error
if viper.GetBool("security.enabled") {
enrollID := viper.GetString("security.enrollID")
enrollSecret := viper.GetString("security.enrollSecret")
if viper.GetBool("peer.validator.enabled") {
if err = crypto.RegisterValidator(enrollID, nil, enrollID, enrollSecret); nil != err {
return nil, err
}
secHelper, err = crypto.InitValidator(enrollID, nil)
if nil != err {
return nil, err
}
} else {
if err = crypto.RegisterPeer(enrollID, nil, enrollID, enrollSecret); nil != err {
return nil, err
}
secHelper, err = crypto.InitPeer(enrollID, nil)
if nil != err {
return nil, err
}
}
}
return secHelper, err
}
示例3: initPeer
//initialize peer and start up. If security==enabled, login as vp
func initPeer() (net.Listener, error) {
//start clean
finitPeer(nil)
var opts []grpc.ServerOption
if viper.GetBool("peer.tls.enabled") {
creds, err := credentials.NewServerTLSFromFile(viper.GetString("peer.tls.cert.file"), viper.GetString("peer.tls.key.file"))
if err != nil {
return nil, fmt.Errorf("Failed to generate credentials %v", err)
}
opts = []grpc.ServerOption{grpc.Creds(creds)}
}
grpcServer := grpc.NewServer(opts...)
peerAddress := viper.GetString("peer.address")
lis, err := net.Listen("tcp", peerAddress)
if err != nil {
return nil, fmt.Errorf("Error starting peer listener %s", err)
}
getPeerEndpoint := func() (*pb.PeerEndpoint, error) {
return &pb.PeerEndpoint{ID: &pb.PeerID{Name: "testpeer"}, Address: peerAddress}, nil
}
// Install security object for peer
var secHelper crypto.Peer
if viper.GetBool("security.enabled") {
enrollID := viper.GetString("security.enrollID")
enrollSecret := viper.GetString("security.enrollSecret")
if err = crypto.RegisterValidator(enrollID, nil, enrollID, enrollSecret); nil != err {
return nil, err
}
secHelper, err = crypto.InitValidator(enrollID, nil)
if nil != err {
return nil, err
}
}
ccStartupTimeout := time.Duration(chaincodeStartupTimeoutDefault) * time.Millisecond
pb.RegisterChaincodeSupportServer(grpcServer, NewChaincodeSupport(DefaultChain, getPeerEndpoint, false, ccStartupTimeout, secHelper))
go grpcServer.Serve(lis)
return lis, nil
}
示例4: initVP
func initVP() {
var opts []grpc.ServerOption
if viper.GetBool("peer.tls.enabled") {
creds, err := credentials.NewServerTLSFromFile(viper.GetString("peer.tls.cert.file"), viper.GetString("peer.tls.key.file"))
if err != nil {
grpclog.Fatalf("Failed to generate credentials %v", err)
}
opts = []grpc.ServerOption{grpc.Creds(creds)}
}
grpcServer := grpc.NewServer(opts...)
//lis, err := net.Listen("tcp", viper.GetString("peer.address"))
//use a different address than what we usually use for "peer"
//we override the peerAddress set in chaincode_support.go
peerAddress := "0.0.0.0:40404"
var err error
lis, err = net.Listen("tcp", peerAddress)
if err != nil {
return
}
getPeerEndpoint := func() (*pb.PeerEndpoint, error) {
return &pb.PeerEndpoint{ID: &pb.PeerID{Name: "testpeer"}, Address: peerAddress}, nil
}
ccStartupTimeout := time.Duration(chaincodeStartupTimeoutDefault) * time.Millisecond
userRunsCC := true
// Install security object for peer
var secHelper crypto.Peer
if viper.GetBool("security.enabled") {
enrollID := viper.GetString("security.enrollID")
enrollSecret := viper.GetString("security.enrollSecret")
var err error
if viper.GetBool("peer.validator.enabled") {
testLogger.Debug("Registering validator with enroll ID: %s", enrollID)
if err = crypto.RegisterValidator(enrollID, nil, enrollID, enrollSecret); nil != err {
panic(err)
}
testLogger.Debug("Initializing validator with enroll ID: %s", enrollID)
secHelper, err = crypto.InitValidator(enrollID, nil)
if nil != err {
panic(err)
}
} else {
testLogger.Debug("Registering non-validator with enroll ID: %s", enrollID)
if err = crypto.RegisterPeer(enrollID, nil, enrollID, enrollSecret); nil != err {
panic(err)
}
testLogger.Debug("Initializing non-validator with enroll ID: %s", enrollID)
secHelper, err = crypto.InitPeer(enrollID, nil)
if nil != err {
panic(err)
}
}
}
pb.RegisterChaincodeSupportServer(grpcServer,
chaincode.NewChaincodeSupport(chaincode.DefaultChain, getPeerEndpoint, userRunsCC,
ccStartupTimeout, secHelper))
grpcServer.Serve(lis)
}