@@ -12,6 +12,7 @@ import (
12
12
13
13
"github.com/metacubex/mihomo/component/ca"
14
14
"github.com/metacubex/mihomo/component/dialer"
15
+ "github.com/metacubex/mihomo/component/ech"
15
16
"github.com/metacubex/mihomo/component/proxydialer"
16
17
tlsC "github.com/metacubex/mihomo/component/tls"
17
18
C "github.com/metacubex/mihomo/constant"
@@ -44,6 +45,9 @@ type Hysteria struct {
44
45
45
46
option * HysteriaOption
46
47
client * core.Client
48
+
49
+ tlsConfig * tlsC.Config
50
+ echConfig * ech.Config
47
51
}
48
52
49
53
func (h * Hysteria ) DialContext (ctx context.Context , metadata * C.Metadata ) (C.Conn , error ) {
@@ -79,7 +83,15 @@ func (h *Hysteria) genHdc(ctx context.Context) utils.PacketDialer {
79
83
return cDialer .ListenPacket (ctx , network , "" , rAddrPort )
80
84
},
81
85
remoteAddr : func (addr string ) (net.Addr , error ) {
82
- return resolveUDPAddr (ctx , "udp" , addr , h .prefer )
86
+ udpAddr , err := resolveUDPAddr (ctx , "udp" , addr , h .prefer )
87
+ if err != nil {
88
+ return nil , err
89
+ }
90
+ err = h .echConfig .ClientHandle (ctx , h .tlsConfig )
91
+ if err != nil {
92
+ return nil , err
93
+ }
94
+ return udpAddr , nil
83
95
},
84
96
}
85
97
}
@@ -93,30 +105,31 @@ func (h *Hysteria) ProxyInfo() C.ProxyInfo {
93
105
94
106
type HysteriaOption struct {
95
107
BasicOption
96
- Name string `proxy:"name"`
97
- Server string `proxy:"server"`
98
- Port int `proxy:"port,omitempty"`
99
- Ports string `proxy:"ports,omitempty"`
100
- Protocol string `proxy:"protocol,omitempty"`
101
- ObfsProtocol string `proxy:"obfs-protocol,omitempty"` // compatible with Stash
102
- Up string `proxy:"up"`
103
- UpSpeed int `proxy:"up-speed,omitempty"` // compatible with Stash
104
- Down string `proxy:"down"`
105
- DownSpeed int `proxy:"down-speed,omitempty"` // compatible with Stash
106
- Auth string `proxy:"auth,omitempty"`
107
- AuthString string `proxy:"auth-str,omitempty"`
108
- Obfs string `proxy:"obfs,omitempty"`
109
- SNI string `proxy:"sni,omitempty"`
110
- SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
111
- Fingerprint string `proxy:"fingerprint,omitempty"`
112
- ALPN []string `proxy:"alpn,omitempty"`
113
- CustomCA string `proxy:"ca,omitempty"`
114
- CustomCAString string `proxy:"ca-str,omitempty"`
115
- ReceiveWindowConn int `proxy:"recv-window-conn,omitempty"`
116
- ReceiveWindow int `proxy:"recv-window,omitempty"`
117
- DisableMTUDiscovery bool `proxy:"disable-mtu-discovery,omitempty"`
118
- FastOpen bool `proxy:"fast-open,omitempty"`
119
- HopInterval int `proxy:"hop-interval,omitempty"`
108
+ Name string `proxy:"name"`
109
+ Server string `proxy:"server"`
110
+ Port int `proxy:"port,omitempty"`
111
+ Ports string `proxy:"ports,omitempty"`
112
+ Protocol string `proxy:"protocol,omitempty"`
113
+ ObfsProtocol string `proxy:"obfs-protocol,omitempty"` // compatible with Stash
114
+ Up string `proxy:"up"`
115
+ UpSpeed int `proxy:"up-speed,omitempty"` // compatible with Stash
116
+ Down string `proxy:"down"`
117
+ DownSpeed int `proxy:"down-speed,omitempty"` // compatible with Stash
118
+ Auth string `proxy:"auth,omitempty"`
119
+ AuthString string `proxy:"auth-str,omitempty"`
120
+ Obfs string `proxy:"obfs,omitempty"`
121
+ SNI string `proxy:"sni,omitempty"`
122
+ ECHOpts ECHOptions `proxy:"ech-opts,omitempty"`
123
+ SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
124
+ Fingerprint string `proxy:"fingerprint,omitempty"`
125
+ ALPN []string `proxy:"alpn,omitempty"`
126
+ CustomCA string `proxy:"ca,omitempty"`
127
+ CustomCAString string `proxy:"ca-str,omitempty"`
128
+ ReceiveWindowConn int `proxy:"recv-window-conn,omitempty"`
129
+ ReceiveWindow int `proxy:"recv-window,omitempty"`
130
+ DisableMTUDiscovery bool `proxy:"disable-mtu-discovery,omitempty"`
131
+ FastOpen bool `proxy:"fast-open,omitempty"`
132
+ HopInterval int `proxy:"hop-interval,omitempty"`
120
133
}
121
134
122
135
func (c * HysteriaOption ) Speed () (uint64 , uint64 , error ) {
@@ -161,6 +174,13 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
161
174
} else {
162
175
tlsConfig .NextProtos = []string {DefaultALPN }
163
176
}
177
+
178
+ echConfig , err := option .ECHOpts .Parse ()
179
+ if err != nil {
180
+ return nil , err
181
+ }
182
+ tlsClientConfig := tlsC .UConfig (tlsConfig )
183
+
164
184
quicConfig := & quic.Config {
165
185
InitialStreamReceiveWindow : uint64 (option .ReceiveWindowConn ),
166
186
MaxStreamReceiveWindow : uint64 (option .ReceiveWindowConn ),
@@ -215,7 +235,7 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
215
235
down = uint64 (option .DownSpeed * mbpsToBps )
216
236
}
217
237
client , err := core .NewClient (
218
- addr , ports , option .Protocol , auth , tlsC . UConfig ( tlsConfig ) , quicConfig , clientTransport , up , down , func (refBPS uint64 ) congestion.CongestionControl {
238
+ addr , ports , option .Protocol , auth , tlsClientConfig , quicConfig , clientTransport , up , down , func (refBPS uint64 ) congestion.CongestionControl {
219
239
return hyCongestion .NewBrutalSender (congestion .ByteCount (refBPS ))
220
240
}, obfuscator , hopInterval , option .FastOpen ,
221
241
)
@@ -233,8 +253,10 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
233
253
rmark : option .RoutingMark ,
234
254
prefer : C .NewDNSPrefer (option .IPVersion ),
235
255
},
236
- option : & option ,
237
- client : client ,
256
+ option : & option ,
257
+ client : client ,
258
+ tlsConfig : tlsClientConfig ,
259
+ echConfig : echConfig ,
238
260
}
239
261
240
262
return outbound , nil
0 commit comments