From efbe99f59da7d67cdd216c87faccd38371f8a862 Mon Sep 17 00:00:00 2001 From: mzz2017 Date: Mon, 25 Apr 2022 15:57:00 +0800 Subject: [PATCH] chore: fix building --- service/core/v2ray/process.go | 2 +- service/core/v2ray/v2rayTmpl.go | 88 ++++++++++++++++--------------- service/server/service/latency.go | 2 +- 3 files changed, 47 insertions(+), 45 deletions(-) diff --git a/service/core/v2ray/process.go b/service/core/v2ray/process.go index 5aa64305..1633c00c 100644 --- a/service/core/v2ray/process.go +++ b/service/core/v2ray/process.go @@ -60,7 +60,7 @@ func NewProcess(tmpl *Template) (process *Process, err error) { } }() if tmpl.API == nil { - tmpl.SetAPI() + log.Fatal("unexpected tmpl.API == nil") } ctx, cancel := context.WithCancel(context.Background()) process.procCancel = cancel diff --git a/service/core/v2ray/v2rayTmpl.go b/service/core/v2ray/v2rayTmpl.go index 52b985de..e830bad0 100644 --- a/service/core/v2ray/v2rayTmpl.go +++ b/service/core/v2ray/v2rayTmpl.go @@ -1380,54 +1380,56 @@ func (t *Template) SetAPI(serverData *ServerData) (port int, err error) { } time.Sleep(100 * time.Millisecond) } - outbounds := t.outNames() - mSubjectSelector := make(map[string]struct{}) - for outbound, isGroup := range outbounds { - if !isGroup { - continue - } - - strategy := "leastPing" - interval := 10 * time.Second - var selector []string - - for _, vi := range serverData.OutboundName2ServerObjs[outbound] { - selector = append(selector, Ps2OutboundTag(vi.GetName())) - } - - t.Routing.Balancers = append(t.Routing.Balancers, coreObj.Balancer{ - Tag: outbound, - Selector: selector, - Strategy: coreObj.BalancerStrategy{ - //TODO: configure.GetOutboundSetting - Type: strategy, - }, - }) - - if strategy == "leastPing" { - if err = service.CheckObservatorySupported(); err != nil { - return port, fmt.Errorf("not support observatory based load balance: %w", err) + if serverData != nil { + outbounds := t.outNames() + mSubjectSelector := make(map[string]struct{}) + for outbound, isGroup := range outbounds { + if !isGroup { + continue } - if t.Observatory == nil { - t.Observatory = &coreObj.Observatory{ - ProbeURL: "https://gstatic.com/generate_204", - ProbeInterval: interval.String(), + + strategy := "leastPing" + interval := 10 * time.Second + var selector []string + + for _, vi := range serverData.OutboundName2ServerObjs[outbound] { + selector = append(selector, Ps2OutboundTag(vi.GetName())) + } + + t.Routing.Balancers = append(t.Routing.Balancers, coreObj.Balancer{ + Tag: outbound, + Selector: selector, + Strategy: coreObj.BalancerStrategy{ + //TODO: configure.GetOutboundSetting + Type: strategy, + }, + }) + + if strategy == "leastPing" { + if err = service.CheckObservatorySupported(); err != nil { + return port, fmt.Errorf("not support observatory based load balance: %w", err) + } + if t.Observatory == nil { + t.Observatory = &coreObj.Observatory{ + ProbeURL: "https://gstatic.com/generate_204", + ProbeInterval: interval.String(), + } + } + for _, s := range selector { + mSubjectSelector[s] = struct{}{} } } - for _, s := range selector { - mSubjectSelector[s] = struct{}{} + } + if t.Observatory != nil { + var subjectSelector []string + for s := range mSubjectSelector { + subjectSelector = append(subjectSelector, s) } - } - } - if t.Observatory != nil { - var subjectSelector []string - for s := range mSubjectSelector { - subjectSelector = append(subjectSelector, s) - } - t.Observatory.SubjectSelector = subjectSelector + t.Observatory.SubjectSelector = subjectSelector - services = append(services, "ObservatoryService") - t.ApiCloses = append(t.ApiCloses, ObservatoryProducer(port)) + services = append(services, "ObservatoryService") + t.ApiCloses = append(t.ApiCloses, ObservatoryProducer(port)) + } } t.API = &coreObj.APIObject{ Tag: "api-out", diff --git a/service/server/service/latency.go b/service/server/service/latency.go index 78ddf8d6..bb7d4103 100644 --- a/service/server/service/latency.go +++ b/service/server/service/latency.go @@ -140,7 +140,7 @@ func TestHttpLatency(which []*configure.Which, timeout time.Duration, maxParalle SpecialMode: configure.SpecialModeNone, AntiPollution: configure.AntipollutionClosed, }) - tmpl.SetAPI() + tmpl.SetAPI(nil) } inboundPortMap := make([]string, len(vms)) pluginPortMap := make(map[int]int)