fix GetAllInterfaceAddr cpu high

This commit is contained in:
arraykeys@gmail.com
2018-08-21 10:29:51 +08:00
parent b9f054c495
commit aab899397e
6 changed files with 15 additions and 10 deletions

View File

@ -48,7 +48,7 @@ Proxy是golang实现的高性能http,https,websocket,tcp,udp,socks5代理服务
- ... - ...
本页是v5.3手册,其他版本手册请点击[这里](docs/old-release.md)查看. 本页是v5.4手册,其他版本手册请点击[这里](docs/old-release.md)查看.
### 怎么找到组织? ### 怎么找到组织?
@ -159,7 +159,7 @@ curl -L https://raw.githubusercontent.com/snail007/goproxy/master/install_auto.s
下载地址:https://github.com/snail007/goproxy/releases 下载地址:https://github.com/snail007/goproxy/releases
```shell ```shell
cd /root/proxy/ cd /root/proxy/
wget https://github.com/snail007/goproxy/releases/download/v5.3/proxy-linux-amd64.tar.gz wget https://github.com/snail007/goproxy/releases/download/v5.4/proxy-linux-amd64.tar.gz
``` ```
#### **2.下载自动安装脚本** #### **2.下载自动安装脚本**
```shell ```shell

View File

@ -1,5 +1,6 @@
# Old Versions of Proxy # Old Versions of Proxy
- [v5.3手册](https://github.com/snail007/goproxy/tree/v5.3)
- [v5.2手册](https://github.com/snail007/goproxy/tree/v5.2) - [v5.2手册](https://github.com/snail007/goproxy/tree/v5.2)
- [v5.1手册](https://github.com/snail007/goproxy/tree/v5.1) - [v5.1手册](https://github.com/snail007/goproxy/tree/v5.1)
- [v5.0手册](https://github.com/snail007/goproxy/tree/v5.0) - [v5.0手册](https://github.com/snail007/goproxy/tree/v5.0)

View File

@ -5,7 +5,7 @@ if [ -e /tmp/proxy ]; then
fi fi
mkdir /tmp/proxy mkdir /tmp/proxy
cd /tmp/proxy cd /tmp/proxy
wget https://github.com/snail007/goproxy/releases/download/v5.3/proxy-linux-amd64.tar.gz wget https://github.com/snail007/goproxy/releases/download/v5.4/proxy-linux-amd64.tar.gz
# #install proxy # #install proxy
tar zxvf proxy-linux-amd64.tar.gz tar zxvf proxy-linux-amd64.tar.gz

View File

@ -9,7 +9,7 @@ import (
"github.com/snail007/goproxy/services" "github.com/snail007/goproxy/services"
) )
const APP_VERSION = "5.3" const APP_VERSION = "5.4"
func main() { func main() {
err := initConfig() err := initConfig()

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
VER="5.3" VER="5.4"
RELEASE="release-${VER}" RELEASE="release-${VER}"
rm -rf .cert rm -rf .cert
mkdir .cert mkdir .cert

View File

@ -22,15 +22,14 @@ import (
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
"context"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"context"
"github.com/snail007/goproxy/utils/id" "github.com/snail007/goproxy/utils/id"
kcp "github.com/xtaci/kcp-go" kcp "github.com/xtaci/kcp-go"
) )
func IoBind(dst io.ReadWriteCloser, src io.ReadWriteCloser, fn func(err interface{}), log *logger.Logger) { func IoBind(dst io.ReadWriteCloser, src io.ReadWriteCloser, fn func(err interface{}), log *logger.Logger) {
@ -210,8 +209,13 @@ func CloseConn(conn *net.Conn) {
(*conn).Close() (*conn).Close()
} }
} }
func GetAllInterfaceAddr() ([]net.IP, error) {
var allInterfaceAddrCache []net.IP
func GetAllInterfaceAddr() ([]net.IP, error) {
if allInterfaceAddrCache != nil {
return allInterfaceAddrCache, nil
}
ifaces, err := net.Interfaces() ifaces, err := net.Interfaces()
if err != nil { if err != nil {
return nil, err return nil, err
@ -252,6 +256,7 @@ func GetAllInterfaceAddr() ([]net.IP, error) {
return nil, fmt.Errorf("no address Found, net.InterfaceAddrs: %v", addresses) return nil, fmt.Errorf("no address Found, net.InterfaceAddrs: %v", addresses)
} }
//only need first //only need first
allInterfaceAddrCache = addresses
return addresses, nil return addresses, nil
} }
func UDPPacket(srcAddr string, packet []byte) []byte { func UDPPacket(srcAddr string, packet []byte) []byte {
@ -635,14 +640,13 @@ func InsertProxyHeaders(head []byte, headers string) []byte {
// return // return
// } // }
/* /*
net.LookupIP may cause deadlock in windows net.LookupIP may cause deadlock in windows
https://github.com/golang/go/issues/24178 https://github.com/golang/go/issues/24178
*/ */
func MyLookupIP(host string) ([]net.IP, error) { func MyLookupIP(host string) ([]net.IP, error) {
ctx ,cancel := context.WithTimeout(context.Background(),time.Second *time.Duration(3)) ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(3))
defer func() { defer func() {
cancel() cancel()
//ctx.Done() //ctx.Done()