Only force a state update if necessary

pull/5/head
Frank Denis 5 years ago
parent 56a8e2eb6a
commit 267a260801

@ -496,19 +496,19 @@ fn main() -> Result<(), Error> {
warn!("Key successfully imported"); warn!("Key successfully imported");
} }
let state = match State::from_file(state_file, key_cache_capacity) { let (state, state_is_new) = match State::from_file(state_file, key_cache_capacity) {
Err(_) => { Err(_) => {
warn!("No state file found... creating a new provider key"); warn!("No state file found... creating a new provider key");
let state = State::new(key_cache_capacity); let state = State::new(key_cache_capacity);
runtime.block_on(state.async_save(state_file))?; runtime.block_on(state.async_save(state_file))?;
state (state, true)
} }
Ok(state) => { Ok(state) => {
info!( info!(
"State file [{}] found; using existing provider key", "State file [{}] found; using existing provider key",
state_file.as_os_str().to_string_lossy() state_file.as_os_str().to_string_lossy()
); );
state (state, false)
} }
}; };
let provider_kp = state.provider_kp; let provider_kp = state.provider_kp;
@ -569,7 +569,9 @@ fn main() -> Result<(), Error> {
cache: Arc::new(Mutex::new(cache)), cache: Arc::new(Mutex::new(cache)),
}); });
let updater = DNSCryptEncryptionParamsUpdater::new(globals.clone()); let updater = DNSCryptEncryptionParamsUpdater::new(globals.clone());
updater.update(); if !state_is_new {
updater.update();
}
runtime.spawn(updater.run()); runtime.spawn(updater.run());
runtime.spawn(start(globals, runtime.clone()).map(|_| ())); runtime.spawn(start(globals, runtime.clone()).map(|_| ()));
runtime.block_on(future::pending::<()>()); runtime.block_on(future::pending::<()>());

Loading…
Cancel
Save