diff --git a/gossip/gossip/algo/pull.go b/gossip/gossip/algo/pull.go index 1d372f21a70..6ccca81ae49 100644 --- a/gossip/gossip/algo/pull.go +++ b/gossip/gossip/algo/pull.go @@ -23,6 +23,7 @@ import ( "time" "github.com/hyperledger/fabric/gossip/util" + "github.com/spf13/viper" ) /* PullEngine is an object that performs pull-based gossip, and maintains an internal state of items @@ -47,23 +48,25 @@ func init() { rand.Seed(42) } -var digestWaitTime = time.Duration(1) * time.Second -var requestWaitTime = time.Duration(1) * time.Second -var responseWaitTime = time.Duration(2) * time.Second +const ( + defDigestWaitTime = time.Duration(1) * time.Second + defRequestWaitTime = time.Duration(1) * time.Second + defResponseWaitTime = time.Duration(2) * time.Second +) // SetDigestWaitTime sets the digest wait time func SetDigestWaitTime(time time.Duration) { - digestWaitTime = time + viper.Set("peer.gossip.digestWaitTime", time) } // SetRequestWaitTime sets the request wait time func SetRequestWaitTime(time time.Duration) { - requestWaitTime = time + viper.Set("peer.gossip.requestWaitTime", time) } // SetResponseWaitTime sets the response wait time func SetResponseWaitTime(time time.Duration) { - responseWaitTime = time + viper.Set("peer.gossip.responseWaitTime", time) } // PullAdapter is needed by the PullEngine in order to @@ -179,6 +182,7 @@ func (engine *PullEngine) initiatePull() { engine.Hello(peer, nonce) } + digestWaitTime := util.GetDurationOrDefault("peer.gossip.digestWaitTime", defDigestWaitTime) time.AfterFunc(digestWaitTime, func() { engine.processIncomingDigests() }) @@ -207,6 +211,7 @@ func (engine *PullEngine) processIncomingDigests() { engine.SendReq(dest, seqsToReq, engine.peers2nonces[dest]) } + responseWaitTime := util.GetDurationOrDefault("peer.gossip.responseWaitTime", defResponseWaitTime) time.AfterFunc(responseWaitTime, engine.endPull) } @@ -262,6 +267,8 @@ func (engine *PullEngine) Remove(seqs ...string) { // OnHello notifies the engine a hello has arrived func (engine *PullEngine) OnHello(nonce uint64, context interface{}) { engine.incomingNONCES.Add(nonce) + + requestWaitTime := util.GetDurationOrDefault("peer.gossip.requestWaitTime", defRequestWaitTime) time.AfterFunc(requestWaitTime, func() { engine.incomingNONCES.Remove(nonce) }) diff --git a/gossip/gossip/algo/pull_test.go b/gossip/gossip/algo/pull_test.go index ed8499d0995..9c1b59979e4 100644 --- a/gossip/gossip/algo/pull_test.go +++ b/gossip/gossip/algo/pull_test.go @@ -29,9 +29,9 @@ import ( ) func init() { - requestWaitTime = time.Duration(200) * time.Millisecond - digestWaitTime = time.Duration(100) * time.Millisecond - responseWaitTime = time.Duration(200) * time.Millisecond + SetDigestWaitTime(time.Duration(100) * time.Millisecond) + SetRequestWaitTime(time.Duration(200) * time.Millisecond) + SetResponseWaitTime(time.Duration(200) * time.Millisecond) } type messageHook func(interface{}) diff --git a/peer/core.yaml b/peer/core.yaml index fabea5a05bb..dc451d6d28e 100644 --- a/peer/core.yaml +++ b/peer/core.yaml @@ -108,6 +108,12 @@ peer: recvBuffSize: 20 # Buffer size of sending messages sendBuffSize: 20 + # Time to wait before pull engine processes incoming digests (unit: second) + digestWaitTime: 1s + # Time to wait before pull engine removes incoming nonce (unit: second) + requestWaitTime: 1s + # Time to wait before pull engine ends pull (unit: second) + responseWaitTime: 2s # This is an endpoint that is published to peers outside of the organization. # If this isn't set, the peer will not be known to other organizations.