mirror of
https://github.com/nadoo/glider.git
synced 2026-11-23 23:49:41 +08:00
general: suport results feedback in more protocols
This commit is contained in:
1 parent
c5881a6db3
commit
b99a730968
9 files changed
+33
-24
No files matched your search
@@ -115,6 +115,7 @@ func (f *Forwarder) Failures() uint32 {
|
||||
func (f *Forwarder) IncFailures() {
|
||||
failures := atomic.AddUint32(&f.failures, 1)
|
||||
log.F("[forwarder] %s recorded %d failures", f.addr, failures)
|
||||
|
||||
if failures >= f.MaxFailures() && f.Enabled() {
|
||||
log.F("[forwarder] %s reaches maxfailures.", f.addr)
|
||||
f.Disable()
|
||||
|
||||
+11
-7
@@ -65,7 +65,7 @@ func NewProxy(s []string, c *Config) *Proxy {
|
||||
return newProxy(fwdrs, c)
|
||||
}
|
||||
|
||||
// newProxy returns a new rrProxy
|
||||
// newProxy returns a new Proxy.
|
||||
func newProxy(fwdrs []*Forwarder, c *Config) *Proxy {
|
||||
p := &Proxy{fwdrs: fwdrs, config: c}
|
||||
sort.Sort(p.fwdrs)
|
||||
@@ -127,12 +127,16 @@ func (p *Proxy) NextDialer(dstAddr string) proxy.Dialer {
|
||||
|
||||
// Record records result while using the dialer from proxy.
|
||||
func (p *Proxy) Record(dialer proxy.Dialer, success bool) {
|
||||
if success {
|
||||
return
|
||||
}
|
||||
forwarder, ok := dialer.(*Forwarder)
|
||||
if ok {
|
||||
forwarder.IncFailures()
|
||||
OnRecord(dialer, success)
|
||||
}
|
||||
|
||||
func OnRecord(dialer proxy.Dialer, success bool) {
|
||||
if fwdr, ok := dialer.(*Forwarder); ok {
|
||||
if success {
|
||||
fwdr.Enable()
|
||||
} else {
|
||||
fwdr.IncFailures()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user