2018-08-23 00:01:31 +08:00
|
|
|
package strategy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nadoo/glider/proxy"
|
|
|
|
)
|
|
|
|
|
2018-08-24 00:57:55 +08:00
|
|
|
// high availability dialer
|
2018-08-23 00:01:31 +08:00
|
|
|
type haDialer struct{ *rrDialer }
|
|
|
|
|
|
|
|
// newHADialer .
|
|
|
|
func newHADialer(dialers []*proxy.Forwarder, webhost string, duration int) proxy.Dialer {
|
|
|
|
return &haDialer{rrDialer: newRRDialer(dialers, webhost, duration)}
|
|
|
|
}
|
|
|
|
|
2018-08-24 01:15:56 +08:00
|
|
|
func (ha *haDialer) NextDialer(dstAddr string) proxy.Dialer {
|
2018-08-24 00:57:55 +08:00
|
|
|
d := ha.fwdrs[ha.Index()]
|
|
|
|
if !d.Enabled() || d.Priority() < ha.Priority() {
|
2018-08-23 00:01:31 +08:00
|
|
|
d = ha.nextDialer(dstAddr)
|
|
|
|
}
|
|
|
|
return d
|
|
|
|
}
|