File tree 1 file changed +10
-0
lines changed
1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 2
2
use std:: sync:: Arc ;
3
3
4
4
use anyhow:: Result ;
5
+ use once_cell:: sync:: Lazy ;
5
6
6
7
use crate :: net:: session:: SessionStream ;
7
8
9
+ use rustls:: client:: ClientSessionStore ;
10
+
8
11
pub async fn wrap_tls (
9
12
strict_tls : bool ,
10
13
hostname : & str ,
@@ -30,6 +33,10 @@ pub async fn wrap_tls(
30
33
}
31
34
}
32
35
36
+ // This is the default as of version 0.23.16, but make it shared between clients.
37
+ static RESUMPTION_STORE : Lazy < Arc < dyn ClientSessionStore > > =
38
+ Lazy :: new ( || Arc :: new ( rustls:: client:: ClientSessionMemoryCache :: new ( 256 ) ) ) ;
39
+
33
40
pub async fn wrap_rustls (
34
41
hostname : & str ,
35
42
alpn : & [ & str ] ,
@@ -43,6 +50,9 @@ pub async fn wrap_rustls(
43
50
. with_no_client_auth ( ) ;
44
51
config. alpn_protocols = alpn. iter ( ) . map ( |s| s. as_bytes ( ) . to_vec ( ) ) . collect ( ) ;
45
52
53
+ let resumption = rustls:: client:: Resumption :: store ( Arc :: clone ( & RESUMPTION_STORE ) ) ;
54
+ config. resumption = resumption;
55
+
46
56
let tls = tokio_rustls:: TlsConnector :: from ( Arc :: new ( config) ) ;
47
57
let name = rustls_pki_types:: ServerName :: try_from ( hostname) ?. to_owned ( ) ;
48
58
let tls_stream = tls. connect ( name, stream) . await ?;
You can’t perform that action at this time.
0 commit comments