Skip to content

Commit f46aa66

Browse files
committed
fix: use timeout in DIPs IPFS client
1 parent afc50dc commit f46aa66

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

crates/dips/src/ipfs.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::sync::Arc;
4+
use std::{sync::Arc, time::Duration};
55

66
use async_trait::async_trait;
77
use derivative::Derivative;
88
use futures::TryStreamExt;
9-
use ipfs_api_backend_hyper::{IpfsApi, TryFromUri};
9+
use ipfs_api_backend_hyper::{BackendWithGlobalOptions, GlobalOptions, IpfsApi, TryFromUri};
1010
use serde::Deserialize;
1111

1212
use crate::DipsError;
@@ -27,12 +27,16 @@ impl<T: IpfsFetcher> IpfsFetcher for Arc<T> {
2727
#[derivative(Debug)]
2828
pub struct IpfsClient {
2929
#[derivative(Debug = "ignore")]
30-
client: ipfs_api_backend_hyper::IpfsClient,
30+
client: ipfs_api_backend_hyper::BackendWithGlobalOptions<IpfsClient>,
3131
}
3232

3333
impl IpfsClient {
3434
pub fn new(url: &str) -> anyhow::Result<Self> {
35-
let client = ipfs_api_backend_hyper::IpfsClient::from_str(url)?;
35+
let opts = GlobalOptions {
36+
timeout: Some(Duration::from_secs(30)),
37+
};
38+
let backend = ipfs_api_backend_hyper::IpfsClient::from_str(url)?;
39+
let client = BackendWithGlobalOptions::new(backend, opts);
3640
Ok(Self { client })
3741
}
3842
}

0 commit comments

Comments
 (0)