Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
snail007 committed Jul 3, 2018
1 parent 05d2f16 commit d84a4be
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
proxy更新日志
v5.2
1.修复了HTTP(S)\SPS反向代理无法正常工作的问题.
2.优化了智能判断,减少不必要的DNS解析.

v5.1
1.优化了kcp默认mtu配置,调整为450.
Expand Down
2 changes: 1 addition & 1 deletion sdk/android-ios/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s *DNS) InitService() (err error) {
nil,
&net.Dialer{
Timeout: 5 * time.Second,
KeepAlive: 5 * time.Second,
KeepAlive: 2 * time.Second,
},
)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions services/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ func (s *HTTP) callback(inConn net.Conn) {
} else if *s.cfg.Always {
useProxy = true
} else {
k := s.Resolve(address)
s.checker.Add(address, k)
//var n, m uint
useProxy, _, _ = s.checker.IsBlocked(k)
var isInMap bool
useProxy, isInMap, _, _ = s.checker.IsBlocked(address)
if !isInMap {
s.checker.Add(address, s.Resolve(address))
}
//s.log.Printf("blocked ? : %v, %s , fail:%d ,success:%d", useProxy, address, n, m)
}
}
Expand Down
8 changes: 5 additions & 3 deletions services/socks/socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,11 @@ func (s *Socks) proxyTCP(inConn *net.Conn, methodReq socks.MethodsRequest, reque
if utils.IsIternalIP(host, *s.cfg.Always) {
useProxy = false
} else {
k := s.Resolve(request.Addr())
s.checker.Add(request.Addr(), k)
useProxy, _, _ = s.checker.IsBlocked(k)
var isInMap bool
useProxy, isInMap, _, _ = s.checker.IsBlocked(request.Addr())
if !isInMap {
s.checker.Add(request.Addr(), s.Resolve(request.Addr()))
}
}
if useProxy {
outConn, err = s.getOutConn(methodReq.Bytes(), request.Bytes(), request.Addr())
Expand Down
10 changes: 5 additions & 5 deletions utils/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,24 @@ func (c *Checker) isNeedCheck(item CheckerItem) bool {
}
return true
}
func (c *Checker) IsBlocked(address string) (blocked bool, failN, successN uint) {
func (c *Checker) IsBlocked(address string) (blocked, isInMap bool, failN, successN uint) {
if c.domainIsInMap(address, true) {
//log.Printf("%s in blocked ? true", address)
return true, 0, 0
return true, true, 0, 0
}
if c.domainIsInMap(address, false) {
//log.Printf("%s in direct ? true", address)
return false, 0, 0
return false, true, 0, 0
}

_item, ok := c.data.Get(address)
if !ok {
//log.Printf("%s not in map, blocked true", address)
return true, 0, 0
return true, false, 0, 0
}
item := _item.(CheckerItem)

return item.FailCount >= item.SuccessCount, item.FailCount, item.SuccessCount
return item.FailCount >= item.SuccessCount, true, item.FailCount, item.SuccessCount
}
func (c *Checker) domainIsInMap(address string, blockedMap bool) bool {
u, err := url.Parse("http://" + address)
Expand Down

0 comments on commit d84a4be

Please sign in to comment.