Recursively find all [`Cid`] fields in the [`Block`] structures stored in the [`Blockstore`] and return all CIDs which could *not* be retrieved from the store. This function is available as a convenience, to be used by any [`BitswapStore`] implementation as they see fit.
(
bs: &mut BS,
cid: &Cid,
)
| 13 | /// This function is available as a convenience, to be used by any [`BitswapStore`] |
| 14 | /// implementation as they see fit. |
| 15 | pub fn missing_blocks<BS: Blockstore, P: StoreParams>( |
| 16 | bs: &mut BS, |
| 17 | cid: &Cid, |
| 18 | ) -> anyhow::Result<Vec<Cid>> |
| 19 | where |
| 20 | Ipld: References<<P as StoreParams>::Codecs>, |
| 21 | { |
| 22 | let mut stack = vec![*cid]; |
| 23 | let mut missing = vec![]; |
| 24 | while let Some(cid) = stack.pop() { |
| 25 | if let Some(data) = bs.get(&cid)? { |
| 26 | let block = libipld::Block::<P>::new_unchecked(cid, data); |
| 27 | block.references(&mut stack)?; |
| 28 | } else { |
| 29 | missing.push(cid); |
| 30 | } |
| 31 | } |
| 32 | Ok(missing) |
| 33 | } |