添加获取所有边缘节点接口;重构相关数据结构与服务逻辑
This commit is contained in:
@@ -218,10 +218,10 @@ func (s *channelService) CreateChannel(
|
||||
protocol channel2.Protocol,
|
||||
authType ChannelAuthType,
|
||||
count int,
|
||||
edgeFilter ...EdgeFilterConfig,
|
||||
edgeFilter ...EdgeFilter,
|
||||
) (channels []*m.Channel, err error) {
|
||||
var now = time.Now()
|
||||
var filter = EdgeFilterConfig{}
|
||||
var filter = EdgeFilter{}
|
||||
if len(edgeFilter) > 0 {
|
||||
filter = edgeFilter[0]
|
||||
}
|
||||
@@ -245,7 +245,7 @@ func (s *channelService) CreateChannel(
|
||||
}
|
||||
|
||||
// 分配节点
|
||||
var config = ChannelCreateConfig{
|
||||
var config = ChannelCreator{
|
||||
Protocol: protocol,
|
||||
AuthIp: authType == ChannelAuthTypeIp,
|
||||
Whitelists: whitelist,
|
||||
@@ -397,7 +397,7 @@ func findWhitelist(q *q.Query, userId int32) ([]string, error) {
|
||||
return whitelist, nil
|
||||
}
|
||||
|
||||
func assignShortChannels(q *q.Query, userId int32, resourceId int32, count int, config ChannelCreateConfig, filter EdgeFilterConfig, now time.Time) ([]*m.Channel, error) {
|
||||
func assignShortChannels(q *q.Query, userId int32, resourceId int32, count int, config ChannelCreator, filter EdgeFilter, now time.Time) ([]*m.Channel, error) {
|
||||
|
||||
// 查找网关
|
||||
proxies, err := q.Proxy.
|
||||
@@ -594,14 +594,14 @@ func assignShortChannels(q *q.Query, userId int32, resourceId int32, count int,
|
||||
return newChannels, nil
|
||||
}
|
||||
|
||||
func assignLongChannels(q *q.Query, userId int32, resourceId int32, count int, config ChannelCreateConfig, filter EdgeFilterConfig) ([]*m.Channel, error) {
|
||||
func assignLongChannels(q *q.Query, userId int32, resourceId int32, count int, config ChannelCreator, filter EdgeFilter) ([]*m.Channel, error) {
|
||||
|
||||
// 查询符合条件的节点,根据 channel 统计使用次数
|
||||
var edges = make([]struct {
|
||||
m.Edge
|
||||
Count int
|
||||
Host string
|
||||
Secret string
|
||||
Count int
|
||||
ProxyHost string
|
||||
ProxySecret string
|
||||
}, 0)
|
||||
|
||||
do := q.Edge.Where(q.Edge.Status.Eq(1))
|
||||
@@ -621,8 +621,8 @@ func assignLongChannels(q *q.Query, userId int32, resourceId int32, count int, c
|
||||
Select(
|
||||
q.Edge.ALL,
|
||||
q.Channel.ALL.Count().As("count"),
|
||||
q.Proxy.Host,
|
||||
q.Proxy.Secret,
|
||||
q.Proxy.Host.As("proxy_host"),
|
||||
q.Proxy.Secret.As("proxy_secret"),
|
||||
).
|
||||
Group(q.Edge.ID, q.Proxy.Host, q.Proxy.Secret).
|
||||
Where(do).
|
||||
@@ -630,7 +630,7 @@ func assignLongChannels(q *q.Query, userId int32, resourceId int32, count int, c
|
||||
Limit(count).
|
||||
Scan(&edges)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("查询符合条件的节点失败: %w", err)
|
||||
}
|
||||
if len(edges) == 0 {
|
||||
return nil, ErrEdgesNoAvailable
|
||||
@@ -650,8 +650,8 @@ func assignLongChannels(q *q.Query, userId int32, resourceId int32, count int, c
|
||||
if _, ok := proxies[edge.ProxyID]; !ok {
|
||||
proxies[edge.ProxyID] = &m.Proxy{
|
||||
ID: edge.ProxyID,
|
||||
Host: edge.Host,
|
||||
Secret: edge.Secret,
|
||||
Host: edge.ProxyHost,
|
||||
Secret: edge.ProxySecret,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -674,7 +674,7 @@ func assignLongChannels(q *q.Query, userId int32, resourceId int32, count int, c
|
||||
AuthIP: config.AuthIp,
|
||||
AuthPass: config.AuthPass,
|
||||
Expiration: orm.LocalDateTime(config.Expiration),
|
||||
ProxyHost: edge.Host,
|
||||
ProxyHost: edge.ProxyHost,
|
||||
ProxyPort: edge.ProxyPort,
|
||||
}
|
||||
if config.AuthIp {
|
||||
@@ -819,7 +819,7 @@ const (
|
||||
ChannelAuthTypePass
|
||||
)
|
||||
|
||||
type ChannelCreateConfig struct {
|
||||
type ChannelCreator struct {
|
||||
Protocol channel2.Protocol
|
||||
AuthIp bool
|
||||
Whitelists []string
|
||||
@@ -827,12 +827,6 @@ type ChannelCreateConfig struct {
|
||||
Expiration time.Time
|
||||
}
|
||||
|
||||
type EdgeFilterConfig struct {
|
||||
Isp string `json:"isp"`
|
||||
Prov string `json:"prov"`
|
||||
City string `json:"city"`
|
||||
}
|
||||
|
||||
type ResourceInfo struct {
|
||||
Id int32
|
||||
Active bool
|
||||
|
||||
Reference in New Issue
Block a user