mirror of
https://github.com/nadoo/glider.git
synced 2026-11-23 23:49:41 +08:00
redir, dns: IncFailures on non-timeout errors (#133)
This commit is contained in:
1 parent
c2d9c67214
commit
22e0576b53
6 files changed
+40
-12
No files matched your search
+6
-5
@@ -101,10 +101,6 @@ func (f *Forwarder) Dial(network, addr string) (c net.Conn, err error) {
|
||||
c, err = f.Dialer.Dial(network, addr)
|
||||
if err != nil {
|
||||
f.IncFailures()
|
||||
if f.Failures() >= f.MaxFailures() && f.Enabled() {
|
||||
f.Disable()
|
||||
log.F("[forwarder] %s reaches maxfailures.", f.addr)
|
||||
}
|
||||
}
|
||||
|
||||
return c, err
|
||||
@@ -117,7 +113,12 @@ func (f *Forwarder) Failures() uint32 {
|
||||
|
||||
// IncFailures increase the failuer count by 1
|
||||
func (f *Forwarder) IncFailures() {
|
||||
atomic.AddUint32(&f.failures, 1)
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
// AddHandler adds a custom handler to handle the status change event
|
||||
|
||||
+15
-2
@@ -15,6 +15,8 @@ import (
|
||||
"github.com/nadoo/glider/proxy"
|
||||
)
|
||||
|
||||
var _ proxy.Proxy = &Proxy{}
|
||||
|
||||
// Config is strategy config struct.
|
||||
type Config struct {
|
||||
Strategy string
|
||||
@@ -102,10 +104,10 @@ func newProxy(fwdrs []*Forwarder, c *Config) *Proxy {
|
||||
}
|
||||
|
||||
// Dial connects to the address addr on the network net.
|
||||
func (p *Proxy) Dial(network, addr string) (net.Conn, string, error) {
|
||||
func (p *Proxy) Dial(network, addr string) (net.Conn, proxy.Dialer, error) {
|
||||
nd := p.NextDialer(addr)
|
||||
c, err := nd.Dial(network, addr)
|
||||
return c, nd.Addr(), err
|
||||
return c, nd, err
|
||||
}
|
||||
|
||||
// DialUDP connects to the given address.
|
||||
@@ -125,6 +127,17 @@ func (p *Proxy) NextDialer(dstAddr string) proxy.Dialer {
|
||||
return p.next(dstAddr)
|
||||
}
|
||||
|
||||
// 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()
|
||||
}
|
||||
}
|
||||
|
||||
// Priority returns the active priority of dialer.
|
||||
func (p *Proxy) Priority() uint32 { return atomic.LoadUint32(&p.priority) }
|
||||
|
||||
|
||||
Reference in new issue
Block a user