redir, dns: IncFailures on non-timeout errors (#133)

This commit is contained in:
wuudjac authored and GitHub committed 2020-04-28 15:18:19 +08:00
1 parent c2d9c67214
commit 22e0576b53
6 files changed
+40 -12

No files matched your search

+4 -1
View File
@@ -5,11 +5,14 @@ import "net"
// Proxy is a dialer manager
type Proxy interface {
// Dial connects to the given address via the proxy.
Dial(network, addr string) (c net.Conn, proxy string, err error)
Dial(network, addr string) (c net.Conn, dialer Dialer, err error)
// DialUDP connects to the given address via the proxy.
DialUDP(network, addr string) (pc net.PacketConn, writeTo net.Addr, err error)
// Get the dialer by dstAddr
NextDialer(dstAddr string) Dialer
// Record records result while using the dialer from proxy.
Record(dialer Dialer, success bool)
}
+4 -3
View File
@@ -104,14 +104,14 @@ func (s *RedirProxy) Serve(c net.Conn) {
return
}
rc, p, err := s.proxy.Dial("tcp", tgt.String())
rc, dialer, err := s.proxy.Dial("tcp", tgt.String())
if err != nil {
log.F("[redir] %s <-> %s via %s, error in dial: %v", c.RemoteAddr(), tgt, p, err)
log.F("[redir] %s <-> %s via %s, error in dial: %v", c.RemoteAddr(), tgt, dialer.Addr(), err)
return
}
defer rc.Close()
log.F("[redir] %s <-> %s via %s", c.RemoteAddr(), tgt, p)
log.F("[redir] %s <-> %s via %s", c.RemoteAddr(), tgt, dialer.Addr())
_, _, err = conn.Relay(c, rc)
if err != nil {
@@ -119,6 +119,7 @@ func (s *RedirProxy) Serve(c net.Conn) {
return // ignore i/o timeout
}
log.F("[redir] relay error: %v", err)
s.proxy.Record(dialer, false)
}
}