[集群]增加TOA相关设置

This commit is contained in:
刘祥超
2020-12-02 14:26:17 +08:00
parent e477c2584e
commit 806786c76e
7 changed files with 1086 additions and 629 deletions

View File

@@ -24,6 +24,9 @@ type NodeConfig struct {
// 全局配置
GlobalConfig *serverconfigs.GlobalConfig `yaml:"globalConfig" json:"globalConfig"` // 全局配置
// TOA配置
TOA *TOAConfig `yaml:"toa" json:"toa"`
paddedId string
cachePolicies []*serverconfigs.HTTPCachePolicy
firewallPolicies []*firewallconfigs.HTTPFirewallPolicy
@@ -96,6 +99,14 @@ func (this *NodeConfig) Init() error {
}
}
// TOA
if this.TOA != nil {
err := this.TOA.Init()
if err != nil {
return err
}
}
return nil
}

View File

@@ -0,0 +1,64 @@
package nodeconfigs
import "github.com/iwind/TeaGo/rands"
// 默认的TOA配置
func DefaultTOAConfig() *TOAConfig {
return &TOAConfig{
IsOn: false,
Debug: false,
OptionType: 0xfe,
MinQueueId: 100,
MaxQueueId: 109,
AutoSetup: true,
}
}
// 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
}
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)
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 {
return uint16(rands.Int(this.minLocalPort, this.maxLocalPort))
}

View File

@@ -0,0 +1,42 @@
package nodeconfigs
import (
"runtime"
"testing"
)
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 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()
}
}