github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/orderer/common/follower/options.go (about)

     1  /*
     2  Copyright hechain. 2017 All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package follower
     8  
     9  import (
    10  	"math"
    11  	"time"
    12  
    13  	"github.com/hechain20/hechain/common/flogging"
    14  )
    15  
    16  const (
    17  	// The default minimal retry interval when pulling blocks
    18  	defaultPullRetryMinInterval time.Duration = 50 * time.Millisecond
    19  	// The default maximal retry interval when pulling blocks
    20  	defaultPullRetryMaxInterval time.Duration = 60 * time.Second
    21  
    22  	// The default minimal height polling interval when pulling blocks after the join block
    23  	defaultHeightPollMinInterval time.Duration = 500 * time.Millisecond
    24  	// The default maximal height polling interval when pulling blocks after the join block
    25  	defaultHeightPollMaxInterval time.Duration = 10 * time.Second
    26  )
    27  
    28  // Options contains some configuration options relevant to the follower.Chain.
    29  type Options struct {
    30  	Logger                *flogging.FabricLogger
    31  	PullRetryMinInterval  time.Duration
    32  	PullRetryMaxInterval  time.Duration
    33  	HeightPollMinInterval time.Duration
    34  	HeightPollMaxInterval time.Duration
    35  	Cert                  []byte
    36  	TimeAfter             TimeAfter // If nil, time.After is selected
    37  }
    38  
    39  func (o *Options) applyDefaults() {
    40  	if o.Logger == nil {
    41  		o.Logger = flogging.MustGetLogger("orderer.common.follower")
    42  	}
    43  
    44  	if o.PullRetryMinInterval <= 0 {
    45  		o.PullRetryMinInterval = defaultPullRetryMinInterval
    46  	}
    47  	if o.PullRetryMaxInterval <= 0 {
    48  		o.PullRetryMaxInterval = defaultPullRetryMaxInterval
    49  	}
    50  	if o.PullRetryMaxInterval > math.MaxInt64/2 {
    51  		o.PullRetryMaxInterval = math.MaxInt64 / 2
    52  	}
    53  	if o.PullRetryMinInterval > o.PullRetryMaxInterval {
    54  		o.PullRetryMaxInterval = o.PullRetryMinInterval
    55  	}
    56  
    57  	if o.HeightPollMinInterval <= 0 {
    58  		o.HeightPollMinInterval = defaultHeightPollMinInterval
    59  	}
    60  	if o.HeightPollMaxInterval <= 0 {
    61  		o.HeightPollMaxInterval = defaultHeightPollMaxInterval
    62  	}
    63  	if o.HeightPollMaxInterval > math.MaxInt64/2 {
    64  		o.HeightPollMaxInterval = math.MaxInt64 / 2
    65  	}
    66  	if o.HeightPollMinInterval > o.HeightPollMaxInterval {
    67  		o.HeightPollMaxInterval = o.HeightPollMinInterval
    68  	}
    69  
    70  	if o.TimeAfter == nil {
    71  		o.TimeAfter = time.After
    72  	}
    73  }