fix: proxy-groups filter logic

This commit is contained in:
gVisor bot 2022-04-22 17:27:55 +08:00
parent de105c08f6
commit 5386a5f00e
17 changed files with 63 additions and 3 deletions

View file

@ -12,6 +12,10 @@ type Direct struct {
*Base *Base
} }
func (d *Direct) IsProxyGroup() bool {
return false
}
// DialContext implements C.ProxyAdapter // DialContext implements C.ProxyAdapter
func (d *Direct) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) { func (d *Direct) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) {
opts = append(opts, dialer.WithDirect()) opts = append(opts, dialer.WithDirect())

View file

@ -38,6 +38,10 @@ type HttpOption struct {
Headers map[string]string `proxy:"headers,omitempty"` Headers map[string]string `proxy:"headers,omitempty"`
} }
func (h *Http) IsProxyGroup() bool {
return false
}
// StreamConn implements C.ProxyAdapter // StreamConn implements C.ProxyAdapter
func (h *Http) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) { func (h *Http) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) {
if h.tlsConfig != nil { if h.tlsConfig != nil {

View file

@ -14,6 +14,10 @@ type Reject struct {
*Base *Base
} }
func (r *Reject) IsProxyGroup() bool {
return false
}
// DialContext implements C.ProxyAdapter // DialContext implements C.ProxyAdapter
func (r *Reject) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) { func (r *Reject) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) {
return NewConn(&nopConn{}, r), nil return NewConn(&nopConn{}, r), nil

View file

@ -54,6 +54,10 @@ type v2rayObfsOption struct {
Mux bool `obfs:"mux,omitempty"` Mux bool `obfs:"mux,omitempty"`
} }
func (ss *ShadowSocks) IsProxyGroup() bool {
return false
}
// StreamConn implements C.ProxyAdapter // StreamConn implements C.ProxyAdapter
func (ss *ShadowSocks) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) { func (ss *ShadowSocks) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) {
switch ss.obfsMode { switch ss.obfsMode {

View file

@ -37,6 +37,10 @@ type ShadowSocksROption struct {
UDP bool `proxy:"udp,omitempty"` UDP bool `proxy:"udp,omitempty"`
} }
func (ssr *ShadowSocksR) IsProxyGroup() bool {
return false
}
// StreamConn implements C.ProxyAdapter // StreamConn implements C.ProxyAdapter
func (ssr *ShadowSocksR) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) { func (ssr *ShadowSocksR) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) {
c = ssr.obfs.StreamConn(c) c = ssr.obfs.StreamConn(c)

View file

@ -39,6 +39,10 @@ type streamOption struct {
obfsOption *simpleObfsOption obfsOption *simpleObfsOption
} }
func (s *Snell) IsProxyGroup() bool {
return false
}
func streamConn(c net.Conn, option streamOption) *snell.Snell { func streamConn(c net.Conn, option streamOption) *snell.Snell {
switch option.obfsOption.Mode { switch option.obfsOption.Mode {
case "tls": case "tls":

View file

@ -22,7 +22,6 @@ type Socks5 struct {
skipCertVerify bool skipCertVerify bool
tlsConfig *tls.Config tlsConfig *tls.Config
} }
type Socks5Option struct { type Socks5Option struct {
BasicOption BasicOption
Name string `proxy:"name"` Name string `proxy:"name"`
@ -35,6 +34,10 @@ type Socks5Option struct {
SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"` SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
} }
func (ss *Socks5) IsProxyGroup() bool {
return false
}
// StreamConn implements C.ProxyAdapter // StreamConn implements C.ProxyAdapter
func (ss *Socks5) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) { func (ss *Socks5) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) {
if ss.tls { if ss.tls {

View file

@ -27,7 +27,6 @@ type Trojan struct {
gunConfig *gun.Config gunConfig *gun.Config
transport *http2.Transport transport *http2.Transport
} }
type TrojanOption struct { type TrojanOption struct {
BasicOption BasicOption
Name string `proxy:"name"` Name string `proxy:"name"`
@ -45,6 +44,10 @@ type TrojanOption struct {
FlowShow bool `proxy:"flow-show,omitempty"` FlowShow bool `proxy:"flow-show,omitempty"`
} }
func (t *Trojan) IsProxyGroup() bool {
return false
}
func (t *Trojan) plainStream(c net.Conn) (net.Conn, error) { func (t *Trojan) plainStream(c net.Conn) (net.Conn, error) {
if t.option.Network == "ws" { if t.option.Network == "ws" {
host, port, _ := net.SplitHostPort(t.addr) host, port, _ := net.SplitHostPort(t.addr)

View file

@ -59,6 +59,10 @@ type VlessOption struct {
ServerName string `proxy:"servername,omitempty"` ServerName string `proxy:"servername,omitempty"`
} }
func (v *Vless) IsProxyGroup() bool {
return false
}
func (v *Vless) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) { func (v *Vless) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) {
var err error var err error
switch v.option.Network { switch v.option.Network {

View file

@ -75,6 +75,10 @@ type WSOptions struct {
EarlyDataHeaderName string `proxy:"early-data-header-name,omitempty"` EarlyDataHeaderName string `proxy:"early-data-header-name,omitempty"`
} }
func (v *Vmess) IsProxyGroup() bool {
return false
}
// StreamConn implements C.ProxyAdapter // StreamConn implements C.ProxyAdapter
func (v *Vmess) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) { func (v *Vmess) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) {
var err error var err error

View file

@ -29,8 +29,9 @@ func getProvidersProxies(providers []provider.ProxyProvider, touch bool, filter
//filterReg = regexp.MustCompile(filter) //filterReg = regexp.MustCompile(filter)
filterReg = regexp2.MustCompile(filter, 0) filterReg = regexp2.MustCompile(filter, 0)
for _, p := range proxies { for _, p := range proxies {
if p.Type() < 8 { if p.IsProxyGroup() {
matchedProxies = append(matchedProxies, p) matchedProxies = append(matchedProxies, p)
continue
} }
//if filterReg.MatchString(p.Name()) { //if filterReg.MatchString(p.Name()) {

View file

@ -24,6 +24,10 @@ type Fallback struct {
failedTime *atomic.Int64 failedTime *atomic.Int64
} }
func (f *Fallback) IsProxyGroup() bool {
return true
}
func (f *Fallback) Now() string { func (f *Fallback) Now() string {
proxy := f.findAliveProxy(false) proxy := f.findAliveProxy(false)
return proxy.Name() return proxy.Name()

View file

@ -28,6 +28,10 @@ type LoadBalance struct {
strategyFn strategyFn strategyFn strategyFn
} }
func (lb *LoadBalance) IsProxyGroup() bool {
return true
}
var errStrategy = errors.New("unsupported strategy") var errStrategy = errors.New("unsupported strategy")
func parseStrategy(config map[string]any) string { func parseStrategy(config map[string]any) string {

View file

@ -19,6 +19,10 @@ type Relay struct {
filter string filter string
} }
func (r *Relay) IsProxyGroup() bool {
return true
}
// DialContext implements C.ProxyAdapter // DialContext implements C.ProxyAdapter
func (r *Relay) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) { func (r *Relay) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) {
var proxies []C.Proxy var proxies []C.Proxy

View file

@ -21,6 +21,10 @@ type Selector struct {
providers []provider.ProxyProvider providers []provider.ProxyProvider
} }
func (s *Selector) IsProxyGroup() bool {
return true
}
// DialContext implements C.ProxyAdapter // DialContext implements C.ProxyAdapter
func (s *Selector) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) { func (s *Selector) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) {
c, err := s.selectedProxy(true).DialContext(ctx, metadata, s.Base.DialOptions(opts...)...) c, err := s.selectedProxy(true).DialContext(ctx, metadata, s.Base.DialOptions(opts...)...)

View file

@ -35,6 +35,10 @@ type URLTest struct {
failedTime *atomic.Int64 failedTime *atomic.Int64
} }
func (u *URLTest) IsProxyGroup() bool {
return true
}
func (u *URLTest) Now() string { func (u *URLTest) Now() string {
return u.fast(false).Name() return u.fast(false).Name()
} }

View file

@ -83,6 +83,7 @@ type ProxyAdapter interface {
Addr() string Addr() string
SupportUDP() bool SupportUDP() bool
MarshalJSON() ([]byte, error) MarshalJSON() ([]byte, error)
IsProxyGroup() bool
// StreamConn wraps a protocol around net.Conn with Metadata. // StreamConn wraps a protocol around net.Conn with Metadata.
// //