|
@@ -135,6 +135,7 @@ func (service *formatterService) OldFormat(ctx context.Context, req *[]model.Gam
|
|
|
UdpSessionTimeout: UdpSessionTimeout,
|
|
|
SdkIp: v.SdkIp,
|
|
|
MaxBandwidth: MaxBandwidth,
|
|
|
+ Host: v.Host,
|
|
|
}
|
|
|
}
|
|
|
return res, nil
|
|
@@ -180,10 +181,10 @@ func (service *formatterService) TidyFormatBackendData(ctx context.Context, req
|
|
|
Type: item.Type,
|
|
|
}
|
|
|
|
|
|
- //// 设置主机名(如果存在)
|
|
|
- //if item.Host != "" {
|
|
|
- // itemMap["host"] = item.Host
|
|
|
- //}
|
|
|
+ // 设置主机名(如果存在)
|
|
|
+ if item.Protocol == "http" && item.Host != "" {
|
|
|
+ itemMap.Host = item.Host
|
|
|
+ }
|
|
|
|
|
|
// 根据协议设置不同属性
|
|
|
if protocol != "udp" {
|
|
@@ -252,13 +253,16 @@ func (service *formatterService) ValidateBackendData(ctx context.Context, data m
|
|
|
return fmt.Errorf("获取配置限制失败: %w", err)
|
|
|
}
|
|
|
|
|
|
- // 提取源机IP
|
|
|
+ // 提取源机IP和SDK端口
|
|
|
sourceIPs := make(map[string]bool)
|
|
|
ruleEntriesCount := int64(0)
|
|
|
maxBandwidthCount := int64(0)
|
|
|
|
|
|
- for _, item := range data {
|
|
|
+ // 分协议检查SDK端口
|
|
|
+ tcpHttpPorts := make(map[int]bool) // TCP和HTTP共用
|
|
|
+ udpPorts := make(map[int]bool) // UDP单独使用
|
|
|
|
|
|
+ for _, item := range data {
|
|
|
// 计算规则条目数
|
|
|
ruleEntriesCount += int64(len(item.Addr))
|
|
|
|
|
@@ -269,10 +273,30 @@ func (service *formatterService) ValidateBackendData(ctx context.Context, data m
|
|
|
sourceIPs[parts[0]] = true
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// 计算最大带宽设置数
|
|
|
if item.MaxBandwidth != "" {
|
|
|
maxBandwidthCount++
|
|
|
}
|
|
|
+
|
|
|
+ // 根据协议类型检查SDK端口重复
|
|
|
+ if item.SdkPort != 0 {
|
|
|
+ // 根据协议字段来判断SDK端口是否重复
|
|
|
+ switch strings.ToUpper(item.Protocol) {
|
|
|
+ case "TCP", "HTTP":
|
|
|
+ if tcpHttpPorts[item.SdkPort] {
|
|
|
+ return fmt.Errorf("TCP/HTTP SDK端口%d重复,每个端口只能配置一次", item.SdkPort)
|
|
|
+ }
|
|
|
+ tcpHttpPorts[item.SdkPort] = true
|
|
|
+ case "UDP":
|
|
|
+ if udpPorts[item.SdkPort] {
|
|
|
+ return fmt.Errorf("UDP SDK端口%d重复,每个端口只能配置一次", item.SdkPort)
|
|
|
+ }
|
|
|
+ udpPorts[item.SdkPort] = true
|
|
|
+ default:
|
|
|
+ return fmt.Errorf("不支持的协议类型: %s", item.Protocol)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 验证源机数量
|