Skip to content

Commit

Permalink
fix GetAllInterfaceAddr cpu high
Browse files Browse the repository at this point in the history
  • Loading branch information
snail007 committed Aug 21, 2018
1 parent b9f054c commit aab8993
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README_ZH.md
Expand Up @@ -48,7 +48,7 @@ Proxy是golang实现的高性能http,https,websocket,tcp,udp,socks5代理服务
- ...


本页是v5.3手册,其他版本手册请点击[这里](docs/old-release.md)查看.
本页是v5.4手册,其他版本手册请点击[这里](docs/old-release.md)查看.


### 怎么找到组织?
Expand Down Expand Up @@ -159,7 +159,7 @@ curl -L https://raw.githubusercontent.com/snail007/goproxy/master/install_auto.s
下载地址:https://github.com/snail007/goproxy/releases
```shell
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.下载自动安装脚本**
```shell
Expand Down
1 change: 1 addition & 0 deletions docs/old-release.md
@@ -1,5 +1,6 @@
# 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.1手册](https://github.com/snail007/goproxy/tree/v5.1)
- [v5.0手册](https://github.com/snail007/goproxy/tree/v5.0)
Expand Down
2 changes: 1 addition & 1 deletion install_auto.sh
Expand Up @@ -5,7 +5,7 @@ if [ -e /tmp/proxy ]; then
fi
mkdir /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
tar zxvf proxy-linux-amd64.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/snail007/goproxy/services"
)

const APP_VERSION = "5.3"
const APP_VERSION = "5.4"

func main() {
err := initConfig()
Expand Down
2 changes: 1 addition & 1 deletion release.sh
@@ -1,5 +1,5 @@
#!/bin/bash
VER="5.3"
VER="5.4"
RELEASE="release-${VER}"
rm -rf .cert
mkdir .cert
Expand Down
14 changes: 9 additions & 5 deletions utils/functions.go
Expand Up @@ -22,15 +22,14 @@ import (

"golang.org/x/crypto/pbkdf2"

"context"
"strconv"
"strings"
"time"
"context"

"github.com/snail007/goproxy/utils/id"

kcp "github.com/xtaci/kcp-go"

)

func IoBind(dst io.ReadWriteCloser, src io.ReadWriteCloser, fn func(err interface{}), log *logger.Logger) {
Expand Down Expand Up @@ -210,8 +209,13 @@ func CloseConn(conn *net.Conn) {
(*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()
if err != nil {
return nil, err
Expand Down Expand Up @@ -252,6 +256,7 @@ func GetAllInterfaceAddr() ([]net.IP, error) {
return nil, fmt.Errorf("no address Found, net.InterfaceAddrs: %v", addresses)
}
//only need first
allInterfaceAddrCache = addresses
return addresses, nil
}
func UDPPacket(srcAddr string, packet []byte) []byte {
Expand Down Expand Up @@ -635,14 +640,13 @@ func InsertProxyHeaders(head []byte, headers string) []byte {
// return
// }


/*
net.LookupIP may cause deadlock in windows
https://github.com/golang/go/issues/24178
*/
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() {
cancel()
//ctx.Done()
Expand Down

0 comments on commit aab8993

Please sign in to comment.