github.com/Hnampk/fabric@v2.1.1+incompatible/gossip/state/config.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package state 8 9 import ( 10 "time" 11 12 "github.com/spf13/viper" 13 ) 14 15 const ( 16 DefStateCheckInterval = 10 * time.Second 17 DefStateResponseTimeout = 3 * time.Second 18 DefStateBatchSize = 10 19 DefStateMaxRetries = 3 20 DefStateBlockBufferSize = 100 21 DefStateChannelSize = 100 22 DefStateEnabled = true 23 ) 24 25 type StateConfig struct { 26 StateCheckInterval time.Duration 27 StateResponseTimeout time.Duration 28 StateBatchSize uint64 29 StateMaxRetries int 30 StateBlockBufferSize int 31 StateChannelSize int 32 StateEnabled bool 33 } 34 35 func GlobalConfig() *StateConfig { 36 c := &StateConfig{} 37 c.loadStateConfig() 38 return c 39 } 40 41 func (c *StateConfig) loadStateConfig() { 42 43 c.StateCheckInterval = DefStateCheckInterval 44 if viper.IsSet("peer.gossip.state.checkInterval") { 45 c.StateCheckInterval = viper.GetDuration("peer.gossip.state.checkInterval") 46 } 47 c.StateResponseTimeout = DefStateResponseTimeout 48 if viper.IsSet("peer.gossip.state.responseTimeout") { 49 c.StateResponseTimeout = viper.GetDuration("peer.gossip.state.responseTimeout") 50 } 51 c.StateBatchSize = DefStateBatchSize 52 if viper.IsSet("peer.gossip.state.batchSize") { 53 c.StateBatchSize = uint64(viper.GetInt("peer.gossip.state.batchSize")) 54 } 55 c.StateMaxRetries = DefStateMaxRetries 56 if viper.IsSet("peer.gossip.state.maxRetries") { 57 c.StateMaxRetries = viper.GetInt("peer.gossip.state.maxRetries") 58 } 59 c.StateBlockBufferSize = DefStateBlockBufferSize 60 if viper.IsSet("peer.gossip.state.blockBufferSize") { 61 c.StateBlockBufferSize = viper.GetInt("peer.gossip.state.blockBufferSize") 62 } 63 c.StateChannelSize = DefStateChannelSize 64 if viper.IsSet("peer.gossip.state.channelSize") { 65 c.StateChannelSize = viper.GetInt("peer.gossip.state.channelSize") 66 } 67 c.StateEnabled = DefStateEnabled 68 if viper.IsSet("peer.gossip.state.enabled") { 69 c.StateEnabled = viper.GetBool("peer.gossip.state.enabled") 70 } 71 }