Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions availability-oracle/src/ipfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,11 @@ impl IpfsImpl {
}
}

async fn call(&self, route: &'static str, arg: Cid) -> Result<reqwest::Response, IpfsError> {
async fn call(&self, cid: Cid) -> Result<reqwest::Response, IpfsError> {
let _permit = self.semaphore.acquire().await;

// URL security: We control the endpoint and the route, the `arg` is a CID.
let url = format!(
"{}/api/v0/{}?arg={}",
self.endpoint.trim_end_matches('/'),
route,
arg
);
// Using standard IPFS gateway URL format
let url = format!("{}/ipfs/{}", self.endpoint.trim_end_matches('/'), cid);
self.client
.get(&url)
.timeout(self.timeout)
Expand All @@ -67,10 +62,10 @@ impl IpfsImpl {
.and_then(|x| x)
.map_err(|e| match e.status().map(|e| e.as_u16()) {
Some(GATEWAY_TIMEOUT) | Some(CLOUDFLARE_TIMEOUT) => {
IpfsError::GatewayTimeout(arg, e.into())
IpfsError::GatewayTimeout(cid, e.into())
}
_ if e.is_timeout() => IpfsError::ClientTimeout(arg, e.into()),
Some(NOT_FOUND) => IpfsError::NotFound(arg, e.into()),
_ if e.is_timeout() => IpfsError::ClientTimeout(cid, e.into()),
Some(NOT_FOUND) => IpfsError::NotFound(cid, e.into()),
_ => IpfsError::Other(e.into()),
})
}
Expand All @@ -97,7 +92,7 @@ impl Ipfs for IpfsImpl {
) -> Result<reqwest::Response, IpfsError> {
let mut last_err = None;
for _ in 0..=retries {
match ipfs.call("cat", cid).await {
match ipfs.call(cid).await {
Ok(res) => return Ok(res),
Err(e) => {
last_err = Some(e);
Expand Down