Skip to content

Commit

Permalink
chore: Add peers reference
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Oct 15, 2023
1 parent bb0e866 commit ac00bdc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
5 changes: 3 additions & 2 deletions extensions/warp-ipfs/src/store/document/identity.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -196,14 +196,15 @@ pub async fn unixfs_fetch(
ipfs: &Ipfs,
cid: Cid,
timeout: Option<Duration>,
peers: &[PeerId],
local: bool,
limit: Option<usize>,
) -> Result<Vec<u8>, Error> {
let timeout = timeout.or(Some(std::time::Duration::from_secs(15)));

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();
Expand Down
5 changes: 3 additions & 2 deletions extensions/warp-ipfs/src/store/document/image_dag.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -102,6 +102,7 @@ pub async fn store_photo(
pub async fn get_image(
ipfs: &Ipfs,
cid: Cid,
peers: &[PeerId],
local: bool,
limit: Option<usize>,
) -> Result<IdentityImage, Error> {
Expand All @@ -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();

Expand Down
30 changes: 22 additions & 8 deletions extensions/warp-ipfs/src/store/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -988,6 +998,7 @@ impl IdentityStore {
let _ = super::document::image_dag::get_image(
&ipfs,
identity_profile_picture,
&[],
false,
Some(2 * 1024 * 1024),
)
Expand Down Expand Up @@ -1036,6 +1047,7 @@ impl IdentityStore {
let _ = super::document::image_dag::get_image(
&ipfs,
identity_profile_banner,
&[],
false,
Some(2 * 1024 * 1024),
)
Expand Down Expand Up @@ -1114,6 +1126,7 @@ impl IdentityStore {
let _ = super::document::image_dag::get_image(
&ipfs,
picture,
&[],
false,
Some(2 * 1024 * 1024),
)
Expand All @@ -1137,6 +1150,7 @@ impl IdentityStore {
let _ = super::document::image_dag::get_image(
&ipfs,
banner,
&[],
false,
Some(2 * 1024 * 1024),
)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ac00bdc

Please sign in to comment.