1 Star 0 Fork 0

妥協/fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
plugin_activation.go 2.69 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package pluggable
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/spf13/viper"
)
const (
EndorsementPluginEnvVar = "ENDORSEMENT_PLUGIN_ENV_VAR"
ValidationPluginEnvVar = "VALIDATION_PLUGIN_ENV_VAR"
)
// EndorsementPluginActivationFolder returns the name of the folder that if
// the file of the peer's id in it exists - it indicates that the endorsement plugin was activated
// for that peer
func EndorsementPluginActivationFolder() string {
return os.Getenv(EndorsementPluginEnvVar)
}
// SetEndorsementPluginActivationFolder sets the name of the folder
// that if the file of the peer's id in it exists - it indicates that the endorsement plugin was activated
// for that peer
func SetEndorsementPluginActivationFolder(path string) {
os.Setenv(EndorsementPluginEnvVar, path)
}
// ValidationPluginActivationFilePath returns the name of the folder that if
// the file of the peer's id in it exists - it indicates that the validation plugin was activated
// for that peer
func ValidationPluginActivationFolder() string {
return os.Getenv(ValidationPluginEnvVar)
}
// SetValidationPluginActivationFolder sets the name of the folder
// that if the file of the peer's id in it exists - it indicates that the validation plugin was activated
// for that peer
func SetValidationPluginActivationFolder(path string) {
os.Setenv(ValidationPluginEnvVar, path)
}
func markPluginActivation(dir string) {
fileName := filepath.Join(dir, viper.GetString("peer.id"))
_, err := os.Create(fileName)
if err != nil {
panic(fmt.Sprintf("failed to create file %s: %v", fileName, err))
}
}
// PublishEndorsementPluginActivation makes it known that the endorsement plugin
// was activated for the peer that is invoking this function
func PublishEndorsementPluginActivation() {
markPluginActivation(EndorsementPluginActivationFolder())
}
// PublishValidationPluginActivation makes it known that the validation plugin
// was activated for the peer that is invoking this function
func PublishValidationPluginActivation() {
markPluginActivation(ValidationPluginActivationFolder())
}
// CountEndorsementPluginActivations returns the number of peers that activated
// the endorsement plugin
func CountEndorsementPluginActivations() int {
return listDir(EndorsementPluginActivationFolder())
}
// CountValidationPluginActivations returns the number of peers that activated
// the validation plugin
func CountValidationPluginActivations() int {
return listDir(ValidationPluginActivationFolder())
}
func listDir(d string) int {
dir, err := ioutil.ReadDir(d)
if err != nil {
panic(fmt.Sprintf("failed listing directory %s: %v", d, err))
}
return len(dir)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liurenhao/fabric.git
git@gitee.com:liurenhao/fabric.git
liurenhao
fabric
fabric
v1.4.9

搜索帮助

0d507c66 1850385 C8b1a773 1850385