优化数据连接处理逻辑,避免数据通道连接空等待问题;授权部分添加全局白名单支持;现在节点丢失连接后不会清空授权数据
This commit is contained in:
@@ -67,7 +67,8 @@ func processUserConn(ctx context.Context, user *core.Conn, ctrl io.Writer) (err
|
||||
}
|
||||
|
||||
// 保存用户连接
|
||||
app.UserConnMap.Store(hex.EncodeToString(user.Tag[:]), user)
|
||||
var tag = hex.EncodeToString(user.Tag[:])
|
||||
app.UserConnMap.Store(tag, user)
|
||||
|
||||
// 如果限定时间内没有建立数据通道,则关闭连接
|
||||
var timeout, cancel = context.WithTimeout(context.Background(), time.Duration(env.AppDataTimeout)*time.Second)
|
||||
@@ -80,11 +81,11 @@ func processUserConn(ctx context.Context, user *core.Conn, ctrl io.Writer) (err
|
||||
err = ctx.Err()
|
||||
}
|
||||
|
||||
_, ok := app.UserConnMap.LoadAndDelete(hex.EncodeToString(user.Tag[:]))
|
||||
_, ok := app.UserConnMap.LoadAndDelete(tag)
|
||||
if ok {
|
||||
utils.Close(user)
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
slog.Error("用户连接超时", "tag", hex.EncodeToString(user.Tag[:]), "addr", user.RemoteAddr().String())
|
||||
slog.Error("用户连接超时", "tag", tag, "addr", user.RemoteAddr().String())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user