- [#184](https://github.com/yisier/nps/issues/184) 限速导致隧道中断:UpdateClient 在 RateLimit=0 时创建零速率令牌桶导致永久阻塞
- [#159](https://github.com/yisier/nps/issues/159) 关闭隧道端口仍可用:StopServer 错误时提前返回未更新状态 + 重复 OpenTask case 导致隧道被自动重启 - [#170](https://github.com/yisier/nps/issues/170) TCP 负载均衡只有一个后端可达:GetRandomTarget 未处理 \r 换行符和尾部空行 - [#319](https://github.com/yisier/nps/issues/319) 客户端列表不显示实时网速:NowRate 计算逻辑错误,改为统计每秒实际消耗字节数
This commit is contained in:
@@ -38,6 +38,11 @@
|
||||
- web 静态文件打包进可执行文件:启动时若 web/static、web/views 目录不存在,自动释放内嵌资源,部署不再需要单独拷贝 web 目录
|
||||
- 精简发布包:去除打包时冗余的 conf/nps.conf、web 目录
|
||||
- 清理失效配置项:移除 appname、runmode、https_default_cert_file、https_default_key_file、https_just_proxy
|
||||
- 修复:
|
||||
- [#184](https://github.com/yisier/nps/issues/184) 限速导致隧道中断:UpdateClient 在 RateLimit=0 时创建零速率令牌桶导致永久阻塞
|
||||
- [#159](https://github.com/yisier/nps/issues/159) 关闭隧道端口仍可用:StopServer 错误时提前返回未更新状态 + 重复 OpenTask case 导致隧道被自动重启
|
||||
- [#170](https://github.com/yisier/nps/issues/170) TCP 负载均衡只有一个后端可达:GetRandomTarget 未处理 \r 换行符和尾部空行
|
||||
- [#319](https://github.com/yisier/nps/issues/319) 客户端列表不显示实时网速:NowRate 计算逻辑错误,改为统计每秒实际消耗字节数
|
||||
|
||||
- 2026-03-27 v0.26.32
|
||||
- 修复:
|
||||
|
||||
+1
-1
@@ -273,7 +273,7 @@ func (s *DbUtils) VerifyUserName(username string, id int) (res bool) {
|
||||
func (s *DbUtils) UpdateClient(t *Client) error {
|
||||
s.JsonDb.Clients.Store(t.Id, t)
|
||||
if t.RateLimit == 0 {
|
||||
t.Rate = rate.NewRate(0)
|
||||
t.Rate = rate.NewRate(int64((2 << 23) * 1024))
|
||||
t.Rate.Start()
|
||||
}
|
||||
return nil
|
||||
|
||||
+13
-7
@@ -207,22 +207,28 @@ type MultiAccount struct {
|
||||
}
|
||||
|
||||
func (s *Target) GetRandomTarget() (string, error) {
|
||||
s.Lock()
|
||||
if s.TargetArr == nil {
|
||||
s.TargetArr = strings.Split(s.TargetStr, "\n")
|
||||
}
|
||||
if len(s.TargetArr) == 1 {
|
||||
return s.TargetArr[0], nil
|
||||
arr := strings.Split(s.TargetStr, "\n")
|
||||
s.TargetArr = make([]string, 0, len(arr))
|
||||
for _, v := range arr {
|
||||
v = strings.TrimRight(v, "\r")
|
||||
if v != "" {
|
||||
s.TargetArr = append(s.TargetArr, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(s.TargetArr) == 0 {
|
||||
s.Unlock()
|
||||
return "", errors.New("all inward-bending targets are offline")
|
||||
}
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
if s.nowIndex >= len(s.TargetArr)-1 {
|
||||
s.nowIndex = -1
|
||||
}
|
||||
s.nowIndex++
|
||||
return s.TargetArr[s.nowIndex], nil
|
||||
addr := s.TargetArr[s.nowIndex]
|
||||
s.Unlock()
|
||||
return addr, nil
|
||||
}
|
||||
|
||||
type Glob struct {
|
||||
|
||||
+4
-3
@@ -2,6 +2,7 @@ package rate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
xrate "golang.org/x/time/rate"
|
||||
@@ -11,6 +12,7 @@ type Rate struct {
|
||||
limiter *xrate.Limiter
|
||||
addSize int64
|
||||
stopChan chan struct{}
|
||||
consumed int64
|
||||
NowRate int64
|
||||
}
|
||||
|
||||
@@ -19,7 +21,6 @@ func NewRate(addSize int64) *Rate {
|
||||
limiter: xrate.NewLimiter(xrate.Limit(addSize), int(addSize)),
|
||||
addSize: addSize,
|
||||
stopChan: make(chan struct{}),
|
||||
NowRate: addSize,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +31,7 @@ func (s *Rate) Start() {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
s.NowRate = s.addSize - (int64(s.limiter.Tokens()))
|
||||
s.NowRate = atomic.SwapInt64(&s.consumed, 0)
|
||||
case <-s.stopChan:
|
||||
return
|
||||
}
|
||||
@@ -55,5 +56,5 @@ func (s *Rate) Get(size int64) {
|
||||
}
|
||||
ctx := context.Background()
|
||||
_ = s.limiter.WaitN(ctx, int(size))
|
||||
s.NowRate = s.addSize - (int64(s.limiter.Tokens()))
|
||||
atomic.AddInt64(&s.consumed, size)
|
||||
}
|
||||
|
||||
+4
-11
@@ -57,7 +57,7 @@ func DealBridgeTask() {
|
||||
for {
|
||||
select {
|
||||
case t := <-Bridge.OpenTask:
|
||||
AddTask(t)
|
||||
StartTask(t.Id)
|
||||
case t := <-Bridge.CloseTask:
|
||||
StopServer(t.Id)
|
||||
case id := <-Bridge.CloseClient:
|
||||
@@ -67,8 +67,6 @@ func DealBridgeTask() {
|
||||
file.GetDb().DelClient(id)
|
||||
}
|
||||
}
|
||||
case tunnel := <-Bridge.OpenTask:
|
||||
StartTask(tunnel.Id)
|
||||
case s := <-Bridge.SecretChan:
|
||||
logs.Trace("New secret connection, addr", s.Conn.Conn.RemoteAddr())
|
||||
if t := file.GetDb().GetTaskByMd5Password(s.Password); t != nil {
|
||||
@@ -160,25 +158,20 @@ func NewMode(Bridge *bridge.Bridge, c *file.Tunnel) proxy.Service {
|
||||
|
||||
// stop server
|
||||
func StopServer(id int) error {
|
||||
//if v, ok := RunList[id]; ok {
|
||||
if v, ok := RunList.Load(id); ok {
|
||||
if svr, ok := v.(proxy.Service); ok {
|
||||
if err := svr.Close(); err != nil {
|
||||
return err
|
||||
logs.Error("stop server id %d error", id, err)
|
||||
}
|
||||
logs.Info("stop server id %d", id)
|
||||
} else {
|
||||
logs.Warn("stop server id %d error", id)
|
||||
}
|
||||
if t, err := file.GetDb().GetTask(id); err != nil {
|
||||
return err
|
||||
} else {
|
||||
RunList.Delete(id)
|
||||
if t, err := file.GetDb().GetTask(id); err == nil {
|
||||
t.Status = false
|
||||
logs.Info("close port %d,remark %s,client id %d,task id %d", t.Port, t.Remark, t.Client.Id, t.Id)
|
||||
file.GetDb().UpdateTask(t)
|
||||
}
|
||||
//delete(RunList, id)
|
||||
RunList.Delete(id)
|
||||
return nil
|
||||
}
|
||||
return errors.New("task is not running")
|
||||
|
||||
Reference in New Issue
Block a user