mirror of https://github.com/ehang-io/nps
commit
7ede000597
|
@ -1,17 +1,14 @@
|
|||
#/bin/bash
|
||||
#sudo apt-get install libgl1-mesa-dev xorg-dev
|
||||
#go get github.com/ffdfgdfg/fyne-cross
|
||||
#fyne-cross --targets=linux/amd64,windows/amd64,darwin/amd64 gui/npc/npc.go
|
||||
|
||||
cd /go
|
||||
apt-get install libegl1-mesa-dev libgles2-mesa-dev libx11-dev -y
|
||||
#go get -u fyne.io/fyne/cmd/fyne fyne.io/fyne
|
||||
mkdir -p /go/src/fyne.io
|
||||
cd src/fyne.io
|
||||
git clone https://github.com/fyne-io/fyne.git
|
||||
cd fyne
|
||||
git checkout v1.2.0
|
||||
go install -v ./cmd/fyne
|
||||
go get -u fyne.io/fyne/cmd/fyne fyne.io/fyne
|
||||
#mkdir -p /go/src/fyne.io
|
||||
#cd src/fyne.io
|
||||
#git clone https://github.com/fyne-io/fyne.git
|
||||
#cd fyne
|
||||
#git checkout v1.2.0
|
||||
#go install -v ./cmd/fyne
|
||||
#fyne package -os android fyne.io/fyne/cmd/hello
|
||||
echo "fyne install success"
|
||||
mkdir -p /go/src/ehang.io/nps
|
||||
|
@ -32,8 +29,6 @@ rm -rf vendor
|
|||
#rm -rf ~/.cache/*
|
||||
echo "vendor success"
|
||||
cd gui/npc
|
||||
#rm -rf /go/src/golang.org/x/mobile
|
||||
#go get -u fyne.io/fyne/cmd/fyne@v1.2.0
|
||||
#export ANDROID_NDK_HOME=/usr/local/android_sdk/ndk-bundle
|
||||
fyne package -appID org.nps.client -os android -icon ../../docs/logo.png
|
||||
mv npc.apk /app/android_client.apk
|
||||
echo "android build success"
|
||||
|
|
2
build.sh
2
build.sh
|
@ -1,5 +1,5 @@
|
|||
#/bash/sh
|
||||
export VERSION=0.26.1
|
||||
export VERSION=0.26.2
|
||||
|
||||
sudo apt-get install gcc-mingw-w64-i686
|
||||
env GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc go build -ldflags "-s -w -extldflags -static -extldflags -static" -buildmode=c-shared -o npc_sdk.dll cmd/npc/sdk.go
|
||||
|
|
|
@ -216,12 +216,12 @@ func (s *TRPClient) handleChan(src net.Conn) {
|
|||
func (s *TRPClient) handleUdp(serverConn net.Conn) {
|
||||
// bind a local udp port
|
||||
local, err := net.ListenUDP("udp", nil)
|
||||
defer local.Close()
|
||||
defer serverConn.Close()
|
||||
if err != nil {
|
||||
logs.Error("bind local udp port error ", err.Error())
|
||||
return
|
||||
}
|
||||
defer local.Close()
|
||||
go func() {
|
||||
defer serverConn.Close()
|
||||
b := common.BufPoolUdp.Get().([]byte)
|
||||
|
|
|
@ -33,6 +33,7 @@ var (
|
|||
localType = flag.String("local_type", "p2p", "p2p target")
|
||||
logPath = flag.String("log_path", "", "npc log path")
|
||||
debug = flag.Bool("debug", true, "npc debug")
|
||||
pprofAddr = flag.String("pprof", "", "PProf debug addr (ip:port)")
|
||||
)
|
||||
|
||||
const systemdScript = `[Unit]
|
||||
|
@ -171,6 +172,7 @@ func (p *npc) run() error {
|
|||
logs.Warning("npc: panic serving %v: %v\n%s", err, string(buf))
|
||||
}
|
||||
}()
|
||||
common.InitPProfFromArg(*pprofAddr)
|
||||
//p2p or secret command
|
||||
if *password != "" {
|
||||
commonConfig := new(config.CommonConfig)
|
||||
|
|
|
@ -59,6 +59,7 @@ func main() {
|
|||
if err := beego.LoadAppConfig("ini", filepath.Join(common.GetRunPath(), "conf", "nps.conf")); err != nil {
|
||||
log.Fatalln("load config file error", err.Error())
|
||||
}
|
||||
common.InitPProfFromFile()
|
||||
if level = beego.AppConfig.String("log_level"); level == "" {
|
||||
level = "7"
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ web_username=user
|
|||
web_password=1234
|
||||
crypt=true
|
||||
compress=true
|
||||
#pprof_addr=0.0.0.0:9999
|
||||
|
||||
[health_check_test1]
|
||||
health_check_timeout=1
|
||||
|
|
|
@ -76,3 +76,7 @@ http_cache_length=100
|
|||
|
||||
#get origin ip
|
||||
http_add_origin_header=false
|
||||
|
||||
#pprof debug options
|
||||
#pprof_ip=0.0.0.0
|
||||
#pprof_port=9999
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# nps
|
||||
 
|
||||
[](https://gitter.im/cnlh-nps/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
[](https://travis-ci.org/cnlh/nps)
|
||||
[](https://travis-ci.org/cnlh/nps)
|
||||
|
||||
nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务器。目前支持**tcp、udp流量转发**,可支持任何**tcp、udp**上层协议(访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析等等……),此外还**支持内网http代理、内网socks5代理**、**p2p等**,并带有功能强大的web管理端。
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||

|
||||
|
||||
# NPS <small>0.26.1</small>
|
||||
# NPS <small>0.26.2</small>
|
||||
|
||||
> 一款轻量级、高性能、功能强大的内网穿透代理服务器
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
* 其他
|
||||
|
||||
* [FAQ](faq.md)
|
||||
* [贡献](contribute.md)
|
||||
* [捐助](donate.md)
|
||||
* [致谢](thanks.md)
|
||||
|
|
|
@ -42,7 +42,4 @@ POST /auth/getauthkey
|
|||
- 解密串编码方式 十六进制
|
||||
|
||||
## 详细文档
|
||||
- **此文档近期可能更新较慢,建议自行抓包**
|
||||
|
||||
为方便第三方扩展,在web模式下可利用webAPI进行相关操作,详情见
|
||||
[webAPI文档](https://github.com/ehang-io/nps/wiki/webAPI%E6%96%87%E6%A1%A3)
|
||||
- **[详见](webapi.md)** (感谢@avengexyz)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# 使用示例
|
||||
## 统一准备工作(必做)
|
||||
- 开启服务端,假设公网服务器ip为1.1.1.1,配置文件中`bridge_port`为8284,配置文件中`web_port`为8080
|
||||
- 开启服务端,假设公网服务器ip为1.1.1.1,配置文件中`bridge_port`为8024,配置文件中`web_port`为8080
|
||||
- 访问1.1.1.1:8080
|
||||
- 在客户端管理中创建一个客户端,记录下验证密钥
|
||||
- 内网客户端运行(windows使用cmd运行加.exe)
|
||||
|
||||
```shell
|
||||
./npc -server=1.1.1.1:8284 -vkey=客户端的密钥
|
||||
./npc -server=1.1.1.1:8024 -vkey=客户端的密钥
|
||||
```
|
||||
**注意:运行服务端后,请确保能从客户端设备上正常访问配置文件中所配置的`bridge_port`端口,telnet,netcat这类的来检查**
|
||||
|
||||
|
@ -89,7 +89,7 @@
|
|||
- 在需要连接ssh的机器上以执行命令
|
||||
|
||||
```
|
||||
./npc -server=1.1.1.1:8284 -vkey=vkey -type=tcp -password=secrettest -local_type=secret
|
||||
./npc -server=1.1.1.1:8024 -vkey=vkey -type=tcp -password=secrettest -local_type=secret
|
||||
```
|
||||
如需指定本地端口可加参数`-local_port=xx`,默认为2000
|
||||
|
||||
|
@ -112,7 +112,7 @@
|
|||
- 在使用端机器(本机)执行命令
|
||||
|
||||
```
|
||||
./npc -server=1.1.1.1:8284 -vkey=123 -password=p2pssh -target=10.2.50.2:22
|
||||
./npc -server=1.1.1.1:8024 -vkey=123 -password=p2pssh -target=10.2.50.2:22
|
||||
```
|
||||
如需指定本地端口可加参数`-local_port=xx`,默认为2000
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
# FAQ
|
||||
|
||||
- 服务端无法启动
|
||||
```
|
||||
服务端默认配置启用了8024,8080,80,443端口,端口冲突无法启动,请修改配置
|
||||
```
|
||||
- 客户端无法连接服务端
|
||||
```
|
||||
请检查配置文件中的所有端口是否在安全组,防火墙放行
|
||||
请检查vkey是否对应
|
||||
请检查版本是否对应
|
||||
```
|
||||
- 服务端配置文件修改无效
|
||||
```
|
||||
install 之后,Linux 配置文件在 /etc/nps
|
||||
```
|
|
@ -167,7 +167,7 @@ npc支持环境变量渲染以适应在某些特殊场景下的要求。
|
|||
**在无配置文件启动模式下:**
|
||||
设置环境变量
|
||||
```
|
||||
export NPC_SERVER_ADDR=1.1.1.1:8284
|
||||
export NPC_SERVER_ADDR=1.1.1.1:8024
|
||||
export NPC_SERVER_VKEY=xxxxx
|
||||
```
|
||||
直接执行./npc即可运行
|
||||
|
@ -245,3 +245,9 @@ LevelInformational->6 LevelDebug->7
|
|||
**对于nps:**
|
||||
|
||||
在`nps.conf`中设置相关配置即可
|
||||
|
||||
## pprof性能分析与调试
|
||||
|
||||
可在服务端与客户端配置中开启pprof端口,用于性能分析与调试,注释或留空相应参数为关闭。
|
||||
|
||||
默认为关闭状态
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
## 源码安装
|
||||
- 安装源码
|
||||
```go get -u ehang.io/nps...```
|
||||
```go get -u ehang.io/nps```
|
||||
- 编译
|
||||
|
||||
服务端```go build cmd/nps/nps.go```
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
nps.exe stop|restart
|
||||
```
|
||||
## 服务端更新
|
||||
请首先执行`sudo nps stop`或者`nps.exe stop`停止运行,然后
|
||||
请首先执行 `sudo nps stop` 或者 `nps.exe stop` 停止运行,然后
|
||||
|
||||
对于linux
|
||||
```shell
|
||||
|
@ -40,6 +40,8 @@
|
|||
nps-update.exe update
|
||||
```
|
||||
|
||||
更新完成后,执行执行`sudo nps start`或者`nps.exe start`重新运行即可完成升级
|
||||
更新完成后,执行执行 `sudo nps start` 或者 `nps.exe start` 重新运行即可完成升级
|
||||
|
||||
如果无法更新成功,可以直接自行下载releases压缩包然后覆盖原有的nps二进制文件和web目录
|
||||
|
||||
注意:`nps install` 之后的 nps 不在原位置,请使用 `whereis nps` 查找具体目录覆盖 nps 二进制文件
|
||||
|
|
|
@ -19,3 +19,5 @@ log_level|日志输出级别
|
|||
auth_crypt_key | 获取服务端authKey时的aes加密密钥,16位
|
||||
p2p_ip| 服务端Ip,使用p2p模式必填
|
||||
p2p_port|p2p模式开启的udp端口
|
||||
pprof_ip|debug pprof 服务端ip
|
||||
pprof_port|debug pprof 端口
|
||||
|
|
20
docs/use.md
20
docs/use.md
|
@ -48,7 +48,7 @@ npc-update.exe update
|
|||
#### 全局配置
|
||||
```ini
|
||||
[common]
|
||||
server_addr=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8024
|
||||
conn_type=tcp
|
||||
vkey=123
|
||||
username=111
|
||||
|
@ -59,6 +59,7 @@ rate_limit=10000
|
|||
flow_limit=100
|
||||
remark=test
|
||||
max_conn=10
|
||||
#pprof_addr=0.0.0.0:9999
|
||||
```
|
||||
项 | 含义
|
||||
---|---
|
||||
|
@ -73,11 +74,12 @@ rate_limit|速度限制,可忽略
|
|||
flow_limit|流量限制,可忽略
|
||||
remark|客户端备注,可忽略
|
||||
max_conn|最大连接数,可忽略
|
||||
pprof_addr|debug pprof ip:port
|
||||
#### 域名代理
|
||||
|
||||
```ini
|
||||
[common]
|
||||
server_addr=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8024
|
||||
vkey=123
|
||||
[web1]
|
||||
host=a.proxy.com
|
||||
|
@ -97,7 +99,7 @@ header_xxx|请求header修改或添加,header_proxy表示添加header proxy:np
|
|||
|
||||
```ini
|
||||
[common]
|
||||
server_addr=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8024
|
||||
vkey=123
|
||||
[tcp]
|
||||
mode=tcp
|
||||
|
@ -114,7 +116,7 @@ tartget_addr|内网目标
|
|||
|
||||
```ini
|
||||
[common]
|
||||
server_addr=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8024
|
||||
vkey=123
|
||||
[udp]
|
||||
mode=udp
|
||||
|
@ -130,7 +132,7 @@ target_addr|内网目标
|
|||
|
||||
```ini
|
||||
[common]
|
||||
server_addr=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8024
|
||||
vkey=123
|
||||
[http]
|
||||
mode=httpProxy
|
||||
|
@ -144,7 +146,7 @@ server_port | 在服务端的代理端口
|
|||
|
||||
```ini
|
||||
[common]
|
||||
server_addr=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8024
|
||||
vkey=123
|
||||
[socks5]
|
||||
mode=socks5
|
||||
|
@ -160,7 +162,7 @@ multi_account | socks5多账号配置文件(可选),配置后使用basic_usern
|
|||
|
||||
```ini
|
||||
[common]
|
||||
server_addr=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8024
|
||||
vkey=123
|
||||
[secret_ssh]
|
||||
mode=secret
|
||||
|
@ -177,7 +179,7 @@ target_addr|内网目标
|
|||
|
||||
```ini
|
||||
[common]
|
||||
server_addr=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8024
|
||||
vkey=123
|
||||
[p2p_ssh]
|
||||
mode=p2p
|
||||
|
@ -196,7 +198,7 @@ target_addr|内网目标
|
|||
|
||||
```ini
|
||||
[common]
|
||||
server_addr=1.1.1.1:8284
|
||||
server_addr=1.1.1.1:8024
|
||||
vkey=123
|
||||
[file]
|
||||
mode=file
|
||||
|
|
|
@ -47,7 +47,7 @@ POST /client/add/
|
|||
| max\_tunnel | 客户端最大隧道数量 空则为不限制 |
|
||||
|
||||
***
|
||||
修改客户端(25.4版本有问题暂时不能用)
|
||||
修改客户端
|
||||
|
||||
```
|
||||
POST /client/edit/
|
||||
|
|
4
go.mod
4
go.mod
|
@ -4,7 +4,7 @@ go 1.13
|
|||
|
||||
require (
|
||||
ehang.io/nps-mux v0.0.0-20200116160632-de59baca47b5
|
||||
fyne.io/fyne v1.2.0
|
||||
fyne.io/fyne v1.2.2
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
||||
github.com/astaxie/beego v1.12.0
|
||||
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
|
||||
|
@ -16,7 +16,7 @@ require (
|
|||
github.com/hooklift/assert v0.0.0-20170704181755-9d1defd6d214 // indirect
|
||||
github.com/kardianos/service v1.0.0
|
||||
github.com/klauspost/pgzip v1.2.1 // indirect
|
||||
github.com/panjf2000/ants/v2 v2.2.2
|
||||
github.com/panjf2000/ants/v2 v2.3.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
|
||||
github.com/shirou/gopsutil v2.19.11+incompatible
|
||||
|
|
15
go.sum
15
go.sum
|
@ -1,7 +1,7 @@
|
|||
ehang.io/nps-mux v0.0.0-20200116160632-de59baca47b5 h1:gbYMN0t1mroAtodN9t7rFRqAYtBGQpqjPNaJ/zFGmD8=
|
||||
ehang.io/nps-mux v0.0.0-20200116160632-de59baca47b5/go.mod h1:v2gdtoMBRGYe5y9mSBwPw6V4V/2Zz5GyTuCNlsUPHkY=
|
||||
fyne.io/fyne v1.2.0 h1:mdp7Cs7QmSJTeazYxEDa9wWeJNig7paBcjm0dooFtLE=
|
||||
fyne.io/fyne v1.2.0/go.mod h1:Ab+3DIB/FVteW0y4DXfmZv4N3JdnCBh2lHkINI02BOU=
|
||||
fyne.io/fyne v1.2.2 h1:mf7EseASp3CAC5vLWVPLnsoKxvp/ARdu3Seh0HvAQak=
|
||||
fyne.io/fyne v1.2.2/go.mod h1:Ab+3DIB/FVteW0y4DXfmZv4N3JdnCBh2lHkINI02BOU=
|
||||
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
||||
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
|
||||
github.com/OwnLocal/goes v1.0.0/go.mod h1:8rIFjBGTue3lCU0wplczcUgt9Gxgrkkrw7etMIcn8TM=
|
||||
|
@ -25,6 +25,8 @@ github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a/go.mod h1:BQwMFl
|
|||
github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
|
||||
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
|
||||
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
|
||||
|
@ -68,8 +70,8 @@ github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
|||
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/panjf2000/ants/v2 v2.2.2 h1:TWzusBjq/IflXhy+/S6u5wmMLCBdJnB9tPIx9Zmhvok=
|
||||
github.com/panjf2000/ants/v2 v2.2.2/go.mod h1:1GFm8bV8nyCQvU5K4WvBCTG1/YBFOD2VzjffD8fV55A=
|
||||
github.com/panjf2000/ants/v2 v2.3.0 h1:+l+41IiyMmpcK+YhWs2dn3tgL6cg4cvJzup1mBGmU00=
|
||||
github.com/panjf2000/ants/v2 v2.3.0/go.mod h1:LtwNaBX6OeF5qRtQlaeGndalVwJlS2ueur7uwoAHbPA=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
|
@ -96,6 +98,8 @@ github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXc
|
|||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709 h1:Ko2LQMrRU+Oy/+EDBwX7eZ2jp3C47eDBB8EIhKTun+I=
|
||||
github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
|
||||
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 h1:89CEmDvlq/F7SJEOqkIdNDGJXrQIhuIx9D2DBXjavSU=
|
||||
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
|
||||
|
@ -143,3 +147,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
|
|||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
|
||||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.26.1"
|
||||
android:versionName="0.26.2"
|
||||
package="org.nps.client"
|
||||
platformBuildVersionCode="15"
|
||||
platformBuildVersionName="4.0.4-1406430">
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
)
|
||||
|
||||
func InitPProfFromFile() {
|
||||
ip := beego.AppConfig.String("pprof_ip")
|
||||
p := beego.AppConfig.String("pprof_port")
|
||||
if len(ip) > 0 && len(p) > 0 && IsPort(p) {
|
||||
runPProf(ip + ":" + p)
|
||||
}
|
||||
}
|
||||
|
||||
func InitPProfFromArg(arg string) {
|
||||
if len(arg) > 0 {
|
||||
runPProf(arg)
|
||||
}
|
||||
}
|
||||
|
||||
func runPProf(ipPort string) {
|
||||
go func() {
|
||||
_ = http.ListenAndServe(ipPort, nil)
|
||||
}()
|
||||
logs.Info("PProf debug listen on", ipPort)
|
||||
}
|
|
@ -145,6 +145,8 @@ func dealCommon(s string) *CommonConfig {
|
|||
c.Client.MaxConn = common.GetIntNoErrByStr(item[1])
|
||||
case "remark":
|
||||
c.Client.Remark = item[1]
|
||||
case "pprof_addr":
|
||||
common.InitPProfFromArg(item[1])
|
||||
}
|
||||
}
|
||||
return c
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"ehang.io/nps/lib/common"
|
||||
|
@ -34,11 +35,33 @@ func NewConn(conn net.Conn) *Conn {
|
|||
return &Conn{Conn: conn}
|
||||
}
|
||||
|
||||
func (s *Conn) readRequest(buf []byte) (n int, err error) {
|
||||
var rd int
|
||||
for {
|
||||
rd, err = s.Read(buf[n:])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
n += rd
|
||||
if n < 4 {
|
||||
continue
|
||||
}
|
||||
if string(buf[n-4:n]) == "\r\n\r\n" {
|
||||
return
|
||||
}
|
||||
// buf is full, can't contain the request
|
||||
if n == cap(buf) {
|
||||
err = io.ErrUnexpectedEOF
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//get host 、connection type、method...from connection
|
||||
func (s *Conn) GetHost() (method, address string, rb []byte, err error, r *http.Request) {
|
||||
var b [32 * 1024]byte
|
||||
var n int
|
||||
if n, err = s.Read(b[:]); err != nil {
|
||||
if n, err = s.readRequest(b[:]); err != nil {
|
||||
return
|
||||
}
|
||||
rb = b[:n]
|
||||
|
@ -371,7 +394,10 @@ func CopyWaitGroup(conn1, conn2 net.Conn, crypt bool, snappy bool, rate *rate.Ra
|
|||
//if flow != nil {
|
||||
// flow.Add(in, out)
|
||||
//}
|
||||
err := goroutine.CopyConnsPool.Invoke(goroutine.NewConns(connHandle, conn2, flow))
|
||||
wg := new(sync.WaitGroup)
|
||||
wg.Add(1)
|
||||
err := goroutine.CopyConnsPool.Invoke(goroutine.NewConns(connHandle, conn2, flow, wg))
|
||||
wg.Wait()
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
}
|
||||
|
|
|
@ -177,4 +177,5 @@ func storeSyncMapToFile(m sync.Map, filePath string) {
|
|||
}
|
||||
return true
|
||||
})
|
||||
file.Sync()
|
||||
}
|
||||
|
|
|
@ -44,13 +44,15 @@ type Conns struct {
|
|||
conn1 io.ReadWriteCloser // mux connection
|
||||
conn2 net.Conn // outside connection
|
||||
flow *file.Flow
|
||||
wg *sync.WaitGroup
|
||||
}
|
||||
|
||||
func NewConns(c1 io.ReadWriteCloser, c2 net.Conn, flow *file.Flow) Conns {
|
||||
func NewConns(c1 io.ReadWriteCloser, c2 net.Conn, flow *file.Flow, wg *sync.WaitGroup) Conns {
|
||||
return Conns{
|
||||
conn1: c1,
|
||||
conn2: c2,
|
||||
flow: flow,
|
||||
wg: wg,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,6 +69,7 @@ func copyConns(group interface{}) {
|
|||
if conns.flow != nil {
|
||||
conns.flow.Add(in, out)
|
||||
}
|
||||
conns.wg.Done()
|
||||
}
|
||||
|
||||
var connCopyPool, _ = ants.NewPoolWithFunc(200000, copyConnGroup, ants.WithNonblocking(false))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package version
|
||||
|
||||
const VERSION = "0.26.1"
|
||||
const VERSION = "0.26.2"
|
||||
|
||||
// Compulsory minimum version, Minimum downward compatibility to this version
|
||||
func GetVersion() string {
|
||||
|
|
Loading…
Reference in New Issue