添加代理与节点的注册与端口分配接口功能

This commit is contained in:
2025-05-13 09:29:13 +08:00
parent 957d9ef443
commit 60df1548f0
17 changed files with 692 additions and 464 deletions

View File

@@ -211,13 +211,13 @@ func (s *channelService) CreateChannel(
protocol channel2.Protocol,
authType ChannelAuthType,
count int,
nodeFilter ...NodeFilterConfig,
edgeFilter ...EdgeFilterConfig,
) (newChannels []*m.Channel, err error) {
var now = time.Now()
var rid = ctx.Value(requestid.ConfigDefault.ContextKey).(string)
var filter = NodeFilterConfig{}
if len(nodeFilter) > 0 {
filter = nodeFilter[0]
var filter = EdgeFilterConfig{}
if len(edgeFilter) > 0 {
filter = edgeFilter[0]
}
err = q.Q.Transaction(func(q *q.Query) (err error) {
@@ -391,7 +391,7 @@ func calcChannels(
protocol channel2.Protocol,
authType ChannelAuthType,
expiration time.Time,
filter NodeFilterConfig,
filter EdgeFilterConfig,
) ([]*m.Channel, error) {
var step = time.Now()
@@ -593,8 +593,8 @@ func updateResource(rid string, resource *ResourceInfo, count int, now time.Time
func saveChannels(channels []*m.Channel) (err error) {
err = q.Channel.
Omit(
q.Channel.NodeID,
q.Channel.NodeHost,
q.Channel.EdgeID,
q.Channel.EdgeHost,
q.Channel.DeletedAt,
).
Create(channels...)

View File

@@ -6,18 +6,18 @@ import (
m "platform/web/models"
)
type NodeServiceErr string
type EdgeServiceErr string
func (e NodeServiceErr) Error() string {
func (e EdgeServiceErr) Error() string {
return string(e)
}
var Node = &nodeService{}
var Edge = &edgeService{}
type nodeService struct{}
type edgeService struct{}
func (s *nodeService) Filter(ctx context.Context, userId int32, count int, config ...NodeFilterConfig) ([]*m.Node, error) {
_config := NodeFilterConfig{}
func (s *edgeService) Filter(ctx context.Context, userId int32, count int, config ...EdgeFilterConfig) ([]*m.Edge, error) {
_config := EdgeFilterConfig{}
if len(config) > 0 {
_config = config[0]
}
@@ -25,10 +25,10 @@ func (s *nodeService) Filter(ctx context.Context, userId int32, count int, confi
// 筛选符合条件且未分配给用户过的节点
// 静态条件:省,市,运营商
// 排序方式1.分配给该用户的次数 2.分配给全部用户的次数 3.todo 节点的健康状态
var nodes []*FilteredNode
var edges []*FilteredEdge
g.DB.Raw(filterSqlRaw, userId, _config.Isp, _config.Prov, _config.City).
Limit(count).
Find(&nodes)
Find(&edges)
// todo 异步任务关闭代理
@@ -37,14 +37,14 @@ func (s *nodeService) Filter(ctx context.Context, userId int32, count int, confi
return nil, nil
}
type NodeFilterConfig struct {
type EdgeFilterConfig struct {
Isp string `json:"isp"`
Prov string `json:"prov"`
City string `json:"city"`
}
type NodeFilterAsyncTask struct {
Config NodeFilterConfig `json:"config"`
type EdgeFilterAsyncTask struct {
Config EdgeFilterConfig `json:"config"`
Count int `json:"count"`
}
@@ -62,9 +62,9 @@ select
count(c.*) as total,
count(c.*) filter ( where c.user_id = ? ) as assigned
from
node n
edge n
left join public.channel c
on n.id = c.node_id and c.expiration > now() and c.deleted_at is null
on n.id = c.edge_id and c.expiration > now() and c.deleted_at is null
where
n.isp = ? and
n.prov = ? and
@@ -75,7 +75,7 @@ order by
assigned, total
`
type FilteredNode struct {
type FilteredEdge struct {
Id int32 `json:"id"`
Name string `json:"name"`
Host string `json:"host"`