网关重启时恢复权限与分配数据

This commit is contained in:
2025-05-26 10:55:44 +08:00
parent 52907b3fae
commit 8c928a8321
5 changed files with 18 additions and 8 deletions

View File

@@ -1,3 +1,7 @@
## TODO
- 连接断开时尽量由
## 开发相关
### 目录结构

View File

@@ -8,3 +8,8 @@ type Permit struct {
Username *string `json:"username"`
Password *string `json:"password"`
}
type PermitDef struct {
Id int32 `json:"id"`
Permit
}

View File

@@ -103,7 +103,7 @@ func processCtrlConn(_ctx context.Context, conn net.Conn) (err error) {
// 读取命令
cmd, err := reader.ReadByte()
if errors.Is(err, syscall.WSAECONNRESET) {
if errors.Is(err, syscall.ECONNRESET) || errors.Is(err, syscall.WSAECONNRESET) {
slog.Debug("节点重置了控制通道连接(WSAECONNRESET)")
return nil
}

View File

@@ -23,8 +23,9 @@ func Online(name string) (err error) {
}
var body struct {
Id int32 `json:"id"`
Secret string `json:"secret"`
Id int32 `json:"id"`
Secret string `json:"secret"`
Permits []core.PermitDef `json:"permits"`
}
err = json.Unmarshal([]byte(resp), &body)
if err != nil {
@@ -33,6 +34,9 @@ func Online(name string) (err error) {
app.Id = body.Id
app.PlatformSecret = body.Secret
for _, def := range body.Permits {
app.Permits.Store(def.Id, &def.Permit)
}
return nil
}

View File

@@ -6,10 +6,7 @@ import (
"proxy-server/gateway/core"
)
type PermitReq struct {
Id int32 `json:"id"`
core.Permit
}
type PermitReq []core.PermitDef
func Permit(ctx *fiber.Ctx) (err error) {
@@ -20,7 +17,7 @@ func Permit(ctx *fiber.Ctx) (err error) {
}
// 获取请求参数
req, err := core.Decrypt[[]PermitReq](&sec, app.PlatformSecret)
req, err := core.Decrypt[PermitReq](&sec, app.PlatformSecret)
if err != nil {
return err
}