From f4eab4d1b210768549e4419c754b6dbf567328b6 Mon Sep 17 00:00:00 2001 From: nadoo <287492+nadoo@users.noreply.github.com> Date: Mon, 13 Aug 2018 00:42:59 +0800 Subject: [PATCH] ipset: move to separate package --- ipset_linux.go => ipset/ipset_linux.go | 2 +- ipset_other.go => ipset/ipset_other.go | 2 +- main.go | 3 ++- proxy/forwarder.go | 11 +++++++---- 4 files changed, 11 insertions(+), 7 deletions(-) rename ipset_linux.go => ipset/ipset_linux.go (99%) rename ipset_other.go => ipset/ipset_other.go (97%) diff --git a/ipset_linux.go b/ipset/ipset_linux.go similarity index 99% rename from ipset_linux.go rename to ipset/ipset_linux.go index 4d5496f..5a75a9c 100644 --- a/ipset_linux.go +++ b/ipset/ipset_linux.go @@ -2,7 +2,7 @@ // @mdlayher https://github.com/mdlayher/netlink // Ref: https://github.com/vishvananda/netlink/blob/master/nl/nl_linux.go -package main +package ipset import ( "bytes" diff --git a/ipset_other.go b/ipset/ipset_other.go similarity index 97% rename from ipset_other.go rename to ipset/ipset_other.go index 6b58d6d..00ec7d8 100644 --- a/ipset_other.go +++ b/ipset/ipset_other.go @@ -1,6 +1,6 @@ // +build !linux -package main +package ipset import ( "errors" diff --git a/main.go b/main.go index 7742701..c42dfc2 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "github.com/nadoo/glider/common/log" "github.com/nadoo/glider/dns" + "github.com/nadoo/glider/ipset" "github.com/nadoo/glider/proxy" "github.com/nadoo/glider/rule" "github.com/nadoo/glider/strategy" @@ -37,7 +38,7 @@ func main() { } dialer := rule.NewDialer(conf.rules, strategy.NewDialer(conf.Forward, &conf.StrategyConfig)) - ipsetM, _ := NewIPSetManager(conf.IPSet, conf.rules) + ipsetM, _ := ipset.NewIPSetManager(conf.IPSet, conf.rules) // DNS Server if conf.DNS != "" { diff --git a/proxy/forwarder.go b/proxy/forwarder.go index 8a2e8bc..421acd9 100644 --- a/proxy/forwarder.go +++ b/proxy/forwarder.go @@ -6,6 +6,8 @@ import ( "strconv" "strings" "sync/atomic" + + "github.com/nadoo/glider/common/log" ) // Forwarder is a forwarder @@ -69,10 +71,11 @@ func (f *Forwarder) Dial(network, addr string) (c net.Conn, err error) { c, err = f.Dialer.Dial(network, addr) if err != nil { atomic.AddUint32(&f.failures, 1) - } - - if f.Failures() >= f.MaxFailures { - f.Disable() + log.F("[forwarder] %s, dials %s, error:%s", f.addr, addr, err) + if f.Failures() >= f.MaxFailures { + f.Disable() + log.F("[forwarder] %s reaches maxfailures, set to disabled", f.addr) + } } return c, err