diff --git a/pkg/nodeconfigs/toa_config.go b/pkg/nodeconfigs/toa_config.go index efc1661..65afe34 100644 --- a/pkg/nodeconfigs/toa_config.go +++ b/pkg/nodeconfigs/toa_config.go @@ -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 +} diff --git a/pkg/nodeconfigs/toa_config_test.go b/pkg/nodeconfigs/toa_config_test.go index dbd7254..1aef6bb 100644 --- a/pkg/nodeconfigs/toa_config_test.go +++ b/pkg/nodeconfigs/toa_config_test.go @@ -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)