Skip to content

Commit

Permalink
fix: unixfs seeking (#606)
Browse files Browse the repository at this point in the history
* feat: Refactor unixfs

* pr: fixes

* fix: Document fix and correct default for absent gateway path

* feat: Skip blocks on seeking
  • Loading branch information
ppodolsky authored Dec 19, 2022
1 parent 6e9dae2 commit 51e3ddf
Show file tree
Hide file tree
Showing 23 changed files with 475 additions and 404 deletions.
5 changes: 2 additions & 3 deletions iroh-api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use iroh_rpc_client::{Client, ClientStatus};
use iroh_unixfs::{
builder::Entry as UnixfsEntry,
content_loader::{FullLoader, FullLoaderConfig},
ResponseClip,
};
use iroh_util::{iroh_config_path, make_config};
#[cfg(feature = "testing")]
Expand Down Expand Up @@ -152,13 +151,13 @@ impl Api {
if out.is_dir() {
yield (relative_path, OutType::Dir);
} else if out.is_symlink() {
let mut reader = out.pretty(resolver.clone(), Default::default(), ResponseClip::NoClip)?;
let mut reader = out.pretty(resolver.clone(), Default::default(), None)?;
let mut target = String::new();
reader.read_to_string(&mut target).await?;
let target = PathBuf::from(target);
yield (relative_path, OutType::Symlink(target));
} else {
let reader = out.pretty(resolver.clone(), Default::default(), ResponseClip::NoClip)?;
let reader = out.pretty(resolver.clone(), Default::default(), None)?;
yield (relative_path, OutType::Reader(Box::new(reader)));
}
}
Expand Down
14 changes: 7 additions & 7 deletions iroh-gateway/src/bad_bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ mod tests {
let uri = hyper::Uri::builder()
.scheme("http")
.authority(format!("localhost:{}", addr.port()))
.path_and_query(format!("/ipfs/{}", bad_cid))
.path_and_query(format!("/ipfs/{bad_cid}"))
.build()
.unwrap();
let client = hyper::Client::new();
Expand All @@ -228,7 +228,7 @@ mod tests {
let uri = hyper::Uri::builder()
.scheme("http")
.authority(format!("localhost:{}", addr.port()))
.path_and_query(format!("/ipfs/{}/{}", bad_cid, bad_path))
.path_and_query(format!("/ipfs/{bad_cid}/{bad_path}"))
.build()
.unwrap();
let client = hyper::Client::new();
Expand All @@ -238,7 +238,7 @@ mod tests {
let uri = hyper::Uri::builder()
.scheme("http")
.authority(format!("localhost:{}", addr.port()))
.path_and_query(format!("/ipfs/{}/{}", bad_cid_2, bad_path))
.path_and_query(format!("/ipfs/{bad_cid_2}/{bad_path}"))
.build()
.unwrap();
let client = hyper::Client::new();
Expand All @@ -249,7 +249,7 @@ mod tests {
let uri = hyper::Uri::builder()
.scheme("http")
.authority(format!("localhost:{}", addr.port()))
.path_and_query(format!("/ipfs/{}/{}?format=raw", bad_cid_2, bad_path))
.path_and_query(format!("/ipfs/{bad_cid_2}/{bad_path}?format=raw"))
.build()
.unwrap();
let client = hyper::Client::new();
Expand All @@ -260,7 +260,7 @@ mod tests {
let uri = hyper::Uri::builder()
.scheme("http")
.authority(format!("localhost:{}", addr.port()))
.path_and_query(format!("/ipfs/{}/{}", bad_cid, good_path))
.path_and_query(format!("/ipfs/{bad_cid}/{good_path}"))
.build()
.unwrap();
let client = hyper::Client::new();
Expand All @@ -270,7 +270,7 @@ mod tests {
let uri = hyper::Uri::builder()
.scheme("http")
.authority(format!("localhost:{}", addr.port()))
.path_and_query(format!("/ipfs/{}/{}", bad_cid_2, good_path))
.path_and_query(format!("/ipfs/{bad_cid_2}/{good_path}"))
.build()
.unwrap();
let client = hyper::Client::new();
Expand All @@ -280,7 +280,7 @@ mod tests {
let uri = hyper::Uri::builder()
.scheme("http")
.authority(format!("localhost:{}", addr.port()))
.path_and_query(format!("/ipfs/{}", good_cid))
.path_and_query(format!("/ipfs/{good_cid}"))
.build()
.unwrap();
let client = hyper::Client::new();
Expand Down
10 changes: 3 additions & 7 deletions iroh-gateway/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use iroh_metrics::{
};
use iroh_resolver::dns_resolver::Config;
use iroh_resolver::resolver::{CidOrDomain, Metadata, Out, OutPrettyReader, OutType, Resolver};
use iroh_unixfs::{content_loader::ContentLoader, ResponseClip, Source};
use iroh_unixfs::{content_loader::ContentLoader, Source};
use mime::Mime;
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncSeekExt, AsyncWrite};
use tokio_util::io::ReaderStream;
Expand Down Expand Up @@ -120,15 +120,11 @@ impl<T: ContentLoader + std::marker::Unpin> Client<T> {
let body = FileResult::Directory(path_metadata);
Ok((body, metadata))
} else {
let mut clip = 0;
if let Some(range) = &range {
clip = range.end as usize;
}
let reader = path_metadata
.pretty(
self.resolver.clone(),
OutMetrics { start: start_time },
ResponseClip::from(clip),
range.as_ref().map(|range| range.end as usize),
)
.map_err(|e| e.to_string())?;

Expand Down Expand Up @@ -194,7 +190,7 @@ impl<T: ContentLoader + std::marker::Unpin> Client<T> {
let reader = res.pretty(
self.resolver.clone(),
OutMetrics { start: start_time },
ResponseClip::NoClip,
None,
);
match reader {
Ok(mut reader) => {
Expand Down
Loading

0 comments on commit 51e3ddf

Please sign in to comment.