diff --git a/car-mirror/src/common.rs b/car-mirror/src/common.rs index acbd0bf..900aa32 100644 --- a/car-mirror/src/common.rs +++ b/car-mirror/src/common.rs @@ -207,13 +207,12 @@ pub async fn block_receive( /// This will error out if /// - the codec is not supported /// - the block can't be parsed. -pub fn references(cid: Cid, block: impl AsRef<[u8]>) -> Result> { +pub fn references>(cid: Cid, block: impl AsRef<[u8]>, mut refs: E) -> Result { let codec: IpldCodec = cid .codec() .try_into() .map_err(|_| anyhow!("Unsupported codec in Cid: {cid}"))?; - let mut refs = Vec::new(); >::references(codec, &mut Cursor::new(block), &mut refs)?; Ok(refs) } diff --git a/car-mirror/src/dag_walk.rs b/car-mirror/src/dag_walk.rs index 9050648..3b45c69 100644 --- a/car-mirror/src/dag_walk.rs +++ b/car-mirror/src/dag_walk.rs @@ -76,7 +76,7 @@ impl DagWalk { // - skip Raw CIDs. They can't have further links (but needs adjustment to this function's return type) // - run multiple `get_block` calls concurrently let block = store.get_block(&cid).await?; - for ref_cid in references(cid, &block)? { + for ref_cid in references(cid, &block, HashSet::new())? { if !self.visited.contains(&ref_cid) { self.frontier.push_front(ref_cid); } @@ -112,7 +112,7 @@ impl DagWalk { /// Skip a node from the traversal for now. pub fn skip_walking(&mut self, block: (Cid, Bytes)) -> Result<()> { let (cid, bytes) = block; - let refs = references(cid, bytes)?; + let refs = references(cid, bytes, HashSet::new())?; self.visited.insert(cid); self.frontier .retain(|frontier_cid| !refs.contains(frontier_cid)); diff --git a/car-mirror/src/test_utils/blockstore_utils.rs b/car-mirror/src/test_utils/blockstore_utils.rs index 1bcd9e5..3394271 100644 --- a/car-mirror/src/test_utils/blockstore_utils.rs +++ b/car-mirror/src/test_utils/blockstore_utils.rs @@ -37,7 +37,7 @@ pub fn dag_to_dot( for (cid, ipld) in blocks { let bytes = encode(&ipld)?; - let refs = references(cid, bytes)?; + let refs = references(cid, bytes, Vec::new())?; for to_cid in refs { print_truncated_string(writer, cid.to_string())?; write!(writer, " -> ")?; diff --git a/car-mirror/src/test_utils/local_utils.rs b/car-mirror/src/test_utils/local_utils.rs index 5c7323f..51f021d 100644 --- a/car-mirror/src/test_utils/local_utils.rs +++ b/car-mirror/src/test_utils/local_utils.rs @@ -24,7 +24,7 @@ pub(crate) async fn get_cid_at_approx_path( let mut working_cid = root; for nth in path { let block = store.get_block(&working_cid).await?; - let refs = references(working_cid, block)?; + let refs = references(working_cid, block, Vec::new())?; if refs.is_empty() { break; }