Chore: improve outbound architecture
This commit is contained in:
@ -3,6 +3,7 @@ package adapters
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -15,7 +16,7 @@ type proxy struct {
|
||||
}
|
||||
|
||||
type Fallback struct {
|
||||
name string
|
||||
*Base
|
||||
proxies []*proxy
|
||||
rawURL string
|
||||
interval time.Duration
|
||||
@ -29,14 +30,6 @@ type FallbackOption struct {
|
||||
Interval int `proxy:"interval"`
|
||||
}
|
||||
|
||||
func (f *Fallback) Name() string {
|
||||
return f.name
|
||||
}
|
||||
|
||||
func (f *Fallback) Type() C.AdapterType {
|
||||
return C.Fallback
|
||||
}
|
||||
|
||||
func (f *Fallback) Now() string {
|
||||
_, proxy := f.findNextValidProxy(0)
|
||||
if proxy != nil {
|
||||
@ -45,7 +38,7 @@ func (f *Fallback) Now() string {
|
||||
return f.proxies[0].RawProxy.Name()
|
||||
}
|
||||
|
||||
func (f *Fallback) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err error) {
|
||||
func (f *Fallback) Generator(metadata *C.Metadata) (net.Conn, error) {
|
||||
idx := 0
|
||||
var proxy *proxy
|
||||
for {
|
||||
@ -53,13 +46,13 @@ func (f *Fallback) Generator(metadata *C.Metadata) (adapter C.ProxyAdapter, err
|
||||
if proxy == nil {
|
||||
break
|
||||
}
|
||||
adapter, err = proxy.RawProxy.Generator(metadata)
|
||||
adapter, err := proxy.RawProxy.Generator(metadata)
|
||||
if err != nil {
|
||||
proxy.Valid = false
|
||||
idx++
|
||||
continue
|
||||
}
|
||||
return
|
||||
return adapter, err
|
||||
}
|
||||
return f.proxies[0].RawProxy.Generator(metadata)
|
||||
}
|
||||
@ -138,7 +131,10 @@ func NewFallback(option FallbackOption, proxies []C.Proxy) (*Fallback, error) {
|
||||
}
|
||||
|
||||
Fallback := &Fallback{
|
||||
name: option.Name,
|
||||
Base: &Base{
|
||||
name: option.Name,
|
||||
tp: C.Fallback,
|
||||
},
|
||||
proxies: warpperProxies,
|
||||
rawURL: option.URL,
|
||||
interval: interval,
|
||||
|
Reference in New Issue
Block a user