diff --git a/src/main.rs b/src/main.rs index c2ad756..e8f8cf5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -188,7 +188,7 @@ async fn main() -> Result<(), Box> { loop { if std::env::var("DAEMON_AUTO_UPGRADE") != Ok("OFF".to_string()) { // This upgrade procedure will get replaced in prod. We need this for the testnet. - if let Err(e) = download_and_replace_binary() { + if let Err(e) = download_and_replace_binary().await { log::error!("Failed to upgrade detee-sgx-daemon to newer version: {e}"); } } @@ -244,17 +244,17 @@ fn set_logging() { .init(); } -fn download_and_replace_binary() -> Result<()> { - use reqwest::blocking::get; +async fn download_and_replace_binary() -> Result<()> { + use reqwest::get; use std::os::unix::fs::PermissionsExt; const TMP_DAEMON: &str = "/usr/local/bin/detee/new-daemon"; const BINARY: &str = "/usr/local/bin/detee-sgx-daemon"; - let response = get("https://registry.detee.ltd/sgx/daemon/detee-sgx-daemon")?; + let response = get("https://registry.detee.ltd/sgx/daemon/detee-sgx-daemon").await?; if !response.status().is_success() { return Err(anyhow!("Failed to download file: {}", response.status())); } let mut tmp_file = File::create(Path::new(&TMP_DAEMON))?; - std::io::copy(&mut response.bytes()?.as_ref(), &mut tmp_file)?; + std::io::copy(&mut response.bytes().await?.as_ref(), &mut tmp_file)?; let new_hash = crate::global::compute_sha256(TMP_DAEMON)?; let old_hash = crate::global::compute_sha256(BINARY)?; log::debug!("Old binary hash: {old_hash}. New binary hash: {new_hash}");