mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-01-03 17:46:36 +08:00
[反向代理]实验性添加TOA支持
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package nodeconfigs
|
||||
|
||||
import "github.com/iwind/TeaGo/rands"
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/iwind/TeaGo/rands"
|
||||
)
|
||||
|
||||
// 默认的TOA配置
|
||||
func DefaultTOAConfig() *TOAConfig {
|
||||
@@ -47,6 +50,11 @@ func (this *TOAConfig) Init() error {
|
||||
this.minLocalPort = int(minPort)
|
||||
this.maxLocalPort = int(maxPort)
|
||||
|
||||
// QueueId
|
||||
if this.MinQueueId > this.MaxQueueId {
|
||||
this.MinQueueId, this.MaxQueueId = this.MaxQueueId, this.MinQueueId
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -62,3 +70,18 @@ func (this *TOAConfig) SockFile() string {
|
||||
func (this *TOAConfig) RandLocalPort() uint16 {
|
||||
return uint16(rands.Int(this.minLocalPort, this.maxLocalPort))
|
||||
}
|
||||
|
||||
// 转换为参数的形式
|
||||
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
|
||||
}
|
||||
|
||||
@@ -27,6 +27,26 @@ func TestTOAConfig_RandLocalPort(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user