1
+ pub mod client_encryption;
1
2
pub mod options;
2
3
mod state_machine;
3
4
@@ -8,7 +9,6 @@ use std::{
8
9
9
10
use derivative:: Derivative ;
10
11
use mongocrypt:: Crypt ;
11
- use rayon:: ThreadPool ;
12
12
13
13
use crate :: {
14
14
error:: { Error , Result } ,
@@ -26,46 +26,55 @@ use options::{
26
26
EO_MONGOCRYPTD_URI ,
27
27
} ;
28
28
29
+ use self :: state_machine:: CryptExecutor ;
30
+
29
31
use super :: WeakClient ;
30
32
31
33
#[ derive( Derivative ) ]
32
34
#[ derivative( Debug ) ]
33
35
pub ( super ) struct ClientState {
34
36
#[ derivative( Debug = "ignore" ) ]
35
- pub ( crate ) crypt : Crypt ,
36
- mongocryptd_client : Option < Client > ,
37
- aux_clients : AuxClients ,
37
+ crypt : Crypt ,
38
+ exec : CryptExecutor ,
39
+ internal_client : Option < Client > ,
38
40
opts : AutoEncryptionOptions ,
39
- crypto_threads : ThreadPool ,
40
41
}
41
42
42
- #[ derive( Debug ) ]
43
43
struct AuxClients {
44
44
key_vault_client : WeakClient ,
45
45
metadata_client : Option < WeakClient > ,
46
- _internal_client : Option < Client > ,
46
+ internal_client : Option < Client > ,
47
47
}
48
48
49
49
impl ClientState {
50
- pub ( super ) async fn new ( client : & Client , opts : AutoEncryptionOptions ) -> Result < Self > {
50
+ pub ( super ) async fn new ( client : & Client , mut opts : AutoEncryptionOptions ) -> Result < Self > {
51
51
let crypt = Self :: make_crypt ( & opts) ?;
52
52
let mongocryptd_client = Self :: spawn_mongocryptd_if_needed ( & opts, & crypt) . await ?;
53
53
let aux_clients = Self :: make_aux_clients ( client, & opts) ?;
54
- let num_cpus = std:: thread:: available_parallelism ( ) ?. get ( ) ;
55
- let crypto_threads = rayon:: ThreadPoolBuilder :: new ( )
56
- . num_threads ( num_cpus)
57
- . build ( )
58
- . map_err ( |e| Error :: internal ( format ! ( "could not initialize thread pool: {}" , e) ) ) ?;
54
+ let exec = CryptExecutor :: new (
55
+ aux_clients. key_vault_client ,
56
+ opts. key_vault_namespace . clone ( ) ,
57
+ mongocryptd_client,
58
+ aux_clients. metadata_client ,
59
+ opts. tls_options . take ( ) ,
60
+ ) ?;
59
61
60
62
Ok ( Self {
61
63
crypt,
62
- mongocryptd_client ,
63
- aux_clients,
64
+ exec ,
65
+ internal_client : aux_clients. internal_client ,
64
66
opts,
65
- crypto_threads,
66
67
} )
67
68
}
68
69
70
+ pub ( super ) fn crypt ( & self ) -> & Crypt {
71
+ & self . crypt
72
+ }
73
+
74
+ pub ( super ) fn exec ( & self ) -> & CryptExecutor {
75
+ & self . exec
76
+ }
77
+
69
78
pub ( super ) fn opts ( & self ) -> & AutoEncryptionOptions {
70
79
& self . opts
71
80
}
@@ -176,7 +185,7 @@ impl ClientState {
176
185
Ok ( AuxClients {
177
186
key_vault_client,
178
187
metadata_client,
179
- _internal_client : internal_client,
188
+ internal_client,
180
189
} )
181
190
}
182
191
}
0 commit comments