···11//! Consume a CAR from an AsyncRead, producing an ordered stream of records
2233+use crate::link::ObjectLink;
34use crate::{
45 Bytes, HashMap, Rkey, Step,
56 disk::{DiskError, DiskStore},
67 mst::MstNode,
77- walk::Output,
88+ walk::{MstError, Output},
89};
910use cid::Cid;
1011use iroh_car::CarReader;
···3334 ChannelSendError, // SendError takes <T> which we don't need
3435 #[error("Failed to join a task: {0}")]
3536 JoinError(#[from] tokio::task::JoinError),
3737+}
3838+3939+impl From<MstError> for DriveError {
4040+ fn from(me: MstError) -> DriveError {
4141+ DriveError::WalkError(WalkError::MstError(me))
4242+ }
3643}
37443845/// An in-order chunk of Rkey + CID + (processed) Block
···209216210217 // stash (maybe processed) blocks in memory as long as we have room
211218 mem_size += maybe_processed.len();
212212- mem_blocks.insert(cid, maybe_processed);
219219+ mem_blocks.insert(cid.into(), maybe_processed);
213220 if mem_size >= max_size {
214221 return Ok(Driver::Disk(NeedDisk {
215222 car,
···227234228235 // the commit always must point to a Node; empty node => empty MST special case
229236 let root_node: MstNode = match mem_blocks
230230- .get(&commit.data)
237237+ .get(&commit.data_link()?)
231238 .ok_or(DriveError::MissingCommit)?
232239 {
233240 MaybeProcessedBlock::Processed(_) => Err(WalkError::BadCommitFingerprint)?,
···262269/// so the sync/async boundaries become a little easier to work around.
263270#[derive(Debug)]
264271pub struct MemDriver {
265265- blocks: HashMap<Cid, MaybeProcessedBlock>,
272272+ blocks: HashMap<ObjectLink, MaybeProcessedBlock>,
266273 walker: Walker,
267274 process: fn(Bytes) -> Bytes,
268275}
···273280 let mut out = Vec::with_capacity(n);
274281 for _ in 0..n {
275282 // walk as far as we can until we run out of blocks or find a record
276276- let Step::Value(output) = self.walker.step(&mut self.blocks, self.process)? else {
283283+ let Step::Value(output) = self.walker.step(&self.blocks, self.process)? else {
277284 break;
278285 };
279286 out.push(output);
···292299 root: Cid,
293300 process: fn(Bytes) -> Bytes,
294301 max_size: usize,
295295- mem_blocks: HashMap<Cid, MaybeProcessedBlock>,
302302+ mem_blocks: HashMap<ObjectLink, MaybeProcessedBlock>,
296303 pub commit: Option<Commit>,
297304}
298305···314321 })
315322 .await??;
316323317317- let (tx, mut rx) = mpsc::channel::<Vec<(Cid, MaybeProcessedBlock)>>(1);
324324+ let (tx, mut rx) = mpsc::channel::<Vec<(ObjectLink, MaybeProcessedBlock)>>(1);
318325319326 let store_worker = tokio::task::spawn_blocking(move || {
320327 while let Some(chunk) = rx.blocking_recv() {
···342349 continue;
343350 }
344351352352+ let link = cid.into();
345353 let data = Bytes::from(data);
346354347355 // remaining possible types: node, record, other. optimistically process
348356 // TODO: get the actual in-memory size to compute disk spill
349357 let maybe_processed = MaybeProcessedBlock::maybe(self.process, data);
350358 mem_size += maybe_processed.len();
351351- chunk.push((cid, maybe_processed));
359359+ chunk.push((link, maybe_processed));
352360 if mem_size >= (self.max_size / 2) {
353361 // soooooo if we're setting the db cache to max_size and then letting
354362 // multiple chunks in the queue that are >= max_size, then at any time
···372380373381 let commit = self.commit.ok_or(DriveError::MissingCommit)?;
374382375375- // the commit always must point to a Node; empty node => empty MST special case
376383 let db_bytes = store
377377- .get(&commit.data.to_bytes())
384384+ .get(&commit.data_link()?.to_bytes())
378385 .map_err(|e| DriveError::StorageError(DiskError::DbError(e)))?
379386 .ok_or(DriveError::MissingCommit)?;
380387···446453447454 for _ in 0..n {
448455 // walk as far as we can until we run out of blocks or find a record
449449- let step = match state.walker.disk_step(&mut state.store, process) {
456456+ let step = match state.walker.disk_step(&state.store, process) {
450457 Ok(s) => s,
451458 Err(e) => {
452459 return (state, Err(e.into()));
+2
src/lib.rs
···82828383pub mod disk;
8484pub mod drive;
8585+pub mod link;
85868687pub use disk::{DiskBuilder, DiskError, DiskStore};
8788pub use drive::{DriveError, Driver, DriverBuilder, NeedDisk, noop};
8989+pub use link::NodeThing;
8890pub use mst::Commit;
8991pub use walk::{Output, Step};
9092