github.com/kaituanwang/hyperledger@v2.0.1+incompatible/gossip/privdata/config.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package privdata
     8  
     9  import (
    10  	"time"
    11  
    12  	"github.com/spf13/viper"
    13  )
    14  
    15  const (
    16  	reconcileSleepIntervalDefault = time.Minute
    17  	reconcileBatchSizeDefault     = 10
    18  )
    19  
    20  // PrivdataConfig is the struct that defines the Gossip Privdata configurations.
    21  type PrivdataConfig struct {
    22  	// ReconcileSleepInterval determines the time reconciler sleeps from end of an interation until the beginning of the next
    23  	// reconciliation iteration.
    24  	ReconcileSleepInterval time.Duration
    25  	// ReconcileBatchSize determines the maximum batch size of missing private data that will be reconciled in a single iteration.
    26  	ReconcileBatchSize int
    27  	// ReconciliationEnabled is a flag that indicates whether private data reconciliation is enabled or not.
    28  	ReconciliationEnabled bool
    29  }
    30  
    31  // GlobalConfig obtains a set of configuration from viper, build and returns the config struct.
    32  func GlobalConfig() *PrivdataConfig {
    33  	c := &PrivdataConfig{}
    34  	c.loadPrivDataConfig()
    35  	return c
    36  }
    37  
    38  func (c *PrivdataConfig) loadPrivDataConfig() {
    39  	c.ReconcileSleepInterval = viper.GetDuration("peer.gossip.pvtData.reconcileSleepInterval")
    40  	if c.ReconcileSleepInterval == 0 {
    41  		logger.Warning("Configuration key peer.gossip.pvtData.reconcileSleepInterval isn't set, defaulting to", reconcileSleepIntervalDefault)
    42  		c.ReconcileSleepInterval = reconcileSleepIntervalDefault
    43  	}
    44  
    45  	c.ReconcileBatchSize = viper.GetInt("peer.gossip.pvtData.reconcileBatchSize")
    46  	if c.ReconcileBatchSize == 0 {
    47  		logger.Warning("Configuration key peer.gossip.pvtData.reconcileBatchSize isn't set, defaulting to", reconcileBatchSizeDefault)
    48  		c.ReconcileBatchSize = reconcileBatchSizeDefault
    49  	}
    50  
    51  	c.ReconciliationEnabled = viper.GetBool("peer.gossip.pvtData.reconciliationEnabled")
    52  
    53  }