From a2d59d6ef540e9e6831e988e6c43e2a3efc6e9ea Mon Sep 17 00:00:00 2001 From: Excited Codes <61885669+ExcitedCodes@users.noreply.github.com> Date: Mon, 6 Sep 2021 21:39:28 +0800 Subject: [PATCH] Feature: skip DIRECT proxies in relay (#1583) --- adapter/outboundgroup/relay.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/adapter/outboundgroup/relay.go b/adapter/outboundgroup/relay.go index 8d8128ba..78410a44 100644 --- a/adapter/outboundgroup/relay.go +++ b/adapter/outboundgroup/relay.go @@ -3,7 +3,6 @@ package outboundgroup import ( "context" "encoding/json" - "errors" "fmt" "github.com/Dreamacro/clash/adapter/outbound" @@ -21,10 +20,20 @@ type Relay struct { // DialContext implements C.ProxyAdapter func (r *Relay) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) { - proxies := r.proxies(metadata, true) - if len(proxies) == 0 { - return nil, errors.New("proxy does not exist") + var proxies []C.Proxy + for _, proxy := range r.proxies(metadata, true) { + 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] last := proxies[len(proxies)-1]