Merge from remote branch

This commit is contained in:
yaling888
2021-09-08 04:42:56 +08:00
33 changed files with 857 additions and 320 deletions

View File

@ -24,7 +24,7 @@ func (d *Direct) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn,
// DialUDP implements C.ProxyAdapter
func (d *Direct) DialUDP(metadata *C.Metadata) (C.PacketConn, error) {
pc, err := dialer.ListenPacket("udp", "")
pc, err := dialer.ListenPacket(context.Background(), "udp", "")
if err != nil {
return nil, err
}

View File

@ -89,7 +89,7 @@ func (ss *ShadowSocks) DialContext(ctx context.Context, metadata *C.Metadata) (_
// DialUDP implements C.ProxyAdapter
func (ss *ShadowSocks) DialUDP(metadata *C.Metadata) (C.PacketConn, error) {
pc, err := dialer.ListenPacket("udp", "")
pc, err := dialer.ListenPacket(context.Background(), "udp", "")
if err != nil {
return nil, err
}

View File

@ -74,7 +74,7 @@ func (ssr *ShadowSocksR) DialContext(ctx context.Context, metadata *C.Metadata)
// DialUDP implements C.ProxyAdapter
func (ssr *ShadowSocksR) DialUDP(metadata *C.Metadata) (C.PacketConn, error) {
pc, err := dialer.ListenPacket("udp", "")
pc, err := dialer.ListenPacket(context.Background(), "udp", "")
if err != nil {
return nil, err
}

View File

@ -110,7 +110,7 @@ func (ss *Socks5) DialUDP(metadata *C.Metadata) (_ C.PacketConn, err error) {
return
}
pc, err := dialer.ListenPacket("udp", "")
pc, err := dialer.ListenPacket(context.Background(), "udp", "")
if err != nil {
return
}

View File

@ -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]

View File

@ -3,6 +3,7 @@ package provider
import (
"context"
"io/ioutil"
"net"
"net/http"
"net/url"
"time"
@ -71,7 +72,9 @@ func (h *HTTPVehicle) Read() ([]byte, error) {
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
DialContext: dialer.DialContext,
DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
return dialer.DialContext(ctx, network, address)
},
}
client := http.Client{Transport: transport}