Feature: skip DIRECT proxies in relay (#1583)
This commit is contained in:
parent
8ef5cdb8be
commit
a2d59d6ef5
1 changed files with 13 additions and 4 deletions
|
@ -3,7 +3,6 @@ package outboundgroup
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/adapter/outbound"
|
"github.com/Dreamacro/clash/adapter/outbound"
|
||||||
|
@ -21,10 +20,20 @@ type Relay struct {
|
||||||
|
|
||||||
// DialContext implements C.ProxyAdapter
|
// DialContext implements C.ProxyAdapter
|
||||||
func (r *Relay) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) {
|
func (r *Relay) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) {
|
||||||
proxies := r.proxies(metadata, true)
|
var proxies []C.Proxy
|
||||||
if len(proxies) == 0 {
|
for _, proxy := range r.proxies(metadata, true) {
|
||||||
return nil, errors.New("proxy does not exist")
|
if proxy.Type() != C.Direct {
|
||||||
|
proxies = append(proxies, proxy)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch len(proxies) {
|
||||||
|
case 0:
|
||||||
|
return outbound.NewDirect().DialContext(ctx, metadata)
|
||||||
|
case 1:
|
||||||
|
return proxies[0].DialContext(ctx, metadata)
|
||||||
|
}
|
||||||
|
|
||||||
first := proxies[0]
|
first := proxies[0]
|
||||||
last := proxies[len(proxies)-1]
|
last := proxies[len(proxies)-1]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue