[#1713] morph: Allow switch interval configuration
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
d09ec2e3fe
commit
d240e2dc87
2 changed files with 16 additions and 5 deletions
|
@ -44,11 +44,14 @@ type cfg struct {
|
|||
singleCli *rpcclient.WSClient // neo-go client for single client mode
|
||||
|
||||
inactiveModeCb Callback
|
||||
|
||||
switchInterval time.Duration
|
||||
}
|
||||
|
||||
const (
|
||||
defaultDialTimeout = 5 * time.Second
|
||||
defaultWaitInterval = 500 * time.Millisecond
|
||||
defaultDialTimeout = 5 * time.Second
|
||||
defaultWaitInterval = 500 * time.Millisecond
|
||||
defaultSwitchInterval = 2 * time.Minute
|
||||
)
|
||||
|
||||
func defaultConfig() *cfg {
|
||||
|
@ -60,6 +63,7 @@ func defaultConfig() *cfg {
|
|||
signer: &transaction.Signer{
|
||||
Scopes: transaction.Global,
|
||||
},
|
||||
switchInterval: defaultSwitchInterval,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -289,3 +293,12 @@ func WithConnLostCallback(cb Callback) Option {
|
|||
c.inactiveModeCb = cb
|
||||
}
|
||||
}
|
||||
|
||||
// WithSwitchInterval returns a client constructor option
|
||||
// that specifies a wait interval b/w attempts to reconnect
|
||||
// to an RPC node with the highest priority.
|
||||
func WithSwitchInterval(i time.Duration) Option {
|
||||
return func(c *cfg) {
|
||||
c.switchInterval = i
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,9 +133,7 @@ func (c *Client) notificationLoop() {
|
|||
}
|
||||
|
||||
func (c *Client) switchToMostPrioritized() {
|
||||
const period = 2 * time.Minute
|
||||
|
||||
t := time.NewTicker(period)
|
||||
t := time.NewTicker(c.cfg.switchInterval)
|
||||
defer t.Stop()
|
||||
defer c.switchIsActive.Store(false)
|
||||
|
||||
|
|
Loading…
Reference in a new issue