Skip to content

Commit 86239cf

Browse files
committed
Prefactor: move client construction out to VssStore
While having it in `VssStoreInner` makes more sense, we now opt to construt the client (soon, clients) in `VssStore` and then hand it down to `VssStoreInner`. That will allow us to use the client once for checking the schema version before actually instantiating `VssStoreInner`.
1 parent 65f6f7b commit 86239cf

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

src/io/vss_store.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ impl VssStore {
8282
base_url: String, store_id: String, vss_seed: [u8; 32],
8383
header_provider: Arc<dyn VssHeaderProvider>, runtime: Arc<Runtime>,
8484
) -> Self {
85-
let inner = Arc::new(VssStoreInner::new(base_url, store_id, vss_seed, header_provider));
8685
let next_version = AtomicU64::new(1);
8786
let internal_runtime = Some(
8887
tokio::runtime::Builder::new_multi_thread()
@@ -98,6 +97,33 @@ impl VssStore {
9897
.unwrap(),
9998
);
10099

100+
let schema_version = VssSchemaVersion::V0;
101+
let (data_encryption_key, obfuscation_master_key) =
102+
derive_data_encryption_and_obfuscation_keys(&vss_seed);
103+
let key_obfuscator = KeyObfuscator::new(obfuscation_master_key);
104+
let retry_policy = ExponentialBackoffRetryPolicy::new(Duration::from_millis(10))
105+
.with_max_attempts(10)
106+
.with_max_total_delay(Duration::from_secs(15))
107+
.with_max_jitter(Duration::from_millis(10))
108+
.skip_retry_on_error(Box::new(|e: &VssError| {
109+
matches!(
110+
e,
111+
VssError::NoSuchKeyError(..)
112+
| VssError::InvalidRequestError(..)
113+
| VssError::ConflictError(..)
114+
)
115+
}) as _);
116+
117+
let client = VssClient::new_with_headers(base_url, retry_policy, header_provider);
118+
119+
let inner = Arc::new(VssStoreInner::new(
120+
schema_version,
121+
client,
122+
store_id,
123+
data_encryption_key,
124+
key_obfuscator,
125+
));
126+
101127
Self { inner, next_version, runtime, internal_runtime }
102128
}
103129

@@ -341,27 +367,9 @@ struct VssStoreInner {
341367

342368
impl VssStoreInner {
343369
pub(crate) fn new(
344-
base_url: String, store_id: String, vss_seed: [u8; 32],
345-
header_provider: Arc<dyn VssHeaderProvider>,
370+
schema_version: VssSchemaVersion, client: VssClient<CustomRetryPolicy>, store_id: String,
371+
data_encryption_key: [u8; 32], key_obfuscator: KeyObfuscator,
346372
) -> Self {
347-
let schema_version = VssSchemaVersion::V0;
348-
let (data_encryption_key, obfuscation_master_key) =
349-
derive_data_encryption_and_obfuscation_keys(&vss_seed);
350-
let key_obfuscator = KeyObfuscator::new(obfuscation_master_key);
351-
let retry_policy = ExponentialBackoffRetryPolicy::new(Duration::from_millis(10))
352-
.with_max_attempts(10)
353-
.with_max_total_delay(Duration::from_secs(15))
354-
.with_max_jitter(Duration::from_millis(10))
355-
.skip_retry_on_error(Box::new(|e: &VssError| {
356-
matches!(
357-
e,
358-
VssError::NoSuchKeyError(..)
359-
| VssError::InvalidRequestError(..)
360-
| VssError::ConflictError(..)
361-
)
362-
}) as _);
363-
364-
let client = VssClient::new_with_headers(base_url, retry_policy, header_provider);
365373
let locks = Mutex::new(HashMap::new());
366374
let pending_lazy_deletes = Mutex::new(Vec::new());
367375
Self {

0 commit comments

Comments
 (0)