修复通道注册失败问题

This commit is contained in:
2025-12-05 18:57:52 +08:00
parent 5649a03c47
commit 9e237be21e
6 changed files with 17 additions and 22 deletions

View File

@@ -1,12 +1,13 @@
## TODO ## TODO
考虑一个方案限制接口请求速率,无侵入更好
trade/create 性能问题,缩短事务时间,考虑其他方式实现可靠分布式事务 trade/create 性能问题,缩短事务时间,考虑其他方式实现可靠分布式事务
jsonb 类型转换问题,考虑一个高效的 any 到 struct 转换工具 jsonb 类型转换问题,考虑一个高效的 any 到 struct 转换工具
端口资源池的 gc 实现 端口资源池的 gc 实现
考虑一个方案限制接口请求速率,无侵入更好
标准化生产环境 cors 配置 标准化生产环境 cors 配置

View File

@@ -503,7 +503,7 @@ create table proxy (
secret text, secret text,
type int not null, type int not null,
status int not null, status int not null,
meta jsonb not null, meta jsonb,
created_at timestamptz default current_timestamp, created_at timestamptz default current_timestamp,
updated_at timestamptz default current_timestamp, updated_at timestamptz default current_timestamp,
deleted_at timestamptz deleted_at timestamptz

View File

@@ -1,10 +1,9 @@
package handlers package handlers
import ( import (
"log/slog"
"net/netip" "net/netip"
"platform/pkg/env" "platform/pkg/env"
g "platform/web/globals" "platform/web/core"
s "platform/web/services" s "platform/web/services"
"time" "time"
@@ -16,18 +15,9 @@ func DebugRegisterProxyBaiYin(c *fiber.Ctx) error {
return fiber.ErrNotFound return fiber.ErrNotFound
} }
ok, err := g.Redis.SetNX(c.Context(), "debug:channel:register:127.0.0.1", true, 0).Result() err := s.Proxy.RegisterBaiyin("1a:2b:3c:4d:5e:6f", netip.AddrFrom4([4]byte{127, 0, 0, 1}), "test", "test")
if err != nil { if err != nil {
return err return core.NewServErr("注册失败", err)
}
slog.Info("注册代理", "ok", ok)
if !ok {
return fiber.ErrConflict
}
err = s.Proxy.RegisterBaiyin("1a:2b:3c:4d:5e:6f", netip.AddrFrom4([4]byte{127, 0, 0, 1}), "test", "test")
if err != nil {
return err
} }
return nil return nil

View File

@@ -73,11 +73,11 @@ func ApplyRouters(app *fiber.App) {
edge.Post("/assign", handlers.AssignEdge) edge.Post("/assign", handlers.AssignEdge)
edge.Post("/all", handlers.AllEdgesAvailable) edge.Post("/all", handlers.AllEdgesAvailable)
callbacks := app.Group("/callback")
callbacks.Get("/identify", handlers.IdentifyCallbackNew)
// 临时 // 临时
debug := app.Group("/debug") debug := app.Group("/debug")
debug.Get("/sms/:phone", handlers.DebugGetSmsCode) debug.Get("/sms/:phone", handlers.DebugGetSmsCode)
debug.Get("/proxy/register", handlers.DebugRegisterProxyBaiYin) debug.Get("/proxy/register", handlers.DebugRegisterProxyBaiYin)
callbacks := app.Group("/callback")
callbacks.Get("/identify", handlers.IdentifyCallbackNew)
} }

View File

@@ -261,8 +261,12 @@ local free_key = KEYS[1]
local all_key = KEYS[2] local all_key = KEYS[2]
local chans = ARGV local chans = ARGV
redis.call("SADD", free_key, unpack(chans)) local batch_size = 5000
redis.call("SADD", all_key, unpack(chans)) for i = 1, #chans, batch_size do
local end_index = math.min(i + batch_size - 1, #chans)
redis.call("SADD", free_key, unpack(chans, i, end_index))
redis.call("SADD", all_key, unpack(chans, i, end_index))
end
return 1 return 1
` `

View File

@@ -40,7 +40,7 @@ func (s *proxyService) RegisterBaiyin(Mac string, IP netip.Addr, username, passw
} }
err := addChans(chans) err := addChans(chans)
if err != nil { if err != nil {
return core.NewServErr("添加通道失败") return core.NewServErr("添加通道失败", err)
} }
// 保存代理信息 // 保存代理信息