Skip to content

Commit 01cc779

Browse files
committed
util: Remove unused functions
1 parent 8da2d14 commit 01cc779

File tree

3 files changed

+18
-31
lines changed

3 files changed

+18
-31
lines changed

src/transfer/cancel.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// Various helpers to deal with closing connections and cancellation
22
use super::*;
3-
use crate::util;
43

54
/// A weird mixture of [`futures::future::Abortable`], [`async_std::sync::Condvar`] and [`futures::future::Select`] tailored to our Ctrl+C handling.
65
///
@@ -83,7 +82,7 @@ pub(super) use with_cancel_transit;
8382

8483
/// Run a future with timeout and cancellation, ignore errors
8584
async fn wrap_timeout(run: impl Future<Output = ()>, cancel: impl Future<Output = ()>) {
86-
let run = util::timeout(SHUTDOWN_TIME, run);
85+
let run = async_std::future::timeout(SHUTDOWN_TIME, run);
8786
futures::pin_mut!(run);
8887
match cancellable(run, cancel).await {
8988
Ok(Ok(())) => {},
@@ -157,7 +156,7 @@ pub async fn handle_run_result_noclose<T, C: Future<Output = ()>>(
157156
// and we should not only look for the next one but all have been received
158157
// and we should not interrupt a receive operation without making sure it leaves the connection
159158
// in a consistent state, otherwise the shutdown may cause protocol errors
160-
if let Ok(Ok(Ok(PeerMessage::Error(e)))) = util::timeout(SHUTDOWN_TIME / 3, wormhole.receive_json()).await {
159+
if let Ok(Ok(Ok(PeerMessage::Error(e)))) = async_std::future::timeout(SHUTDOWN_TIME / 3, wormhole.receive_json()).await {
161160
error = TransferError::PeerError(e);
162161
} else {
163162
tracing::debug!("Failed to retrieve more specific error message from peer. Maybe it crashed?");

src/transit.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! "leader" side and one "follower" side (formerly called "sender" and "receiver").
1515
1616
#[allow(deprecated)]
17-
use crate::{util, Key, KeyPurpose};
17+
use crate::{Key, KeyPurpose};
1818
use serde_derive::{Deserialize, Serialize};
1919

2020
#[cfg(not(target_family = "wasm"))]
@@ -797,7 +797,7 @@ pub async fn init(
797797
* so that we will be NATted to the same port again. If it doesn't, simply bind a new socket
798798
* and use that instead.
799799
*/
800-
let socket: MaybeConnectedSocket = match util::timeout(
800+
let socket: MaybeConnectedSocket = match async_std::future::timeout(
801801
std::time::Duration::from_secs(4),
802802
transport::tcp_get_external_ip(),
803803
)
@@ -1008,14 +1008,16 @@ impl TransitConnector {
10081008
}),
10091009
);
10101010

1011-
let (mut transit, mut finalizer, mut conn_info) =
1012-
util::timeout(std::time::Duration::from_secs(60), connection_stream.next())
1013-
.await
1014-
.map_err(|_| {
1015-
tracing::debug!("`leader_connect` timed out");
1016-
TransitConnectError::Handshake
1017-
})?
1018-
.ok_or(TransitConnectError::Handshake)?;
1011+
let (mut transit, mut finalizer, mut conn_info) = async_std::future::timeout(
1012+
std::time::Duration::from_secs(60),
1013+
connection_stream.next(),
1014+
)
1015+
.await
1016+
.map_err(|_| {
1017+
tracing::debug!("`leader_connect` timed out");
1018+
TransitConnectError::Handshake
1019+
})?
1020+
.ok_or(TransitConnectError::Handshake)?;
10191021

10201022
if conn_info.conn_type != ConnectionType::Direct && our_abilities.can_direct() {
10211023
tracing::debug!(
@@ -1031,7 +1033,7 @@ impl TransitConnector {
10311033
} else {
10321034
elapsed.mul_f32(0.3)
10331035
};
1034-
let _ = util::timeout(to_wait, async {
1036+
let _ = async_std::future::timeout(to_wait, async {
10351037
while let Some((new_transit, new_finalizer, new_conn_info)) =
10361038
connection_stream.next().await
10371039
{
@@ -1113,7 +1115,7 @@ impl TransitConnector {
11131115
}),
11141116
);
11151117

1116-
let transit = match util::timeout(
1118+
let transit = match async_std::future::timeout(
11171119
std::time::Duration::from_secs(60),
11181120
&mut connection_stream.next(),
11191121
)
@@ -1260,7 +1262,7 @@ impl TransitConnector {
12601262
.map(move |(i, h)| (i, h, name.clone()))
12611263
})
12621264
.map(|(index, host, name)| async move {
1263-
util::sleep(std::time::Duration::from_secs(
1265+
async_std::task::sleep(std::time::Duration::from_secs(
12641266
index as u64 * 5,
12651267
))
12661268
.await;
@@ -1304,7 +1306,7 @@ impl TransitConnector {
13041306
.map(move |(i, u)| (i, u, name.clone()))
13051307
})
13061308
.map(|(index, url, name)| async move {
1307-
util::sleep(std::time::Duration::from_secs(
1309+
async_std::task::sleep(std::time::Duration::from_secs(
13081310
index as u64 * 5,
13091311
))
13101312
.await;

src/util.rs

-14
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,3 @@ pub fn hashcash(resource: String, bits: u32) -> String {
175175
}
176176
}
177177
}
178-
179-
pub async fn sleep(duration: std::time::Duration) {
180-
async_std::task::sleep(duration).await
181-
}
182-
183-
pub async fn timeout<F, T>(
184-
duration: std::time::Duration,
185-
future: F,
186-
) -> Result<T, async_std::future::TimeoutError>
187-
where
188-
F: futures::Future<Output = T>,
189-
{
190-
async_std::future::timeout(duration, future).await
191-
}

0 commit comments

Comments
 (0)