@@ -2,15 +2,13 @@ package outbound
2
2
3
3
import (
4
4
"context"
5
- "errors"
6
5
"net"
7
6
"strconv"
8
7
"time"
9
8
10
9
CN "github.com/metacubex/clash/common/net"
11
10
"github.com/metacubex/clash/component/dialer"
12
11
"github.com/metacubex/clash/component/proxydialer"
13
- "github.com/metacubex/clash/component/resolver"
14
12
C "github.com/metacubex/clash/constant"
15
13
"github.com/metacubex/clash/transport/anytls"
16
14
"github.com/metacubex/clash/transport/vmess"
@@ -28,19 +26,20 @@ type AnyTLS struct {
28
26
29
27
type AnyTLSOption struct {
30
28
BasicOption
31
- Name string `proxy:"name"`
32
- Server string `proxy:"server"`
33
- Port int `proxy:"port"`
34
- Password string `proxy:"password"`
35
- ALPN []string `proxy:"alpn,omitempty"`
36
- SNI string `proxy:"sni,omitempty"`
37
- ClientFingerprint string `proxy:"client-fingerprint,omitempty"`
38
- SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
39
- Fingerprint string `proxy:"fingerprint,omitempty"`
40
- UDP bool `proxy:"udp,omitempty"`
41
- IdleSessionCheckInterval int `proxy:"idle-session-check-interval,omitempty"`
42
- IdleSessionTimeout int `proxy:"idle-session-timeout,omitempty"`
43
- MinIdleSession int `proxy:"min-idle-session,omitempty"`
29
+ Name string `proxy:"name"`
30
+ Server string `proxy:"server"`
31
+ Port int `proxy:"port"`
32
+ Password string `proxy:"password"`
33
+ ALPN []string `proxy:"alpn,omitempty"`
34
+ SNI string `proxy:"sni,omitempty"`
35
+ ECHOpts ECHOptions `proxy:"ech-opts,omitempty"`
36
+ ClientFingerprint string `proxy:"client-fingerprint,omitempty"`
37
+ SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
38
+ Fingerprint string `proxy:"fingerprint,omitempty"`
39
+ UDP bool `proxy:"udp,omitempty"`
40
+ IdleSessionCheckInterval int `proxy:"idle-session-check-interval,omitempty"`
41
+ IdleSessionTimeout int `proxy:"idle-session-timeout,omitempty"`
42
+ MinIdleSession int `proxy:"min-idle-session,omitempty"`
44
43
}
45
44
46
45
func (t * AnyTLS ) DialContext (ctx context.Context , metadata * C.Metadata ) (_ C.Conn , err error ) {
@@ -52,20 +51,17 @@ func (t *AnyTLS) DialContext(ctx context.Context, metadata *C.Metadata) (_ C.Con
52
51
}
53
52
54
53
func (t * AnyTLS ) ListenPacketContext (ctx context.Context , metadata * C.Metadata ) (_ C.PacketConn , err error ) {
54
+ if err = t .ResolveUDP (ctx , metadata ); err != nil {
55
+ return nil , err
56
+ }
57
+
55
58
// create tcp
56
59
c , err := t .client .CreateProxy (ctx , uot .RequestDestination (2 ))
57
60
if err != nil {
58
61
return nil , err
59
62
}
60
63
61
64
// create uot on tcp
62
- if ! metadata .Resolved () {
63
- ip , err := resolver .ResolveIP (ctx , metadata .Host )
64
- if err != nil {
65
- return nil , errors .New ("can't resolve ip" )
66
- }
67
- metadata .DstIP = ip
68
- }
69
65
destination := M .SocksaddrFromNet (metadata .UDPAddr ())
70
66
return newPacketConn (CN .NewThreadSafePacketConn (uot .NewLazyConn (c , uot.Request {Destination : destination })), t ), nil
71
67
}
@@ -115,12 +111,17 @@ func NewAnyTLS(option AnyTLSOption) (*AnyTLS, error) {
115
111
IdleSessionTimeout : time .Duration (option .IdleSessionTimeout ) * time .Second ,
116
112
MinIdleSession : option .MinIdleSession ,
117
113
}
114
+ echConfig , err := option .ECHOpts .Parse ()
115
+ if err != nil {
116
+ return nil , err
117
+ }
118
118
tlsConfig := & vmess.TLSConfig {
119
119
Host : option .SNI ,
120
120
SkipCertVerify : option .SkipCertVerify ,
121
121
NextProtos : option .ALPN ,
122
122
FingerPrint : option .Fingerprint ,
123
123
ClientFingerprint : option .ClientFingerprint ,
124
+ ECH : echConfig ,
124
125
}
125
126
if tlsConfig .Host == "" {
126
127
tlsConfig .Host = option .Server
0 commit comments