From cef96bf0928bce8bcdb3052d69251cd70b299af2 Mon Sep 17 00:00:00 2001 From: ffdfgdfg Date: Sat, 8 Feb 2020 21:25:48 +0800 Subject: [PATCH 01/14] update docs --- docs/_sidebar.md | 1 + docs/api.md | 5 +---- docs/example.md | 8 ++++---- docs/faq.md | 15 +++++++++++++++ docs/feature.md | 2 +- docs/install.md | 2 +- docs/use.md | 18 +++++++++--------- docs/webapi.md | 2 +- 8 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 docs/faq.md diff --git a/docs/_sidebar.md b/docs/_sidebar.md index c35b26e1..cc88eb17 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -22,6 +22,7 @@ * 其他 + * [FAQ](faq.md) * [贡献](contribute.md) * [捐助](donate.md) * [致谢](thanks.md) diff --git a/docs/api.md b/docs/api.md index f4c6b9a8..445d8f53 100644 --- a/docs/api.md +++ b/docs/api.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) diff --git a/docs/example.md b/docs/example.md index acaab936..2da0b87f 100644 --- a/docs/example.md +++ b/docs/example.md @@ -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 diff --git a/docs/faq.md b/docs/faq.md new file mode 100644 index 00000000..8af4769b --- /dev/null +++ b/docs/faq.md @@ -0,0 +1,15 @@ +# FAQ + +- 服务端无法启动 + +服务端默认配置启用了8024,8080,80,443端口,端口冲突无法启动,请修改配置 + +- 客户端无法连接服务端 + +请检查配置文件中的所有端口是否在安全组,防火墙放行 +请检查vkey是否对应 +请检查版本是否对应 + +- 服务端配置文件修改无效 + +install之后,linux配置文件在/etc/nps \ No newline at end of file diff --git a/docs/feature.md b/docs/feature.md index c3252b96..e8ba92a1 100644 --- a/docs/feature.md +++ b/docs/feature.md @@ -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即可运行 diff --git a/docs/install.md b/docs/install.md index a1d46c64..975ac0de 100644 --- a/docs/install.md +++ b/docs/install.md @@ -6,7 +6,7 @@ ## 源码安装 - 安装源码 -```go get -u ehang.io/nps...``` +```go get -u ehang.io/nps``` - 编译 服务端```go build cmd/nps/nps.go``` diff --git a/docs/use.md b/docs/use.md index 481e853c..086bcf07 100644 --- a/docs/use.md +++ b/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 @@ -77,7 +77,7 @@ max_conn|最大连接数,可忽略 ```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 +97,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 +114,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 +130,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 +144,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 +160,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 +177,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 +196,7 @@ target_addr|内网目标 ```ini [common] -server_addr=1.1.1.1:8284 +server_addr=1.1.1.1:8024 vkey=123 [file] mode=file diff --git a/docs/webapi.md b/docs/webapi.md index 836358ba..dfd72537 100644 --- a/docs/webapi.md +++ b/docs/webapi.md @@ -47,7 +47,7 @@ POST /client/add/ | max\_tunnel | 客户端最大隧道数量 空则为不限制 | *** -修改客户端(25.4版本有问题暂时不能用) +修改客户端 ``` POST /client/edit/ From d12edb7303295e230b78a5a2cd3510842bae2c32 Mon Sep 17 00:00:00 2001 From: ffdfgdfg Date: Sun, 9 Feb 2020 00:44:09 +0800 Subject: [PATCH 02/14] add wait after invoke goroutine pool, fix #391 --- lib/conn/conn.go | 6 +++++- lib/goroutine/pool.go | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/conn/conn.go b/lib/conn/conn.go index cf29acb3..4e511d19 100755 --- a/lib/conn/conn.go +++ b/lib/conn/conn.go @@ -14,6 +14,7 @@ import ( "net/url" "strconv" "strings" + "sync" "time" "ehang.io/nps/lib/common" @@ -371,7 +372,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) } diff --git a/lib/goroutine/pool.go b/lib/goroutine/pool.go index ca91d6d5..60717e68 100644 --- a/lib/goroutine/pool.go +++ b/lib/goroutine/pool.go @@ -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)) From df3c840a6aa29f7dda06d27368d322f0d8613d7b Mon Sep 17 00:00:00 2001 From: ffdfgdfg Date: Sun, 9 Feb 2020 00:59:07 +0800 Subject: [PATCH 03/14] bump ants version --- go.mod | 2 +- go.sum | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 6938d344..433c30b3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index f72e449c..b5ddccfb 100644 --- a/go.sum +++ b/go.sum @@ -25,6 +25,7 @@ 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/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= @@ -70,6 +71,8 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6 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 +99,7 @@ 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/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= From b475c2c46e76796eed29946ed599022c2657c06c Mon Sep 17 00:00:00 2001 From: yzy613 <59520517+yzy613@users.noreply.github.com> Date: Sun, 9 Feb 2020 16:00:11 +0800 Subject: [PATCH 04/14] Update nps_use.md --- docs/nps_use.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/nps_use.md b/docs/nps_use.md index 2681e8b3..753d40b0 100644 --- a/docs/nps_use.md +++ b/docs/nps_use.md @@ -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目录 + +对于Redhat系的Linux(例如CentOS),二进制文件会默认存放在 `/usr/bin` 或者 `/usr/lib/bin ` From 809134f3ee31d1c2ca3a72ae25ae3e88804fc4ed Mon Sep 17 00:00:00 2001 From: yzy613 <59520517+yzy613@users.noreply.github.com> Date: Sun, 9 Feb 2020 16:15:16 +0800 Subject: [PATCH 05/14] Update nps_use.md --- docs/nps_use.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/nps_use.md b/docs/nps_use.md index 753d40b0..696203b6 100644 --- a/docs/nps_use.md +++ b/docs/nps_use.md @@ -44,4 +44,4 @@ 如果无法更新成功,可以直接自行下载releases压缩包然后覆盖原有的nps二进制文件和web目录 -对于Redhat系的Linux(例如CentOS),二进制文件会默认存放在 `/usr/bin` 或者 `/usr/lib/bin ` +注意:`nps install` 之后的 nps 不在原位置,请使用 `whereis nps` 查找具体目录覆盖 nps 二进制文件 From 165529fa02ceeaecd320864da6c9988a9627341c Mon Sep 17 00:00:00 2001 From: ffdfgdfg Date: Sun, 9 Feb 2020 16:54:40 +0800 Subject: [PATCH 06/14] pprof configuration support, #382 --- cmd/npc/npc.go | 2 ++ cmd/nps/nps.go | 1 + conf/npc.conf | 1 + conf/nps.conf | 4 ++++ docs/feature.md | 6 ++++++ docs/server_config.md | 2 ++ docs/use.md | 2 ++ lib/common/pprof.go | 29 +++++++++++++++++++++++++++++ lib/config/config.go | 2 ++ 9 files changed, 49 insertions(+) create mode 100644 lib/common/pprof.go diff --git a/cmd/npc/npc.go b/cmd/npc/npc.go index 309ca685..781dc1f0 100644 --- a/cmd/npc/npc.go +++ b/cmd/npc/npc.go @@ -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) diff --git a/cmd/nps/nps.go b/cmd/nps/nps.go index e74f3445..93640ae7 100644 --- a/cmd/nps/nps.go +++ b/cmd/nps/nps.go @@ -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" } diff --git a/conf/npc.conf b/conf/npc.conf index b3dccdbd..f7b73d97 100644 --- a/conf/npc.conf +++ b/conf/npc.conf @@ -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 diff --git a/conf/nps.conf b/conf/nps.conf index cee576f2..404a981b 100755 --- a/conf/nps.conf +++ b/conf/nps.conf @@ -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 diff --git a/docs/feature.md b/docs/feature.md index e8ba92a1..79b9aba0 100644 --- a/docs/feature.md +++ b/docs/feature.md @@ -245,3 +245,9 @@ LevelInformational->6 LevelDebug->7 **对于nps:** 在`nps.conf`中设置相关配置即可 + +## pprof性能分析与调试 + +可在服务端与客户端配置中开启pprof端口,用于性能分析与调试,注释或留空相应参数为关闭。 + +默认为关闭状态 \ No newline at end of file diff --git a/docs/server_config.md b/docs/server_config.md index afa85c0b..eb7cd4ed 100644 --- a/docs/server_config.md +++ b/docs/server_config.md @@ -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 端口 diff --git a/docs/use.md b/docs/use.md index 086bcf07..32c26bdb 100644 --- a/docs/use.md +++ b/docs/use.md @@ -59,6 +59,7 @@ rate_limit=10000 flow_limit=100 remark=test max_conn=10 +#pprof_addr=0.0.0.0:9999 ``` 项 | 含义 ---|--- @@ -73,6 +74,7 @@ rate_limit|速度限制,可忽略 flow_limit|流量限制,可忽略 remark|客户端备注,可忽略 max_conn|最大连接数,可忽略 +pprof_addr|debug pprof ip:port #### 域名代理 ```ini diff --git a/lib/common/pprof.go b/lib/common/pprof.go new file mode 100644 index 00000000..7f9ee766 --- /dev/null +++ b/lib/common/pprof.go @@ -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) +} diff --git a/lib/config/config.go b/lib/config/config.go index 62e2d2bf..d30e22c0 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -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 From a12a10564ffb664f61250b16d59ab729b25a4527 Mon Sep 17 00:00:00 2001 From: ffdfgdfg Date: Sun, 9 Feb 2020 20:25:10 +0800 Subject: [PATCH 07/14] bump version to 0.26.2 --- build.sh | 2 +- docs/_coverpage.md | 2 +- gui/npc/AndroidManifest.xml | 2 +- lib/version/version.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index afd4e1e8..b67091bb 100755 --- a/build.sh +++ b/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 diff --git a/docs/_coverpage.md b/docs/_coverpage.md index 8936cfb3..17d1b602 100644 --- a/docs/_coverpage.md +++ b/docs/_coverpage.md @@ -1,6 +1,6 @@ ![logo](logo.svg) -# NPS 0.26.1 +# NPS 0.26.2 > 一款轻量级、高性能、功能强大的内网穿透代理服务器 diff --git a/gui/npc/AndroidManifest.xml b/gui/npc/AndroidManifest.xml index 550151fe..6e6f2d70 100755 --- a/gui/npc/AndroidManifest.xml +++ b/gui/npc/AndroidManifest.xml @@ -2,7 +2,7 @@ diff --git a/lib/version/version.go b/lib/version/version.go index 4f594121..b7b9f207 100644 --- a/lib/version/version.go +++ b/lib/version/version.go @@ -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 { From c68a1e812a72d1552bb198d9f6b812c969b52ae0 Mon Sep 17 00:00:00 2001 From: cnlh Date: Mon, 10 Feb 2020 16:22:56 +0800 Subject: [PATCH 08/14] fix:bind local udp port error causes program to crash --- client/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index 99801f2b..1501573a 100755 --- a/client/client.go +++ b/client/client.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) From 148fcfcb1495cf72489054275623e558031985cc Mon Sep 17 00:00:00 2001 From: cnlh Date: Mon, 10 Feb 2020 17:52:51 +0800 Subject: [PATCH 09/14] change ci address --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 0ca334ed..361ed2a7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,7 @@ # nps ![](https://img.shields.io/github/stars/cnlh/nps.svg) ![](https://img.shields.io/github/forks/cnlh/nps.svg) [![Gitter](https://badges.gitter.im/cnlh-nps/community.svg)](https://gitter.im/cnlh-nps/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) -[![Build Status](https://travis-ci.org/cnlh/nps.svg?branch=master)](https://travis-ci.org/cnlh/nps) +[![Build Status](https://travis-ci.org/ehang-io/nps.svg?branch=master)](https://travis-ci.org/cnlh/nps) nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务器。目前支持**tcp、udp流量转发**,可支持任何**tcp、udp**上层协议(访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析等等……),此外还**支持内网http代理、内网socks5代理**、**p2p等**,并带有功能强大的web管理端。 From 01d230a453b2b9373781895763bba482f50df95a Mon Sep 17 00:00:00 2001 From: ffdfgdfg Date: Tue, 11 Feb 2020 00:38:24 +0800 Subject: [PATCH 10/14] read full http proxy request, fix UnexpectedEOF error --- lib/conn/conn.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/conn/conn.go b/lib/conn/conn.go index 4e511d19..2bd5ea20 100755 --- a/lib/conn/conn.go +++ b/lib/conn/conn.go @@ -35,11 +35,30 @@ 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 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] From 94c0618dad1f4c90a379923c697ad90bf72b8977 Mon Sep 17 00:00:00 2001 From: cnlh Date: Tue, 11 Feb 2020 14:01:16 +0800 Subject: [PATCH 11/14] fix read request --- lib/conn/conn.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/conn/conn.go b/lib/conn/conn.go index 2bd5ea20..dbc7d886 100755 --- a/lib/conn/conn.go +++ b/lib/conn/conn.go @@ -43,6 +43,9 @@ func (s *Conn) readRequest(buf []byte) (n int, err error) { return } n += rd + if n < 4 { + continue + } if string(buf[n-4:n]) == "\r\n\r\n" { return } From a15013bbdf84b2d41fcc679bf47f1880e12a7c2d Mon Sep 17 00:00:00 2001 From: yzy613 <59520517+yzy613@users.noreply.github.com> Date: Tue, 11 Feb 2020 02:45:58 -0600 Subject: [PATCH 12/14] Update faq.md (#400) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update faq.md 文字排版美化 * Update faq.md --- docs/faq.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index 8af4769b..a8efdcf3 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -1,15 +1,16 @@ # FAQ - 服务端无法启动 - +``` 服务端默认配置启用了8024,8080,80,443端口,端口冲突无法启动,请修改配置 - +``` - 客户端无法连接服务端 - +``` 请检查配置文件中的所有端口是否在安全组,防火墙放行 请检查vkey是否对应 请检查版本是否对应 - +``` - 服务端配置文件修改无效 - -install之后,linux配置文件在/etc/nps \ No newline at end of file +``` +install 之后,Linux 配置文件在 /etc/nps +``` From 332b98e3700582f07c6817defcc18c1338c15604 Mon Sep 17 00:00:00 2001 From: cnlh Date: Tue, 11 Feb 2020 19:54:16 +0800 Subject: [PATCH 13/14] sync file when save --- lib/file/file.go | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/file/file.go b/lib/file/file.go index beab47f3..9e28e95e 100644 --- a/lib/file/file.go +++ b/lib/file/file.go @@ -177,4 +177,5 @@ func storeSyncMapToFile(m sync.Map, filePath string) { } return true }) + file.Sync() } From f50df9aefdf2d603c73314b3a343062893ebca11 Mon Sep 17 00:00:00 2001 From: ffdfgdfg Date: Tue, 11 Feb 2020 21:37:05 +0800 Subject: [PATCH 14/14] bump fyne version --- build.android.sh | 21 ++++++++------------- go.mod | 2 +- go.sum | 8 ++++---- 3 files changed, 13 insertions(+), 18 deletions(-) mode change 100644 => 100755 build.android.sh diff --git a/build.android.sh b/build.android.sh old mode 100644 new mode 100755 index 918a66ae..8f1a57fd --- a/build.android.sh +++ b/build.android.sh @@ -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" diff --git a/go.mod b/go.mod index 433c30b3..c43c98c4 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index b5ddccfb..d4dd9519 100644 --- a/go.sum +++ b/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,7 @@ 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= @@ -69,8 +70,6 @@ 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= @@ -99,6 +98,7 @@ 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=