Compare commits

..
37 Commits
Author SHA1 Message Date
ffdfgdfg e69b596370 Merge pull request #342 from cnlh/dev
fix version v0.25.4
2019-12-30 00:27:36 +08:00
ffdfgdfg fe1c6e10dd master to dev (#341) 2019-12-30 00:25:36 +08:00
ffdfgdfg 86e0a52bb9 fix android build 2019-12-30 00:22:50 +08:00
ffdfgdfg 1f64715fab fix mux kcp connection 2019-12-28 20:40:00 +08:00
ffdfgdfg 813eae1216 Merge branch 'dev' of https://github.com/cnlh/nps into dev 2019-12-28 00:22:50 +08:00
ffdfgdfg 9b29bd64bd fix windows 2019-12-27 23:24:19 +08:00
ffdfgdfg 3875bbfa17 Merge pull request #334 from cnlh/dev
Dev
2019-12-27 13:19:34 +08:00
ffdfgdfg f364936087 bump version to 0.25.4 2019-12-27 13:14:49 +08:00
ffdfgdfg 5e1b0be81c fix mux send window size counting 2019-12-27 13:02:28 +08:00
刘河 4de24ff13a update docs 2019-12-27 11:12:46 +08:00
刘河 0b5c903d89 fix update 2019-12-27 10:59:56 +08:00
ffdfgdfg 076fc8b2e1 fine bandwidth calculation, fix slide window calculated size too large, fix #330 2019-12-27 00:32:40 +08:00
ffdfgdfg 258be8e67a add docker image latest tag 2019-12-24 22:00:17 +08:00
ffdfgdfg 346cb58613 Merge pull request #328 from cnlh/dev
Dev
2019-12-24 13:28:10 +08:00
ffdfgdfg b1384475d9 version to 0.25.3 2019-12-24 13:21:30 +08:00
ffdfgdfg 5390e965a9 Merge pull request #327 from cnlh/master
master
2019-12-24 13:07:11 +08:00
ffdfgdfg bcba0351aa add manifest 2019-12-22 22:55:27 +08:00
ffdfgdfg 8e6132077c Merge remote-tracking branch 'origin/dev' into dev 2019-12-22 19:33:59 +08:00
ffdfgdfg 7361d55e3a temporary fix android internet permission 2019-12-22 19:33:32 +08:00
ffdfgdfg eee05abaab Merge pull request #323 from zouri/dev
fix button not working on firefox
2019-12-21 16:24:30 +08:00
zouri 8224996970 fix button not working on firefox 2019-12-21 15:35:55 +08:00
he liu a2f5665fbc Update README.md 2019-12-21 11:49:35 +08:00
ffdfgdfg 231ba13e8c remove mux connection deadline 2019-12-19 22:24:58 +08:00
unknown eba8af3595 change md 2019-12-19 15:12:31 +08:00
unknown 1ab7e476a1 change md 2019-12-19 15:08:31 +08:00
刘河 453d36f658 add web protection in md 2019-12-19 01:15:18 +08:00
刘河 f253afd2fb change md 2019-12-19 00:48:39 +08:00
刘河 e9580e939b print log when run with nps 2019-12-19 00:46:22 +08:00
he liu 2faff58341 Merge pull request #318 from cnlh/master
change default log setting
2019-12-19 00:29:28 +08:00
unknown 0c08d9e202 change default log setting 2019-12-18 16:37:04 +08:00
ffdfgdfg 0559d29e74 Merge pull request #316 from cnlh/master
master to dev
2019-12-18 16:21:04 +08:00
ffdfgdfg 726be1cba0 Update build.android.sh 2019-12-18 16:07:36 +08:00
unknown bcf581b491 update md 2019-12-18 10:01:22 +08:00
he liu 897c123daa Update use.md 2019-12-18 01:14:53 +08:00
he liu 6f0ad73c23 Update _sidebar.md 2019-12-18 00:26:59 +08:00
he liu a7a52ea85c Update use.md 2019-12-17 22:18:50 +08:00
he liu 7330f9f728 Update use.md 2019-12-17 22:17:06 +08:00
27 changed files with 297 additions and 56 deletions
+13 -1
View File
@@ -3,6 +3,7 @@
![](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)
![GitHub All Releases](https://img.shields.io/github/downloads/cnlh/nps/total)
nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务器。目前支持**tcp、udp流量转发**,可支持任何**tcp、udp**上层协议(访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析等等……),此外还**支持内网http代理、内网socks5代理**、**p2p等**,并带有功能强大的web管理端。
@@ -19,7 +20,18 @@ nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务
4. 在外网使用HTTP代理访问内网站点----> http代理模式
5. 搭建一个内网穿透ss,在外网如同使用内网vpn一样访问内网资源或者设备----> socks5代理模式
## 特点
- 协议支持全面,兼容几乎所有常用协议,例如tcp、udp、http(s)、socks5、p2p、http代理...
- 全平台兼容(linux、windows、macos、群辉等),支持一键安装为系统服务
- 控制全面,同时支持服务端和客户端控制
- https集成,支持将后端代理和web服务转成https,同时支持多证书
- 操作简单,只需简单的配置即可在web ui上完成其余操作
- 展示信息全面,流量、系统信息、即时带宽、客户端版本等
- 扩展功能强大,该有的都有了(缓存、压缩、加密、流量限制、带宽限制、端口复用等等)
- 域名解析具备自定义header、404页面配置、host修改、站点保护、URL路由、泛解析等功能
- 服务端支持多用户和用户注册功能
**没找到你想要的功能?不要紧,点击[进入文档](https://cnlh.github.io/nps/)查找吧**
## 快速开始
### 安装
@@ -42,7 +54,7 @@ nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务
对于windows,管理员身份运行cmd,进入程序目录 ```nps.exe start```
停止和重启可用,stop和restart
```安装后windows配置文件位于 C:\Program Files\nps,linux和darwin位于/etc/nps```
**如果发现没有启动成功,可以查看日志(Windows日志文件位于当前运行目录下,linux和darwin位于/var/log/nps.log)**
- 访问服务端ip:web服务端口(默认为8080)
+25 -3
View File
@@ -3,15 +3,37 @@
#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
#fyne package -os android fyne.io/fyne/cmd/hello
echo "fyne install success"
mkdir -p /go/src/github.com/cnlh/nps
cp -R * /go/src/github.com/cnlh/nps
cp -R /app/* /go/src/github.com/cnlh/nps
cd /go/src/github.com/cnlh/nps
#go get -u fyne.io/fyne fyne.io/fyne/cmd/fyne
rm cmd/npc/sdk.go
#go get -u ./...
#go mod tidy
#rm -rf /go/src/golang.org/x/mobile
echo "tidy success"
cd /go/src/github.com/cnlh/nps
go get -u fyne.io/fyne fyne.io/fyne/cmd/fyne
go mod vendor
cd vendor
cp -R * /go/src
cd ..
rm -rf vendor
#rm -rf ~/.cache/*
echo "vendor success"
cd gui/npc
fyne package -os android -appID org.nps.client -icon ../../docs/logo.png
#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
+3 -3
View File
@@ -1,5 +1,5 @@
#/bash/sh
export VERSION=0.25.2
export VERSION=0.25.4
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
@@ -175,5 +175,5 @@ echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
export DOCKER_CLI_EXPERIMENTAL=enabled
docker run --rm --privileged docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
docker buildx create --use --name mybuilder
docker buildx build --tag ffdfgdfg/nps:$VERSION --output type=image,push=true --file Dockerfile.nps --platform=linux/amd64,linux/arm64,linux/386,linux/arm .
docker buildx build --tag ffdfgdfg/npc:$VERSION --output type=image,push=true --file Dockerfile.npc --platform=linux/amd64,linux/arm64,linux/386,linux/arm .
docker buildx build --tag ffdfgdfg/nps:$VERSION --tag ffdfgdfg/nps:latest --output type=image,push=true --file Dockerfile.nps --platform=linux/amd64,linux/arm64,linux/386,linux/arm .
docker buildx build --tag ffdfgdfg/npc:$VERSION --tag ffdfgdfg/npc:latest --output type=image,push=true --file Dockerfile.npc --platform=linux/amd64,linux/arm64,linux/386,linux/arm .
+2
View File
@@ -108,6 +108,8 @@ func main() {
os.Exit(0)
case "install", "start", "stop", "uninstall", "restart":
if os.Args[1] == "install" {
service.Control(s, "stop")
service.Control(s, "uninstall")
install.InstallNpc()
}
err := service.Control(s, os.Args[1])
+9 -6
View File
@@ -25,8 +25,7 @@ import (
)
var (
level string
logType = flag.String("log", "stdout", "Log output mode(stdout|file)")
level string
)
func main() {
@@ -48,7 +47,6 @@ func main() {
if common.IsWindows() {
logPath = strings.Replace(logPath, "\\", "\\\\", -1)
}
logs.SetLogger(logs.AdapterFile, `{"level":`+level+`,"filename":"`+logPath+`","daily":false,"maxlines":100000,"color":true}`)
// init service
options := make(service.KeyValue)
options["Restart"] = "on-success"
@@ -59,6 +57,12 @@ func main() {
Description: "一款轻量级、功能强大的内网穿透代理服务器。支持tcp、udp流量转发,支持内网http代理、内网socks5代理,同时支持snappy压缩、站点保护、加密传输、多路复用、header修改等。支持web图形化管理,集成多用户模式。",
Option: options,
}
svcConfig.Arguments = append(svcConfig.Arguments, "service")
if len(os.Args) > 1 && os.Args[1] == "service" {
logs.SetLogger(logs.AdapterFile, `{"level":`+level+`,"filename":"`+logPath+`","daily":false,"maxlines":100000,"color":true}`)
} else {
logs.SetLogger(logs.AdapterConsole, `{"level":`+level+`,"color":true}`)
}
if !common.IsWindows() {
svcConfig.Dependencies = []string{
"Requires=network.target",
@@ -71,15 +75,14 @@ func main() {
logs.Error(err)
return
}
if len(os.Args) > 1 {
if len(os.Args) > 1 && os.Args[1] != "service" {
switch os.Args[1] {
case "debug":
logs.SetLogger(logs.AdapterConsole, `{"level":`+level+`,"color":true}`)
case "reload":
daemon.InitDaemon("nps", common.GetRunPath(), common.GetTmpPath())
return
case "install":
// uninstall before
service.Control(s, "stop")
service.Control(s, "uninstall")
binPath := install.InstallNps()
+7 -5
View File
@@ -1,13 +1,15 @@
![logo](logo.svg)
# NPS <small>0.25.1</small>
# NPS <small>0.25.4</small>
> 一款轻量级、高性能、功能强大的内网穿透代理服务器
- 支持tcp、udp流量转发
- 支持内网http代理、内网socks5代理、p2p
- 简洁方便的WEB管理界面
- 服务端控制
- 几乎支持所有协议
- 支持内网http代理、内网socks5代理、p2p等
- 简洁但功能强大的WEB管理界面
- 支持服务端、客户端同时控制
- 扩展功能强大
- 全平台兼容,一键注册为服务
[GitHub](https://github.com/cnlh/nps/)
+1 -1
View File
@@ -19,7 +19,7 @@
* [说明](description.md)
* [web api](api.md)
* [sdk](npc_sdk.md)
git
* 其他
* [贡献](contribute.md)
+3
View File
@@ -8,6 +8,9 @@
## 热更新支持
对于绝大多数配置,在web管理中的修改将实时使用,无需重启客户端或者服务端
## web端保护
在一分钟内,如果密码错误次数超过10次,该ip在一分钟内将不能再次登陆。
## 客户端地址显示
在web管理中将显示客户端的连接地址
+3 -1
View File
@@ -40,4 +40,6 @@
nps-update.exe update
```
更新完成后,执行执行`sudo nps start`或者`nps.exe start`重新运行即可完成升级
更新完成后,执行执行`sudo nps start`或者`nps.exe start`重新运行即可完成升级
如果无法更新成功,可以直接自行下载releases压缩包然后覆盖原有的nps二进制文件和web目录
+3 -1
View File
@@ -14,9 +14,11 @@
对于windows,管理员身份运行cmd,进入程序目录 ```nps.exe start```
```安装后windows配置文件位于 C:\Program Files\nps,linux和darwin位于/etc/nps```
停止和重启可用,stop和restart
**如果发现没有启动成功,可以使用`nps(.exe) debug`运行调试,或查看日志**(Windows日志文件位于当前运行目录下,linux和darwin位于/var/log/nps.log)
**如果发现没有启动成功,可以使用`nps(.exe) stop`,然后运行`nps.(exe)`运行调试,或查看日志**(Windows日志文件位于当前运行目录下,linux和darwin位于/var/log/nps.log)
- 访问服务端ip:web服务端口(默认为8080)
- 使用用户名和密码登陆(默认admin/123,正式使用一定要更改)
- 创建客户端
+11 -9
View File
@@ -2,39 +2,41 @@
## 无配置文件模式
此模式的各种配置在服务端web管理中完成,客户端除运行一条命令外无需任何其他设置
```
./npc -debug=true -server=ip:port -vkey=web界面中显示的密钥
./npc -server=ip:port -vkey=web界面中显示的密钥
```
## 注册到系统服务
## 注册到系统服务(开机启动、守护进程)
对于linux、darwin
- 注册:`sudo ./npc install 其他参数(例如-server=xx -vkey=xx或者-config=xxx)`
- 启动:`sudo ./npc start`
- 停止:`sudo ./npc stop`
- 如果需要更换命令内容需要先卸载`./npc -service=uninstall`,再重新注册
- 启动:`sudo npc start`
- 停止:`sudo npc stop`
- 如果需要更换命令内容需要先卸载`./npc uninstall`,再重新注册
对于windows,使用管理员身份运行cmd
- 注册:`npc.exe install 其他参数(例如-server=xx -vkey=xx或者-config=xxx)`
- 启动:`npc.exe start`
- 停止:`npc.exe stop`
- 如果需要更换命令内容需要先卸载`npc.exe -service=uninstall`,再重新注册
- 如果需要更换命令内容需要先卸载`npc.exe uninstall`,再重新注册
注册到服务后,日志文件windows位于当前目录下,linux和darwin位于/var/log/npc.log
## 客户端更新
首先进入到对于的客户端二进制文件目录
请首先执行`sudo ./npc stop`或者`nps.exe stop`停止运行,然后
请首先执行`sudo npc stop`或者`npc.exe stop`停止运行,然后
对于linux
```shell
sudo ./npc-update update
sudo npc-update update
```
对于windows
```shell
npc-update.exe update
```
更新完成后,执行执行`sudo nps start`或者`nps.exe start`重新运行即可完成升级
更新完成后,执行执行`sudo npc start`或者`npc.exe start`重新运行即可完成升级
如果无法更新成功,可以直接自行下载releases压缩包然后覆盖原有的npc二进制文件
## 配置文件模式
此模式使用nps的公钥或者客户端私钥验证,各种配置在客户端完成,同时服务端web也可以进行管理
+37
View File
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="0.25.4"
package="org.nps.client"
platformBuildVersionCode="15"
platformBuildVersionName="4.0.4-1406430">
<uses-permission
android:name="android.permission.INTERNET"/>
<application
android:label="Npc"
android:debuggable="true">
<activity
android:label="Npc"
android:name="org.golang.app.GoNativeActivity"
android:configChanges="0xa0">
<meta-data
android:name="android.app.lib_name"
android:value="npc"/>
<intent-filter>
<action
android:name="android.intent.action.MAIN"/>
<category
android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
+9
View File
@@ -246,6 +246,15 @@ func (Self *MuxPackager) UnPack(reader io.Reader) (n uint16, err error) {
return
}
func (Self *MuxPackager) reset() {
Self.Id = 0
Self.Flag = 0
Self.Length = 0
Self.Content = nil
Self.ReadLength = 0
Self.Window = 0
}
const (
ipV4 = 1
domainName = 3
+6 -3
View File
@@ -93,18 +93,20 @@ type windowBufferPool struct {
func (Self *windowBufferPool) New() {
Self.pool = sync.Pool{
New: func() interface{} {
return make([]byte, PoolSizeWindow, PoolSizeWindow)
return make([]byte, PoolSizeWindow)
},
}
}
func (Self *windowBufferPool) Get() (buf []byte) {
buf = Self.pool.Get().([]byte)
return buf[:PoolSizeWindow]
buf = buf[:PoolSizeWindow]
return buf
}
func (Self *windowBufferPool) Put(x []byte) {
Self.pool.Put(x[:PoolSizeWindow]) // make buf to full
x = x[:0] // clean buf
Self.pool.Put(x)
}
type bufferPool struct {
@@ -146,6 +148,7 @@ func (Self *muxPackagerPool) Get() *MuxPackager {
}
func (Self *muxPackagerPool) Put(pack *MuxPackager) {
pack.reset()
Self.pool.Put(pack)
}
+4 -2
View File
@@ -91,11 +91,13 @@ func copyStaticFile(srcPath, bin string) string {
if _, err := copyFile(filepath.Join(srcPath, bin), "/usr/local/bin/"+bin); err != nil {
log.Fatalln(err)
} else {
copyFile(filepath.Join(srcPath, "nps"), "/usr/local/bin/"+bin+"-update")
copyFile(filepath.Join(srcPath, bin), "/usr/local/bin/"+bin+"-update")
chMod("/usr/local/bin/"+bin+"-update", 0755)
binPath = "/usr/local/bin/" + bin
}
} else {
copyFile(filepath.Join(srcPath, "nps"), "/usr/bin/"+bin+"-update")
copyFile(filepath.Join(srcPath, bin), "/usr/bin/"+bin+"-update")
chMod("/usr/bin/"+bin+"-update", 0755)
binPath = "/usr/bin/" + bin
}
} else {
+20 -5
View File
@@ -2,6 +2,7 @@ package mux
import (
"errors"
"github.com/astaxie/beego/logs"
"io"
"math"
"net"
@@ -215,10 +216,10 @@ func (Self *ReceiveWindow) calcSize() {
if n < common.MAXIMUM_SEGMENT_SIZE*10 {
n = common.MAXIMUM_SEGMENT_SIZE * 10
}
bufLen := Self.bufQueue.Len()
if n < bufLen {
n = bufLen
}
//bufLen := Self.bufQueue.Len()
//if n < bufLen {
// n = bufLen
//}
if n < Self.maxSize/2 {
n = Self.maxSize / 2
}
@@ -227,6 +228,7 @@ func (Self *ReceiveWindow) calcSize() {
n = 2 * Self.maxSize
}
if n > (common.MAXIMUM_WINDOW_SIZE / uint32(conns)) {
logs.Warn("window too large", n)
n = common.MAXIMUM_WINDOW_SIZE / uint32(conns)
}
// set the maximum size
@@ -444,7 +446,20 @@ func (Self *SendWindow) allow() {
}
func (Self *SendWindow) sent(sentSize uint32) {
atomic.AddUint64(&Self.remainingWait, ^(uint64(sentSize)<<dequeueBits - 1))
var remaining, wait uint32
for {
ptrs := atomic.LoadUint64(&Self.remainingWait)
remaining, wait = Self.unpack(ptrs)
if remaining >= sentSize {
atomic.AddUint64(&Self.remainingWait, ^(uint64(sentSize)<<dequeueBits - 1))
break
} else {
if atomic.CompareAndSwapUint64(&Self.remainingWait, ptrs, Self.pack(0, wait)) {
// just keep the wait status, it will be wait in the next loop
break
}
}
}
}
func (Self *SendWindow) WriteTo() (p []byte, sendSize uint32, part bool, err error) {
+31 -5
View File
@@ -5,6 +5,7 @@ import (
"io"
"math"
"net"
"os"
"sync/atomic"
"time"
@@ -34,13 +35,18 @@ type Mux struct {
func NewMux(c net.Conn, connType string) *Mux {
//c.(*net.TCPConn).SetReadBuffer(0)
//c.(*net.TCPConn).SetWriteBuffer(0)
_ = c.SetDeadline(time.Time{})
fd, err := getConnFd(c)
if err != nil {
logs.Warn(err)
}
m := &Mux{
conn: c,
connMap: NewConnMap(),
id: 0,
closeChan: make(chan struct{}, 1),
newConnCh: make(chan *conn),
bw: new(bandwidth),
bw: NewBandwidth(fd),
IsClose: false,
connType: connType,
pingCh: make(chan []byte),
@@ -173,7 +179,7 @@ func (s *Mux) ping() {
s.sendInfo(common.MUX_PING_FLAG, common.MUX_PING, now)
// send the ping flag and get the latency first
ticker := time.NewTicker(time.Second * 5)
defer ticker.Stop()
defer ticker.Stop()
for {
if s.IsClose {
break
@@ -198,7 +204,7 @@ func (s *Mux) ping() {
}
atomic.AddUint32(&s.pingOk, 1)
}
return
return
}()
}
@@ -391,13 +397,19 @@ type bandwidth struct {
readStart time.Time
lastReadStart time.Time
bufLength uint32
fd *os.File
calcThreshold uint32
}
func NewBandwidth(fd *os.File) *bandwidth {
return &bandwidth{fd: fd}
}
func (Self *bandwidth) StartRead() {
if Self.readStart.IsZero() {
Self.readStart = time.Now()
}
if Self.bufLength >= common.MAXIMUM_SEGMENT_SIZE*300 {
if Self.bufLength >= Self.calcThreshold {
Self.lastReadStart, Self.readStart = Self.readStart, time.Now()
Self.calcBandWidth()
}
@@ -409,7 +421,21 @@ func (Self *bandwidth) SetCopySize(n uint16) {
func (Self *bandwidth) calcBandWidth() {
t := Self.readStart.Sub(Self.lastReadStart)
atomic.StoreUint64(&Self.readBandwidth, math.Float64bits(float64(Self.bufLength)/t.Seconds()))
bufferSize, err := sysGetSock(Self.fd)
//logs.Warn(bufferSize)
if err != nil {
logs.Warn(err)
Self.bufLength = 0
return
}
if Self.bufLength >= uint32(bufferSize) {
atomic.StoreUint64(&Self.readBandwidth, math.Float64bits(float64(Self.bufLength)/t.Seconds()))
// calculate the whole socket buffer, the time meaning to fill the buffer
//logs.Warn(Self.Get())
} else {
Self.calcThreshold = uint32(bufferSize)
}
// socket buffer size is bigger than bufLength, so we don't calculate it
Self.bufLength = 0
}
+11 -4
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/cnlh/nps/lib/common"
"github.com/cnlh/nps/lib/goroutine"
"github.com/xtaci/kcp-go"
"io"
"log"
"net"
@@ -33,7 +34,8 @@ func TestNewMux(t *testing.T) {
//poolConnCopy, _ := ants.NewPoolWithFunc(200000, common.copyConn, ants.WithNonblocking(false))
time.Sleep(time.Second * 3)
go func() {
m2 := NewMux(conn2, "tcp")
//m2 := NewMux(conn2, "tcp")
m2 := NewMux(conn2, "kcp")
for {
//logs.Warn("npc starting accept")
c, err := m2.Accept()
@@ -82,7 +84,8 @@ func TestNewMux(t *testing.T) {
}()
go func() {
m1 := NewMux(conn1, "tcp")
//m1 := NewMux(conn1, "tcp")
m1 := NewMux(conn1, "kcp")
l, err := net.Listen("tcp", "127.0.0.1:7777")
if err != nil {
logs.Warn(err)
@@ -144,12 +147,14 @@ func TestNewMux(t *testing.T) {
func server() {
var err error
l, err := net.Listen("tcp", "127.0.0.1:9999")
//l, err := net.Listen("tcp", "127.0.0.1:9999")
l, err := kcp.Listen("127.0.0.1:9999")
if err != nil {
logs.Warn(err)
}
go func() {
conn1, err = l.Accept()
logs.Info("accept", conn1)
if err != nil {
logs.Warn(err)
}
@@ -159,7 +164,9 @@ func server() {
func client() {
var err error
conn2, err = net.Dial("tcp", "127.0.0.1:9999")
//conn2, err = net.Dial("tcp", "127.0.0.1:9999")
logs.Warn("dial")
conn2, err = kcp.Dial("127.0.0.1:9999")
if err != nil {
logs.Warn(err)
}
+46
View File
@@ -0,0 +1,46 @@
// +build !windows
package mux
import (
"errors"
"github.com/xtaci/kcp-go"
"net"
"os"
"syscall"
)
func sysGetSock(fd *os.File) (bufferSize int, err error) {
if fd != nil {
return syscall.GetsockoptInt(int(fd.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
} else {
return 1400 * 320, nil
}
}
func getConnFd(c net.Conn) (fd *os.File, err error) {
switch c.(type) {
case *net.TCPConn:
fd, err = c.(*net.TCPConn).File()
if err != nil {
return
}
return
case *net.UDPConn:
fd, err = c.(*net.UDPConn).File()
if err != nil {
return
}
return
case *kcp.UDPSession:
//fd, err = (*net.UDPConn)(unsafe.Pointer(c.(*kcp.UDPSession))).File()
//if err != nil {
// return
//}
// Todo
return
default:
err = errors.New("mux:unknown conn type, only tcp or kcp")
return
}
}
+46
View File
@@ -0,0 +1,46 @@
// +build windows
package mux
import (
"errors"
"github.com/xtaci/kcp-go"
"net"
"os"
)
func sysGetSock(fd *os.File) (bufferSize int, err error) {
// https://github.com/golang/sys/blob/master/windows/syscall_windows.go#L1184
// not support, WTF???
// Todo
// return syscall.GetsockoptInt((syscall.Handle)(unsafe.Pointer(fd.Fd())), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
bufferSize = 10 * 1024 * 1024
return
}
func getConnFd(c net.Conn) (fd *os.File, err error) {
switch c.(type) {
case *net.TCPConn:
//fd, err = c.(*net.TCPConn).File()
//if err != nil {
// return
//}
return
case *net.UDPConn:
//fd, err = c.(*net.UDPConn).File()
//if err != nil {
// return
//}
return
case *kcp.UDPSession:
//fd, err = (*net.UDPConn)(unsafe.Pointer(c.(*kcp.UDPSession))).File()
//if err != nil {
// return
//}
// Todo
return
default:
err = errors.New("mux:unknown conn type, only tcp or kcp")
return
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
package version
const VERSION = "0.25.2"
const VERSION = "0.25.4"
// Compulsory minimum version, Minimum downward compatibility to this version
func GetVersion() string {
+1 -1
View File
@@ -119,7 +119,7 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-success" href="#" id="add"><i
<button class="btn btn-success" type="button" id="add"><i
class="fa fa-fw fa-lg fa-eye"></i>新增
</button>
</div>
+1 -1
View File
@@ -128,7 +128,7 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-success" href="#" id="add"><i
<button class="btn btn-success" type="button" id="add"><i
class="fa fa-fw fa-lg fa-eye"></i><span langtag="info-save">保存</span>
</button>
</div>
+1 -1
View File
@@ -101,7 +101,7 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
&nbsp;<button class="btn btn-success" href="#" id="add"><i
&nbsp;<button class="btn btn-success" type="button" id="add"><i
class="fa fa-fw fa-lg fa-eye"></i>新增
</button>
</div>
+1 -1
View File
@@ -101,7 +101,7 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-success" href="#" id="add"><i
<button class="btn btn-success" type="button" id="add"><i
class="fa fa-fw fa-lg fa-eye"></i><span langtag="info-save">保存</span>
</button>
</div>
+1 -1
View File
@@ -97,7 +97,7 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
&nbsp;<button class="btn btn-success" href="#" id="add"><i
&nbsp;<button class="btn btn-success" type="button" id="add"><i
class="fa fa-fw fa-lg fa-eye"></i>新增
</button>
</div>
+1 -1
View File
@@ -100,7 +100,7 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
&nbsp;<button class="btn btn-success" href="#" id="add"><i
&nbsp;<button class="btn btn-success" type="button" id="add"><i
class="fa fa-fw fa-lg fa-eye"></i><span langtag="info-save">保存</span>
</button>
</div>