forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.go
53 lines (42 loc) · 1.75 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package privdata
import (
"time"
"github.com/spf13/viper"
)
const (
reconcileSleepIntervalDefault = time.Minute
reconcileBatchSizeDefault = 10
)
// 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
}
// 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")
}