[反向代理]实验性添加TOA支持

This commit is contained in:
刘祥超
2020-12-03 10:16:45 +08:00
parent c282347e36
commit 15bd634280
2 changed files with 44 additions and 1 deletions

View File

@@ -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
}

View File

@@ -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)