From 01cc779cc7f8043d61ff9c3c3926bedf6d6a7d9b Mon Sep 17 00:00:00 2001 From: Fina Wilke Date: Sat, 23 Nov 2024 22:02:59 +0100 Subject: [PATCH] util: Remove unused functions --- src/transfer/cancel.rs | 5 ++--- src/transit.rs | 30 ++++++++++++++++-------------- src/util.rs | 14 -------------- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/transfer/cancel.rs b/src/transfer/cancel.rs index 6883e061..ba822f1d 100644 --- a/src/transfer/cancel.rs +++ b/src/transfer/cancel.rs @@ -1,6 +1,5 @@ /// Various helpers to deal with closing connections and cancellation use super::*; -use crate::util; /// A weird mixture of [`futures::future::Abortable`], [`async_std::sync::Condvar`] and [`futures::future::Select`] tailored to our Ctrl+C handling. /// @@ -83,7 +82,7 @@ pub(super) use with_cancel_transit; /// Run a future with timeout and cancellation, ignore errors async fn wrap_timeout(run: impl Future, cancel: impl Future) { - let run = util::timeout(SHUTDOWN_TIME, run); + let run = async_std::future::timeout(SHUTDOWN_TIME, run); futures::pin_mut!(run); match cancellable(run, cancel).await { Ok(Ok(())) => {}, @@ -157,7 +156,7 @@ pub async fn handle_run_result_noclose>( // and we should not only look for the next one but all have been received // and we should not interrupt a receive operation without making sure it leaves the connection // in a consistent state, otherwise the shutdown may cause protocol errors - if let Ok(Ok(Ok(PeerMessage::Error(e)))) = util::timeout(SHUTDOWN_TIME / 3, wormhole.receive_json()).await { + if let Ok(Ok(Ok(PeerMessage::Error(e)))) = async_std::future::timeout(SHUTDOWN_TIME / 3, wormhole.receive_json()).await { error = TransferError::PeerError(e); } else { tracing::debug!("Failed to retrieve more specific error message from peer. Maybe it crashed?"); diff --git a/src/transit.rs b/src/transit.rs index 3829fe42..e0edc881 100644 --- a/src/transit.rs +++ b/src/transit.rs @@ -14,7 +14,7 @@ //! "leader" side and one "follower" side (formerly called "sender" and "receiver"). #[allow(deprecated)] -use crate::{util, Key, KeyPurpose}; +use crate::{Key, KeyPurpose}; use serde_derive::{Deserialize, Serialize}; #[cfg(not(target_family = "wasm"))] @@ -797,7 +797,7 @@ pub async fn init( * so that we will be NATted to the same port again. If it doesn't, simply bind a new socket * and use that instead. */ - let socket: MaybeConnectedSocket = match util::timeout( + let socket: MaybeConnectedSocket = match async_std::future::timeout( std::time::Duration::from_secs(4), transport::tcp_get_external_ip(), ) @@ -1008,14 +1008,16 @@ impl TransitConnector { }), ); - let (mut transit, mut finalizer, mut conn_info) = - util::timeout(std::time::Duration::from_secs(60), connection_stream.next()) - .await - .map_err(|_| { - tracing::debug!("`leader_connect` timed out"); - TransitConnectError::Handshake - })? - .ok_or(TransitConnectError::Handshake)?; + let (mut transit, mut finalizer, mut conn_info) = async_std::future::timeout( + std::time::Duration::from_secs(60), + connection_stream.next(), + ) + .await + .map_err(|_| { + tracing::debug!("`leader_connect` timed out"); + TransitConnectError::Handshake + })? + .ok_or(TransitConnectError::Handshake)?; if conn_info.conn_type != ConnectionType::Direct && our_abilities.can_direct() { tracing::debug!( @@ -1031,7 +1033,7 @@ impl TransitConnector { } else { elapsed.mul_f32(0.3) }; - let _ = util::timeout(to_wait, async { + let _ = async_std::future::timeout(to_wait, async { while let Some((new_transit, new_finalizer, new_conn_info)) = connection_stream.next().await { @@ -1113,7 +1115,7 @@ impl TransitConnector { }), ); - let transit = match util::timeout( + let transit = match async_std::future::timeout( std::time::Duration::from_secs(60), &mut connection_stream.next(), ) @@ -1260,7 +1262,7 @@ impl TransitConnector { .map(move |(i, h)| (i, h, name.clone())) }) .map(|(index, host, name)| async move { - util::sleep(std::time::Duration::from_secs( + async_std::task::sleep(std::time::Duration::from_secs( index as u64 * 5, )) .await; @@ -1304,7 +1306,7 @@ impl TransitConnector { .map(move |(i, u)| (i, u, name.clone())) }) .map(|(index, url, name)| async move { - util::sleep(std::time::Duration::from_secs( + async_std::task::sleep(std::time::Duration::from_secs( index as u64 * 5, )) .await; diff --git a/src/util.rs b/src/util.rs index 14b84709..74649ea5 100644 --- a/src/util.rs +++ b/src/util.rs @@ -175,17 +175,3 @@ pub fn hashcash(resource: String, bits: u32) -> String { } } } - -pub async fn sleep(duration: std::time::Duration) { - async_std::task::sleep(duration).await -} - -pub async fn timeout( - duration: std::time::Duration, - future: F, -) -> Result -where - F: futures::Future, -{ - async_std::future::timeout(duration, future).await -}