Skip to content

Commit

Permalink
util: Remove unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Nov 23, 2024
1 parent 8da2d14 commit 01cc779
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 31 deletions.
5 changes: 2 additions & 3 deletions src/transfer/cancel.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down Expand Up @@ -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<Output = ()>, cancel: impl Future<Output = ()>) {
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(())) => {},
Expand Down Expand Up @@ -157,7 +156,7 @@ pub async fn handle_run_result_noclose<T, C: Future<Output = ()>>(
// 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?");
Expand Down
30 changes: 16 additions & 14 deletions src/transit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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(),
)
Expand Down Expand Up @@ -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!(
Expand All @@ -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
{
Expand Down Expand Up @@ -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(),
)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 0 additions & 14 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F, T>(
duration: std::time::Duration,
future: F,
) -> Result<T, async_std::future::TimeoutError>
where
F: futures::Future<Output = T>,
{
async_std::future::timeout(duration, future).await
}

0 comments on commit 01cc779

Please sign in to comment.