@@ -246,6 +246,20 @@ fn load_cert_and_key(
246
246
Ok ( ( certificates, key) )
247
247
}
248
248
249
+ impl TlsConfig {
250
+ #[ inline( always) ]
251
+ fn load_cert_and_key ( & self ) -> anyhow:: Result < ( Vec < Certificate > , PrivateKey ) > {
252
+ load_cert_and_key ( & self . certificate , & self . key )
253
+ }
254
+ }
255
+
256
+ impl HttpsAndQuicConfig {
257
+ #[ inline( always) ]
258
+ fn load_cert_and_key ( & self ) -> anyhow:: Result < ( Vec < Certificate > , PrivateKey ) > {
259
+ load_cert_and_key ( & self . certificate , & self . key )
260
+ }
261
+ }
262
+
249
263
/// Load a text file from url and cache it.
250
264
/// If restore_from_cache is true, only the cache is used.
251
265
/// The first return value is the file content.
@@ -354,9 +368,9 @@ async fn async_main(config: Config) {
354
368
server. register_socket ( udp_socket) ;
355
369
} ,
356
370
DownstreamConfig :: Tls ( downstream) => {
357
- let cert_and_key =
358
- load_cert_and_key ( & downstream . certificate , & downstream . key )
359
- . expect ( "failed to load certificate or private key" ) ;
371
+ let cert_and_key = downstream
372
+ . load_cert_and_key ( )
373
+ . expect ( "failed to load certificate or private key" ) ;
360
374
let socket_addr = format ! ( "{}:{}" , downstream. listen, downstream. port) ;
361
375
let tcp_listener = TcpListener :: bind ( & socket_addr)
362
376
. await
@@ -371,9 +385,9 @@ async fn async_main(config: Config) {
371
385
. expect ( "failed to register tls downstream" ) ;
372
386
} ,
373
387
DownstreamConfig :: Https ( downstream) => {
374
- let cert_and_key =
375
- load_cert_and_key ( & downstream . certificate , & downstream . key )
376
- . expect ( "failed to load certificate or private key" ) ;
388
+ let cert_and_key = downstream
389
+ . load_cert_and_key ( )
390
+ . expect ( "failed to load certificate or private key" ) ;
377
391
let socket_addr = format ! ( "{}:{}" , downstream. listen, downstream. port) ;
378
392
let tcp_listener = TcpListener :: bind ( & socket_addr)
379
393
. await
@@ -386,16 +400,16 @@ async fn async_main(config: Config) {
386
400
cert_and_key,
387
401
downstream. dns_hostname
388
402
)
389
- . expect ( "failed to register tls downstream" ) ;
403
+ . expect ( "failed to register https downstream" ) ;
390
404
} ,
391
405
DownstreamConfig :: Quic ( downstream) => {
392
- let cert_and_key =
393
- load_cert_and_key ( & downstream . certificate , & downstream . key )
394
- . expect ( "failed to load certificate or private key" ) ;
406
+ let cert_and_key = downstream
407
+ . load_cert_and_key ( )
408
+ . expect ( "failed to load certificate or private key" ) ;
395
409
let socket_addr = format ! ( "{}:{}" , downstream. listen, downstream. port) ;
396
410
let udp_socket = UdpSocket :: bind ( & socket_addr)
397
411
. await
398
- . with_context ( || format ! ( "failed to bind tcp socket {socket_addr}" ) )
412
+ . with_context ( || format ! ( "failed to bind udp socket {socket_addr}" ) )
399
413
. unwrap_or_else ( |err| panic ! ( "{err:?}" ) ) ;
400
414
server
401
415
. register_quic_listener (
@@ -404,7 +418,25 @@ async fn async_main(config: Config) {
404
418
cert_and_key,
405
419
downstream. dns_hostname
406
420
)
407
- . expect ( "failed to register tls downstream" ) ;
421
+ . expect ( "failed to register quic downstream" ) ;
422
+ } ,
423
+ DownstreamConfig :: H3 ( downstream) => {
424
+ let cert_and_key = downstream
425
+ . load_cert_and_key ( )
426
+ . expect ( "failed to load certificate or private key" ) ;
427
+ let socket_addr = format ! ( "{}:{}" , downstream. listen, downstream. port) ;
428
+ let udp_socket = UdpSocket :: bind ( & socket_addr)
429
+ . await
430
+ . with_context ( || format ! ( "failed to bind udp socket {socket_addr}" ) )
431
+ . unwrap_or_else ( |err| panic ! ( "{err:?}" ) ) ;
432
+ server
433
+ . register_h3_listener (
434
+ udp_socket,
435
+ Duration :: from_millis ( downstream. timeout_ms ) ,
436
+ cert_and_key,
437
+ downstream. dns_hostname
438
+ )
439
+ . expect ( "failed to register h3 downstream" ) ;
408
440
}
409
441
}
410
442
}
@@ -460,7 +492,8 @@ enum DownstreamConfig {
460
492
Udp ( UdpConfig ) ,
461
493
Tls ( TlsConfig ) ,
462
494
Https ( HttpsAndQuicConfig ) ,
463
- Quic ( HttpsAndQuicConfig )
495
+ Quic ( HttpsAndQuicConfig ) ,
496
+ H3 ( HttpsAndQuicConfig )
464
497
}
465
498
466
499
fn default_timeout ( ) -> u64 {
0 commit comments