Compare commits

..

6 Commits

Author SHA1 Message Date
刘祥超
4a11ecb7b4 修复一处编译问题 2023-07-25 14:08:26 +08:00
刘祥超
5c8dff120a 增加 DefaultTCPLinger 值 2023-07-25 09:35:28 +08:00
刘祥超
df148bf027 删除TOA相关不需要的内容 2023-07-24 15:33:30 +08:00
刘祥超
d5bb623339 优化TOA相关API 2023-07-24 09:56:49 +08:00
刘祥超
58ec21d676 优化HTTP报头策略是否为空的判断 2023-07-22 15:00:15 +08:00
刘祥超
279e4025fd 默认自动检查版本更新 2023-07-20 09:37:47 +08:00
8 changed files with 716 additions and 731 deletions

View File

@@ -3154,7 +3154,10 @@
"responseMessageName": "RPCSuccess",
"code": "rpc updateHTTPWebOptimization(UpdateHTTPWebOptimizationRequest) returns (RPCSuccess);",
"doc": "更改页面优化配置",
"roles": [],
"roles": [
"admin",
"user"
],
"isDeprecated": false
},
{
@@ -5720,6 +5723,17 @@
"admin"
],
"isDeprecated": false
},
{
"name": "findNodeTOAConfig",
"requestMessageName": "FindNodeTOAConfigRequest",
"responseMessageName": "FindNodeTOAConfigResponse",
"code": "rpc findNodeTOAConfig(FindNodeTOAConfigRequest) returns (FindNodeTOAConfigResponse);",
"doc": "查找节点的TOA配置",
"roles": [
"node"
],
"isDeprecated": false
}
],
"filename": "service_node.proto",
@@ -14045,12 +14059,12 @@
},
{
"name": "CopyNodeActionsToNodeClusterRequest",
"code": "message CopyNodeActionsToNodeClusterRequest {\n\tint64 nodeId = 1;\n}",
"code": "message CopyNodeActionsToNodeClusterRequest {\n\tint64 nodeId = 1; // 节点ID\n}",
"doc": "同步动作设置到集群"
},
{
"name": "CopyNodeActionsToNodeGroupRequest",
"code": "message CopyNodeActionsToNodeGroupRequest {\n\tint64 nodeId = 1;\n}",
"code": "message CopyNodeActionsToNodeGroupRequest {\n\tint64 nodeId = 1; // 节点ID\n}",
"doc": "同步动作设置到分组"
},
{
@@ -19273,31 +19287,16 @@
"code": "message FindNodeGlobalServerConfigResponse {\n\tbytes globalServerConfigJSON = 1;\n}",
"doc": ""
},
{
"name": "FindNodeHTTP3PoliciesRequest",
"code": "message FindNodeHTTP3PoliciesRequest {\n\tint64 nodeId = 1; // 节点ID\n}",
"doc": "查找节点的HTTP3策略"
},
{
"name": "FindNodeHTTP3PoliciesResponse",
"code": "message FindNodeHTTP3PoliciesResponse {\n\trepeated HTTP3Policy http3Policies = 1; // HTTP3策略列表\n\n\n\tmessage HTTP3Policy {\n\t\tint64 nodeClusterId = 1; // 集群ID\n\t\tbytes http3PolicyJSON = 2; // HTTP3策略配置\n\t}\n}",
"doc": ""
},
{
"name": "FindNodeHTTPCCPoliciesRequest",
"code": "message FindNodeHTTPCCPoliciesRequest {\n\tint64 nodeId = 1; // 节点ID\n}",
"doc": "查找节点的HTTP CC策略"
},
{
"name": "FindNodeHTTPCCPoliciesResponse",
"code": "message FindNodeHTTPCCPoliciesResponse {\n\trepeated HTTPCCPolicy httpCCPolicies = 1; // HTTP CC策略列表\n\n\n\tmessage HTTPCCPolicy {\n\t\tint64 nodeClusterId = 1; // 集群ID\n\t\tbytes httpCCPolicyJSON = 2; // HTTP CC策略配置\n\t}\n}",
"doc": ""
},
{
"name": "FindNodeHTTPPagesPoliciesRequest",
"code": "message FindNodeHTTPPagesPoliciesRequest {\n\tint64 nodeId = 1; // 节点ID\n}",
"doc": "查找节点的自定义页面策略"
},
{
"name": "FindNodeHTTPPagesPoliciesResponse",
"code": "message FindNodeHTTPPagesPoliciesResponse {\n\trepeated HTTPPagesPolicy httpPagesPolicies = 1; // 自定义页面策略列表\n\n\n\tmessage HTTPPagesPolicy {\n\t\tint64 nodeClusterId = 1; // 集群ID\n\t\tbytes httpPagesPolicyJSON = 2; // 自定义页面策略配置\n\t}\n}",
@@ -19338,6 +19337,11 @@
"code": "message FindNodeScheduleInfoResponse {\n\tScheduleInfo scheduleInfo = 1; // 调度信息\n\n\n\tmessage ScheduleInfo {\n\t\tstring offlineDay = 1; // 下线日期格式YYYYMMDD\n\t\tbool isBackupForCluster = 2; // 是否为集群备份节点\n\t\tbool isBackupForGroup = 3; // 是否为分组备份节点\n\t\trepeated string backupIPs = 4; // 备用IP\n\t\tbytes actionStatusJSON = 5; // 动作状态\n\t}\n}",
"doc": ""
},
{
"name": "FindNodeTOAConfigResponse",
"code": "message FindNodeTOAConfigResponse {\n\tbytes toaJSON = 1; // TOA配置\n}",
"doc": ""
},
{
"name": "FindNodeTasksRequest",
"code": "message FindNodeTasksRequest {\n\tint64 version = 1; // 上一次执行的版本\n}",
@@ -19348,11 +19352,6 @@
"code": "message FindNodeTasksResponse {\n\trepeated NodeTask nodeTasks = 1;\n}",
"doc": ""
},
{
"name": "FindNodeUAMPoliciesRequest",
"code": "message FindNodeUAMPoliciesRequest {\n\tint64 nodeId = 1; // 节点ID\n}",
"doc": "查找节点的UAM策略"
},
{
"name": "FindNodeUAMPoliciesResponse",
"code": "message FindNodeUAMPoliciesResponse {\n\trepeated UAMPolicy uamPolicies = 1; // UAM策略列表\n\n\n\tmessage UAMPolicy {\n\t\tint64 nodeClusterId = 1; // 集群ID\n\t\tbytes uamPolicyJSON = 2; // UAM策略配置\n\t}\n}",

View File

@@ -22,7 +22,7 @@ const (
DefaultTCPNewConnectionsSecondlyRate = 300 // 单IP连接速率限制按秒
DefaultTCPNewConnectionsMinSecondlyRate = 3 // 单IP最小连接速率
DefaultTCPLinger = 3 // 单节点TCP Linger值
DefaultTCPLinger = 5 // 单节点TCP Linger值
DefaultTLSHandshakeTimeout = 3 // TLS握手超时时间
)

View File

@@ -1,93 +1,22 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build !plus
package nodeconfigs
import (
"fmt"
"github.com/iwind/TeaGo/rands"
"net"
)
// 默认的TOA配置
func DefaultTOAConfig() *TOAConfig {
return &TOAConfig{
IsOn: false,
Debug: false,
OptionType: 0xfe,
MinQueueId: 100,
MaxQueueId: 109,
AutoSetup: true,
}
// NewTOAConfig 默认的TOA配置
func NewTOAConfig() *TOAConfig {
return &TOAConfig{}
}
// TOA相关配置
// TOAConfig TOA相关配置
type TOAConfig struct {
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
Debug bool `yaml:"debug" json:"debug"`
OptionType uint8 `yaml:"optionType" json:"optionType"`
MinQueueId uint8 `yaml:"minQueueId" json:"minQueueId"`
MaxQueueId uint8 `yaml:"maxQueueId" json:"maxQueueId"`
AutoSetup bool `yaml:"autoSetup" json:"autoSetup"`
MinLocalPort uint16 `yaml:"minLocalPort" json:"minLocalPort"` // 本地可使用的最小端口 TODO
MaxLocalPort uint16 `yaml:"maxLocalPort" json:"maxLocalPort"` // 本地可使用的最大端口 TODO
SockPath string `yaml:"sockPath" json:"sockPath"` // Sock文件路径 TODO
ByPassPorts []uint16 `yaml:"byPassPorts" json:"byPassPorts"` // 忽略的端口 TODO
minLocalPort int
maxLocalPort int
IsOn bool `yaml:"isOn" json:"isOn"`
}
func (this *TOAConfig) Init() error {
// LocalPort
minPort := this.MinLocalPort
maxPort := this.MaxLocalPort
if minPort == 0 {
minPort = 1025
}
if maxPort == 0 {
maxPort = 65534
}
if minPort > maxPort {
minPort, maxPort = maxPort, minPort
}
this.minLocalPort = int(minPort)
this.maxLocalPort = int(maxPort)
// QueueId
if this.MinQueueId > this.MaxQueueId {
this.MinQueueId, this.MaxQueueId = this.MaxQueueId, this.MinQueueId
}
return nil
}
// Sock路径
func (this *TOAConfig) SockFile() string {
if len(this.SockPath) == 0 {
return "/tmp/edge-toa.sock"
}
return this.SockPath
}
// 获取随机端口
func (this *TOAConfig) RandLocalPort() uint16 {
listener, err := net.Listen("tcp", ":0")
if err != nil {
return uint16(rands.Int(this.minLocalPort, this.maxLocalPort))
}
_ = listener.Close()
return uint16(listener.Addr().(*net.TCPAddr).Port)
}
// 转换为参数的形式
func (this *TOAConfig) AsArgs() (args []string) {
args = append(args, "run")
args = append(args, "-option-type="+fmt.Sprintf("%d", this.OptionType))
args = append(args, "-min-queue-id="+fmt.Sprintf("%d", this.MinQueueId))
args = append(args, "-max-queue-id="+fmt.Sprintf("%d", this.MaxQueueId))
if this.AutoSetup {
args = append(args, "-auto-setup")
}
if this.Debug {
args = append(args, "-debug")
}
return
return 0
}

View File

@@ -1,77 +0,0 @@
package nodeconfigs
import (
"net"
"runtime"
"testing"
"time"
)
func TestTOAConfig_RandLocalPort(t *testing.T) {
{
toa := &TOAConfig{}
err := toa.Init()
if err != nil {
t.Fatal(err)
}
t.Log(toa.RandLocalPort())
}
{
toa := &TOAConfig{
MinLocalPort: 1,
MaxLocalPort: 2,
}
err := toa.Init()
if err != nil {
t.Fatal(err)
}
t.Log(toa.RandLocalPort())
}
}
func TestTOAConfig_FreePort(t *testing.T) {
before := time.Now()
listener, err := net.Listen("tcp", ":0")
if err != nil {
t.Fatal(err)
}
t.Log(listener.Addr())
_ = listener.Close()
t.Log(time.Since(before).Seconds()*1000, "ms")
time.Sleep(30 * time.Second)
}
func TestTOAConfig_AsArgs(t *testing.T) {
toa := &TOAConfig{
IsOn: false,
Debug: true,
OptionType: 0xfe,
MinQueueId: 10,
MaxQueueId: 20,
AutoSetup: true,
MinLocalPort: 0,
MaxLocalPort: 0,
SockPath: "",
ByPassPorts: nil,
}
err := toa.Init()
if err != nil {
t.Fatal(err)
}
t.Log(toa.AsArgs())
}
func BenchmarkTOAConfig_RandLocalPort(b *testing.B) {
runtime.GOMAXPROCS(1)
toa := &TOAConfig{
MinLocalPort: 1,
MaxLocalPort: 2,
}
_ = toa.Init()
for i := 0; i < b.N; i++ {
_ = toa.RandLocalPort()
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -199,6 +199,9 @@ service NodeService {
// 复制动作设置到集群
rpc copyNodeActionsToNodeCluster(CopyNodeActionsToNodeClusterRequest) returns (RPCSuccess);
// 查找节点的TOA配置
rpc findNodeTOAConfig(FindNodeTOAConfigRequest) returns (FindNodeTOAConfigResponse);
}
// 创建节点
@@ -695,7 +698,6 @@ message UpdateNodeAPIConfigRequest {
// 查找节点的UAM策略
message FindNodeUAMPoliciesRequest {
int64 nodeId = 1; // 节点ID
}
message FindNodeUAMPoliciesResponse {
@@ -709,7 +711,6 @@ message FindNodeUAMPoliciesResponse {
// 查找节点的HTTP CC策略
message FindNodeHTTPCCPoliciesRequest {
int64 nodeId = 1; // 节点ID
}
message FindNodeHTTPCCPoliciesResponse {
@@ -723,7 +724,6 @@ message FindNodeHTTPCCPoliciesResponse {
// 查找节点的HTTP3策略
message FindNodeHTTP3PoliciesRequest {
int64 nodeId = 1; // 节点ID
}
message FindNodeHTTP3PoliciesResponse {
@@ -737,7 +737,6 @@ message FindNodeHTTP3PoliciesResponse {
// 查找节点的自定义页面策略
message FindNodeHTTPPagesPoliciesRequest {
int64 nodeId = 1; // 节点ID
}
message FindNodeHTTPPagesPoliciesResponse {
@@ -803,10 +802,18 @@ message FindAllNodeScheduleInfoWithNodeClusterIdResponse {
// 同步动作设置到分组
message CopyNodeActionsToNodeGroupRequest {
int64 nodeId = 1;
int64 nodeId = 1; // 节点ID
}
// 同步动作设置到集群
message CopyNodeActionsToNodeClusterRequest {
int64 nodeId = 1;
int64 nodeId = 1; // 节点ID
}
// 查找节点的TOA配置
message FindNodeTOAConfigRequest {
}
message FindNodeTOAConfigResponse {
bytes toaJSON = 1; // TOA配置
}

View File

@@ -51,7 +51,11 @@ func (this *HTTPHeaderPolicy) Init() error {
// IsEmpty 判断是否为空
func (this *HTTPHeaderPolicy) IsEmpty() bool {
return len(this.SetHeaders) == 0 && this.Expires == nil && len(this.DeleteHeaders) == 0
return len(this.SetHeaders) == 0 &&
this.Expires == nil &&
len(this.DeleteHeaders) == 0 &&
len(this.NonStandardHeaders) == 0 &&
(this.CORS == nil || !this.CORS.IsOn)
}
// ContainsHeader 判断Add和Set中是否包含某个Header

View File

@@ -9,5 +9,7 @@ type CheckUpdatesConfig struct {
}
func NewCheckUpdatesConfig() *CheckUpdatesConfig {
return &CheckUpdatesConfig{}
return &CheckUpdatesConfig{
AutoCheck: true,
}
}