From ac00bdc1268ba182c0d049a1dcbfafa65185a090 Mon Sep 17 00:00:00 2001 From: Darius Date: Sun, 15 Oct 2023 18:56:40 -0400 Subject: [PATCH] chore: Add peers reference --- .../warp-ipfs/src/store/document/identity.rs | 5 ++-- .../warp-ipfs/src/store/document/image_dag.rs | 5 ++-- extensions/warp-ipfs/src/store/identity.rs | 30 ++++++++++++++----- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/extensions/warp-ipfs/src/store/document/identity.rs b/extensions/warp-ipfs/src/store/document/identity.rs index b2d397483..0e74d1d08 100644 --- a/extensions/warp-ipfs/src/store/document/identity.rs +++ b/extensions/warp-ipfs/src/store/document/identity.rs @@ -1,7 +1,7 @@ use chrono::{DateTime, Utc}; use futures::{StreamExt, TryStreamExt}; use libipld::Cid; -use rust_ipfs::{Ipfs, IpfsPath}; +use rust_ipfs::{Ipfs, IpfsPath, PeerId}; use serde::{Deserialize, Serialize}; use std::{hash::Hash, time::Duration}; use warp::{ @@ -196,6 +196,7 @@ pub async fn unixfs_fetch( ipfs: &Ipfs, cid: Cid, timeout: Option, + peers: &[PeerId], local: bool, limit: Option, ) -> Result, Error> { @@ -203,7 +204,7 @@ pub async fn unixfs_fetch( let mut stream = ipfs .unixfs() - .cat(IpfsPath::from(cid), None, &[], local, timeout) + .cat(IpfsPath::from(cid), None, peers, local, timeout) .await .map_err(anyhow::Error::from)? .boxed(); diff --git a/extensions/warp-ipfs/src/store/document/image_dag.rs b/extensions/warp-ipfs/src/store/document/image_dag.rs index c162b4a4d..93d11bb54 100644 --- a/extensions/warp-ipfs/src/store/document/image_dag.rs +++ b/extensions/warp-ipfs/src/store/document/image_dag.rs @@ -1,6 +1,6 @@ use futures::{stream::BoxStream, StreamExt}; use libipld::{serde::to_ipld, Cid}; -use rust_ipfs::Ipfs; +use rust_ipfs::{Ipfs, PeerId}; use serde::{Deserialize, Serialize}; use std::task::Poll; use tracing::log; @@ -102,6 +102,7 @@ pub async fn store_photo( pub async fn get_image( ipfs: &Ipfs, cid: Cid, + peers: &[PeerId], local: bool, limit: Option, ) -> Result { @@ -110,7 +111,7 @@ pub async fn get_image( false => cid.get_dag(&ipfs, None).await?, }; - let image = unixfs_fetch(ipfs, dag.link, None, local, limit).await?; + let image = unixfs_fetch(ipfs, dag.link, None, peers, local, limit).await?; let mut id_img = IdentityImage::default(); diff --git a/extensions/warp-ipfs/src/store/identity.rs b/extensions/warp-ipfs/src/store/identity.rs index e192c41d7..b0ea00c3c 100644 --- a/extensions/warp-ipfs/src/store/identity.rs +++ b/extensions/warp-ipfs/src/store/identity.rs @@ -792,9 +792,14 @@ impl IdentityStore { return Ok(()); } - let image = - super::document::image_dag::get_image(&self.ipfs, cid, true, Some(2 * 1024 * 1024)) - .await?; + let image = super::document::image_dag::get_image( + &self.ipfs, + cid, + &[], + true, + Some(2 * 1024 * 1024), + ) + .await?; let event = IdentityEvent::Receive { option: ResponseOption::Image { @@ -844,9 +849,14 @@ impl IdentityStore { return Ok(()); } - let image = - super::document::image_dag::get_image(&self.ipfs, cid, true, Some(2 * 1024 * 1024)) - .await?; + let image = super::document::image_dag::get_image( + &self.ipfs, + cid, + &[], + true, + Some(2 * 1024 * 1024), + ) + .await?; let event = IdentityEvent::Receive { option: ResponseOption::Image { @@ -988,6 +998,7 @@ impl IdentityStore { let _ = super::document::image_dag::get_image( &ipfs, identity_profile_picture, + &[], false, Some(2 * 1024 * 1024), ) @@ -1036,6 +1047,7 @@ impl IdentityStore { let _ = super::document::image_dag::get_image( &ipfs, identity_profile_banner, + &[], false, Some(2 * 1024 * 1024), ) @@ -1114,6 +1126,7 @@ impl IdentityStore { let _ = super::document::image_dag::get_image( &ipfs, picture, + &[], false, Some(2 * 1024 * 1024), ) @@ -1137,6 +1150,7 @@ impl IdentityStore { let _ = super::document::image_dag::get_image( &ipfs, banner, + &[], false, Some(2 * 1024 * 1024), ) @@ -1599,7 +1613,7 @@ impl IdentityStore { }; if let Some(cid) = document.profile_picture { - let data = match get_image(&self.ipfs, cid, true, Some(2 * 1024 * 1024)).await { + let data = match get_image(&self.ipfs, cid, &[], true, Some(2 * 1024 * 1024)).await { Ok(data) => data, Err(_) => { return Err(Error::InvalidIdentityPicture); @@ -1634,7 +1648,7 @@ impl IdentityStore { }; if let Some(cid) = document.profile_banner { - let data = match get_image(&self.ipfs, cid, true, Some(2 * 1024 * 1024)).await { + let data = match get_image(&self.ipfs, cid, &[], true, Some(2 * 1024 * 1024)).await { Ok(data) => data, Err(_) => { return Err(Error::InvalidIdentityPicture);