diff --git a/README.md b/README.md index 2d640d74c..48d0537db 100644 --- a/README.md +++ b/README.md @@ -109,10 +109,10 @@ Proxy: Proxy Group: # url-test select which proxy will be used by benchmarking speed to a URL. -- { name: "auto", type: url-test, proxies: ["ss1", "ss2", "vmess1"], url: http://www.gstatic.com/generate_204, delay: 300 } +- { name: "auto", type: url-test, proxies: ["ss1", "ss2", "vmess1"], url: http://www.gstatic.com/generate_204, interval: 300 } # fallback select an available policy by priority. The availability is tested by accessing an URL, just like an auto url-test group. -- { name: "fallback-auto", type: fallback, proxies: ["ss1", "ss2", "vmess1"], url: http://www.gstatic.com/generate_204, delay: 300 } +- { name: "fallback-auto", type: fallback, proxies: ["ss1", "ss2", "vmess1"], url: http://www.gstatic.com/generate_204, interval: 300 } # select is used for selecting proxy or proxy group # you can use RESTful API to switch proxy, is recommended for use in GUI. diff --git a/adapters/outbound/fallback.go b/adapters/outbound/fallback.go index 7057d0238..e858d0ab0 100644 --- a/adapters/outbound/fallback.go +++ b/adapters/outbound/fallback.go @@ -14,18 +14,18 @@ type proxy struct { } type Fallback struct { - name string - proxies []*proxy - rawURL string - delay time.Duration - done chan struct{} + name string + proxies []*proxy + rawURL string + interval time.Duration + done chan struct{} } type FallbackOption struct { - Name string `proxy:"name"` - Proxies []string `proxy:"proxies"` - URL string `proxy:"url"` - Delay int `proxy:"delay"` + Name string `proxy:"name"` + Proxies []string `proxy:"proxies"` + URL string `proxy:"url"` + Interval int `proxy:"interval"` } func (f *Fallback) Name() string { @@ -68,7 +68,7 @@ func (f *Fallback) Close() { } func (f *Fallback) loop() { - tick := time.NewTicker(f.delay) + tick := time.NewTicker(f.interval) go f.validTest() Loop: for { @@ -115,7 +115,7 @@ func NewFallback(option FallbackOption, proxies []C.Proxy) (*Fallback, error) { return nil, errors.New("The number of proxies cannot be 0") } - delay := time.Duration(option.Delay) * time.Second + interval := time.Duration(option.Interval) * time.Second warpperProxies := make([]*proxy, len(proxies)) for idx := range proxies { warpperProxies[idx] = &proxy{ @@ -125,11 +125,11 @@ func NewFallback(option FallbackOption, proxies []C.Proxy) (*Fallback, error) { } Fallback := &Fallback{ - name: option.Name, - proxies: warpperProxies, - rawURL: option.URL, - delay: delay, - done: make(chan struct{}), + name: option.Name, + proxies: warpperProxies, + rawURL: option.URL, + interval: interval, + done: make(chan struct{}), } go Fallback.loop() return Fallback, nil diff --git a/adapters/outbound/urltest.go b/adapters/outbound/urltest.go index c536e612f..df2be060d 100644 --- a/adapters/outbound/urltest.go +++ b/adapters/outbound/urltest.go @@ -9,19 +9,19 @@ import ( ) type URLTest struct { - name string - proxies []C.Proxy - rawURL string - fast C.Proxy - delay time.Duration - done chan struct{} + name string + proxies []C.Proxy + rawURL string + fast C.Proxy + interval time.Duration + done chan struct{} } type URLTestOption struct { - Name string `proxy:"name"` - Proxies []string `proxy:"proxies"` - URL string `proxy:"url"` - Delay int `proxy:"delay"` + Name string `proxy:"name"` + Proxies []string `proxy:"proxies"` + URL string `proxy:"url"` + Interval int `proxy:"interval"` } func (u *URLTest) Name() string { @@ -45,7 +45,7 @@ func (u *URLTest) Close() { } func (u *URLTest) loop() { - tick := time.NewTicker(u.delay) + tick := time.NewTicker(u.interval) go u.speedTest() Loop: for { @@ -63,7 +63,7 @@ func (u *URLTest) speedTest() { wg.Add(len(u.proxies)) c := make(chan interface{}) fast := selectFast(c) - timer := time.NewTimer(u.delay) + timer := time.NewTimer(u.interval) for _, p := range u.proxies { go func(p C.Proxy) { @@ -100,14 +100,14 @@ func NewURLTest(option URLTestOption, proxies []C.Proxy) (*URLTest, error) { return nil, errors.New("The number of proxies cannot be 0") } - delay := time.Duration(option.Delay) * time.Second + interval := time.Duration(option.Interval) * time.Second urlTest := &URLTest{ - name: option.Name, - proxies: proxies[:], - rawURL: option.URL, - fast: proxies[0], - delay: delay, - done: make(chan struct{}), + name: option.Name, + proxies: proxies[:], + rawURL: option.URL, + fast: proxies[0], + interval: interval, + done: make(chan struct{}), } go urlTest.loop() return urlTest, nil