github.com/yimialmonte/fabric@v2.1.1+incompatible/gossip/gossip/config.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package gossip 8 9 import ( 10 "net" 11 "strconv" 12 "time" 13 14 "github.com/hyperledger/fabric/gossip/comm" 15 "github.com/hyperledger/fabric/gossip/common" 16 "github.com/hyperledger/fabric/gossip/discovery" 17 "github.com/hyperledger/fabric/gossip/election" 18 "github.com/hyperledger/fabric/gossip/gossip/algo" 19 "github.com/hyperledger/fabric/gossip/util" 20 "github.com/spf13/viper" 21 ) 22 23 // Config is the configuration of the gossip component 24 type Config struct { 25 // BindPort is the port that gossip bind to, used only for tests. 26 BindPort int 27 // Id of the specific gossip instance. 28 ID string 29 // BootstrapPeers are peers we connect to at startup. 30 BootstrapPeers []string 31 // PropagateIterations is the number of times a message is pushed to remote peers. 32 PropagateIterations int 33 // PropagatePeerNum is the number of peers selected to push messages to. 34 PropagatePeerNum int 35 36 // MaxBlockCountToStore is the maximum count of blocks we store in memory. 37 MaxBlockCountToStore int 38 39 // MaxPropagationBurstSize is the max number of messages stored until it triggers a push to remote peers. 40 MaxPropagationBurstSize int 41 // MaxPropagationBurstLatency is the max time between consecutive message pushes. 42 MaxPropagationBurstLatency time.Duration 43 44 // PullInterval determines frequency of pull phases. 45 PullInterval time.Duration 46 // PullPeerNum is the number of peers to pull from. 47 PullPeerNum int 48 49 // SkipBlockVerification controls either we skip verifying block message or not. 50 SkipBlockVerification bool 51 52 // PublishCertPeriod is the time from startup certificates are included in Alive message. 53 PublishCertPeriod time.Duration 54 // PublishStateInfoInterval determines frequency of pushing state info messages to peers. 55 PublishStateInfoInterval time.Duration 56 // RequestStateInfoInterval determines frequency of pulling state info messages from peers. 57 RequestStateInfoInterval time.Duration 58 59 // TLSCerts is the TLS certificates of the peer. 60 TLSCerts *common.TLSCertificates 61 62 // InternalEndpoint is the endpoint we publish to peers in our organization. 63 InternalEndpoint string 64 // ExternalEndpoint is the peer publishes this endpoint instead of selfEndpoint to foreign organizations. 65 ExternalEndpoint string 66 // TimeForMembershipTracker determines time for polloing with membershipTracker. 67 TimeForMembershipTracker time.Duration 68 69 // DigestWaitTime is the time to wait before pull engine processes incoming digests. 70 DigestWaitTime time.Duration 71 // RequestWaitTime is the time to wait before pull engine removes incoming nonce. 72 RequestWaitTime time.Duration 73 // ResponseWaitTime is the time to wait before pull engine ends pull. 74 ResponseWaitTime time.Duration 75 76 // DialTimeout indicate Dial timeout. 77 DialTimeout time.Duration 78 // ConnTimeout indicate Connection timeout. 79 ConnTimeout time.Duration 80 // RecvBuffSize is the buffer size of received message. 81 RecvBuffSize int 82 // SendBuffSize is the buffer size of sending message. 83 SendBuffSize int 84 85 // MsgExpirationTimeout indicate leadership message expiration timeout. 86 MsgExpirationTimeout time.Duration 87 88 // AliveTimeInterval is the alive check interval. 89 AliveTimeInterval time.Duration 90 // AliveExpirationTimeout is the alive expiration timeout. 91 AliveExpirationTimeout time.Duration 92 // AliveExpirationCheckInterval is the alive expiration check interval. 93 AliveExpirationCheckInterval time.Duration 94 // ReconnectInterval is the Reconnect interval. 95 ReconnectInterval time.Duration 96 } 97 98 // GlobalConfig builds a Config from the given endpoint, certificate and bootstrap peers. 99 func GlobalConfig(endpoint string, certs *common.TLSCertificates, bootPeers ...string) (*Config, error) { 100 c := &Config{} 101 err := c.loadConfig(endpoint, certs, bootPeers...) 102 return c, err 103 } 104 105 func (c *Config) loadConfig(endpoint string, certs *common.TLSCertificates, bootPeers ...string) error { 106 _, p, err := net.SplitHostPort(endpoint) 107 if err != nil { 108 return err 109 } 110 port, err := strconv.ParseInt(p, 10, 64) 111 if err != nil { 112 return err 113 } 114 115 c.BindPort = int(port) 116 c.BootstrapPeers = bootPeers 117 c.ID = endpoint 118 c.MaxBlockCountToStore = util.GetIntOrDefault("peer.gossip.maxBlockCountToStore", 100) 119 c.MaxPropagationBurstLatency = util.GetDurationOrDefault("peer.gossip.maxPropagationBurstLatency", 10*time.Millisecond) 120 c.MaxPropagationBurstSize = util.GetIntOrDefault("peer.gossip.maxPropagationBurstSize", 10) 121 c.PropagateIterations = util.GetIntOrDefault("peer.gossip.propagateIterations", 1) 122 c.PropagatePeerNum = util.GetIntOrDefault("peer.gossip.propagatePeerNum", 3) 123 c.PullInterval = util.GetDurationOrDefault("peer.gossip.pullInterval", 4*time.Second) 124 c.PullPeerNum = util.GetIntOrDefault("peer.gossip.pullPeerNum", 3) 125 c.InternalEndpoint = endpoint 126 c.ExternalEndpoint = viper.GetString("peer.gossip.externalEndpoint") 127 c.PublishCertPeriod = util.GetDurationOrDefault("peer.gossip.publishCertPeriod", 10*time.Second) 128 c.RequestStateInfoInterval = util.GetDurationOrDefault("peer.gossip.requestStateInfoInterval", 4*time.Second) 129 c.PublishStateInfoInterval = util.GetDurationOrDefault("peer.gossip.publishStateInfoInterval", 4*time.Second) 130 c.SkipBlockVerification = viper.GetBool("peer.gossip.skipBlockVerification") 131 c.TLSCerts = certs 132 c.TimeForMembershipTracker = util.GetDurationOrDefault("peer.gossip.membershipTrackerInterval", 5*time.Second) 133 c.DigestWaitTime = util.GetDurationOrDefault("peer.gossip.digestWaitTime", algo.DefDigestWaitTime) 134 c.RequestWaitTime = util.GetDurationOrDefault("peer.gossip.requestWaitTime", algo.DefRequestWaitTime) 135 c.ResponseWaitTime = util.GetDurationOrDefault("peer.gossip.responseWaitTime", algo.DefResponseWaitTime) 136 c.DialTimeout = util.GetDurationOrDefault("peer.gossip.dialTimeout", comm.DefDialTimeout) 137 c.ConnTimeout = util.GetDurationOrDefault("peer.gossip.connTimeout", comm.DefConnTimeout) 138 c.RecvBuffSize = util.GetIntOrDefault("peer.gossip.recvBuffSize", comm.DefRecvBuffSize) 139 c.SendBuffSize = util.GetIntOrDefault("peer.gossip.sendBuffSize", comm.DefSendBuffSize) 140 c.MsgExpirationTimeout = util.GetDurationOrDefault("peer.gossip.election.leaderAliveThreshold", election.DefLeaderAliveThreshold) * 10 141 c.AliveTimeInterval = util.GetDurationOrDefault("peer.gossip.aliveTimeInterval", discovery.DefAliveTimeInterval) 142 c.AliveExpirationTimeout = util.GetDurationOrDefault("peer.gossip.aliveExpirationTimeout", 5*c.AliveTimeInterval) 143 c.AliveExpirationCheckInterval = c.AliveExpirationTimeout / 10 144 c.ReconnectInterval = util.GetDurationOrDefault("peer.gossip.reconnectInterval", c.AliveExpirationTimeout) 145 146 return nil 147 }