1 Star 0 Fork 0

BUPT-ZKJC / fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
config.go 3.64 KB
一键复制 编辑 原始数据 按行查看 历史
MJL 提交于 2021-08-06 18:37 . first commit
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package privdata
import (
"fmt"
"time"
"github.com/spf13/viper"
)
const (
reconcileSleepIntervalDefault = time.Minute
reconcileBatchSizeDefault = 10
implicitCollectionMaxPeerCountDefault = 1
)
// PrivdataConfig is the struct that defines the Gossip Privdata configurations.
type PrivdataConfig struct {
// ReconcileSleepInterval determines the time reconciler sleeps from end of an interation until the beginning of the next
// reconciliation iteration.
ReconcileSleepInterval time.Duration
// ReconcileBatchSize determines the maximum batch size of missing private data that will be reconciled in a single iteration.
ReconcileBatchSize int
// ReconciliationEnabled is a flag that indicates whether private data reconciliation is enabled or not.
ReconciliationEnabled bool
// ImplicitCollectionDisseminationPolicy specifies the dissemination policy for the peer's own implicit collection.
ImplicitCollDisseminationPolicy ImplicitCollectionDisseminationPolicy
}
// ImplicitCollectionDisseminationPolicy specifies the dissemination policy for the peer's own implicit collection.
// It is not applicable to private data for other organizations' implicit collections.
type ImplicitCollectionDisseminationPolicy struct {
// RequiredPeerCount defines the minimum number of eligible peers to which each endorsing peer must successfully
// disseminate private data for its own implicit collection. Default is 0.
RequiredPeerCount int
// MaxPeerCount defines the maximum number of eligible peers to which each endorsing peer will attempt to
// disseminate private data for its own implicit collection. Default is 1.
MaxPeerCount int
}
// GlobalConfig obtains a set of configuration from viper, build and returns the config struct.
func GlobalConfig() *PrivdataConfig {
c := &PrivdataConfig{}
c.loadPrivDataConfig()
return c
}
func (c *PrivdataConfig) loadPrivDataConfig() {
c.ReconcileSleepInterval = viper.GetDuration("peer.gossip.pvtData.reconcileSleepInterval")
if c.ReconcileSleepInterval == 0 {
logger.Warning("Configuration key peer.gossip.pvtData.reconcileSleepInterval isn't set, defaulting to", reconcileSleepIntervalDefault)
c.ReconcileSleepInterval = reconcileSleepIntervalDefault
}
c.ReconcileBatchSize = viper.GetInt("peer.gossip.pvtData.reconcileBatchSize")
if c.ReconcileBatchSize == 0 {
logger.Warning("Configuration key peer.gossip.pvtData.reconcileBatchSize isn't set, defaulting to", reconcileBatchSizeDefault)
c.ReconcileBatchSize = reconcileBatchSizeDefault
}
c.ReconciliationEnabled = viper.GetBool("peer.gossip.pvtData.reconciliationEnabled")
requiredPeerCount := viper.GetInt("peer.gossip.pvtData.implicitCollectionDisseminationPolicy.requiredPeerCount")
maxPeerCount := implicitCollectionMaxPeerCountDefault
if viper.Get("peer.gossip.pvtData.implicitCollectionDisseminationPolicy.maxPeerCount") != nil {
// allow override maxPeerCount to 0 that will effectively disable dissemination on the peer
maxPeerCount = viper.GetInt("peer.gossip.pvtData.implicitCollectionDisseminationPolicy.maxPeerCount")
}
if requiredPeerCount < 0 {
panic(fmt.Sprintf("peer.gossip.pvtData.implicitCollectionDisseminationPolicy.requiredPeerCount (%d) cannot be less than zero",
requiredPeerCount))
}
if maxPeerCount < requiredPeerCount {
panic(fmt.Sprintf("peer.gossip.pvtData.implicitCollectionDisseminationPolicy.maxPeerCount (%d) cannot be less than requiredPeerCount (%d)",
maxPeerCount, requiredPeerCount))
}
c.ImplicitCollDisseminationPolicy.RequiredPeerCount = requiredPeerCount
c.ImplicitCollDisseminationPolicy.MaxPeerCount = maxPeerCount
}
1
https://gitee.com/bupt-zkjc/fabric.git
git@gitee.com:bupt-zkjc/fabric.git
bupt-zkjc
fabric
fabric
98d302355562

搜索帮助