forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
71 lines (62 loc) · 1.91 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package state
import (
"time"
"github.com/spf13/viper"
)
const (
DefStateCheckInterval = 10 * time.Second
DefStateResponseTimeout = 3 * time.Second
DefStateBatchSize = 10
DefStateMaxRetries = 3
DefStateBlockBufferSize = 100
DefStateChannelSize = 100
DefStateEnabled = true
)
type StateConfig struct {
StateCheckInterval time.Duration
StateResponseTimeout time.Duration
StateBatchSize uint64
StateMaxRetries int
StateBlockBufferSize int
StateChannelSize int
StateEnabled bool
}
func GlobalConfig() *StateConfig {
c := &StateConfig{}
c.loadStateConfig()
return c
}
func (c *StateConfig) loadStateConfig() {
c.StateCheckInterval = DefStateCheckInterval
if viper.IsSet("peer.gossip.state.checkInterval") {
c.StateCheckInterval = viper.GetDuration("peer.gossip.state.checkInterval")
}
c.StateResponseTimeout = DefStateResponseTimeout
if viper.IsSet("peer.gossip.state.responseTimeout") {
c.StateResponseTimeout = viper.GetDuration("peer.gossip.state.responseTimeout")
}
c.StateBatchSize = DefStateBatchSize
if viper.IsSet("peer.gossip.state.batchSize") {
c.StateBatchSize = uint64(viper.GetInt("peer.gossip.state.batchSize"))
}
c.StateMaxRetries = DefStateMaxRetries
if viper.IsSet("peer.gossip.state.maxRetries") {
c.StateMaxRetries = viper.GetInt("peer.gossip.state.maxRetries")
}
c.StateBlockBufferSize = DefStateBlockBufferSize
if viper.IsSet("peer.gossip.state.blockBufferSize") {
c.StateBlockBufferSize = viper.GetInt("peer.gossip.state.blockBufferSize")
}
c.StateChannelSize = DefStateChannelSize
if viper.IsSet("peer.gossip.state.channelSize") {
c.StateChannelSize = viper.GetInt("peer.gossip.state.channelSize")
}
c.StateEnabled = DefStateEnabled
if viper.IsSet("peer.gossip.state.enabled") {
c.StateEnabled = viper.GetBool("peer.gossip.state.enabled")
}
}