/// Pipe chunks from src to dst, but omit any chunks in omit
Pipe chunks from src to dst, but omit any chunks in omit
Pipe chunks from src to dst but omit any chunks in omit
pub fn pipe_partial_state_sync(
    src: &StateSyncMessage,
    dst: &mut dyn Chunkable,
    omit: &HashSet<ChunkId>,
) -> Option<StateSyncMessage> {
    while !dst.is_complete() {
        let ids: Vec<_> = dst.chunks_to_download().collect();
        assert!(
            !ids.is_empty(),
            "Can't have incomplete artifact that needs no chunks"
        );
        let mut omitted_chunks = false;
        for id in ids {
            if omit.contains(&id) {
                omitted_chunks = true;
                continue;
            }
            let chunk = Box::new(src.clone())
                .get_chunk(id)
                .unwrap_or_else(|| panic!("Requested unknown chunk {}", id));
            match dst.add_chunk(chunk) {
                Ok(Artifact::StateSync(msg)) => {
                    assert!(
                        dst.is_complete(),
                        "add_chunk returned OK but the artifact is not complete"
                    );
                    return Some(msg);
                }
                Ok(artifact) => {
                    panic!("Unexpected artifact type: {:?}", artifact);
                }
                Err(ChunksMoreNeeded) => (),
                Err(ChunkVerificationFailed) => panic!("Encountered invalid chunk {}", id),
            }
        }
        if omitted_chunks {
            return None;
        }
    }
    unreachable!()
}
pub fn pipe_partial_state_sync ( src : & StateSyncMessage , dst : & mut dyn Chunkable , omit : & HashSet < ChunkId > , ) -> Option < StateSyncMessage > { while ! dst . is_complete ( ) { let ids : Vec < _ > = dst . chunks_to_download ( ) . collect ( ) ; assert ! ( ids is_empty ( ) " " ) ; let mut omitted_chunks = false ; for id in ids { if omit . contains ( & id ) { omitted_chunks = true ; continue ; } let chunk = Box :: new ( src . clone ( ) ) . get_chunk ( id ) . unwrap_or_else ( | | panic ! ( " " id ) ) ; match dst . add_chunk ( chunk ) { Ok ( Artifact :: StateSync ( msg ) ) => { assert ! ( dst is_complete ( ) " " ) ; return Some ( msg ) ; } Ok ( artifact ) => { panic ! ( " " artifact ) ; } Err ( ChunksMoreNeeded ) => ( ) , Err ( ChunkVerificationFailed ) => panic ! ( " " id ) , } } if omitted_chunks { return None ; } } unreachable ! ( ) }
Pipe chunks from src to dst, but omit any chunks in omit
Pipe chunks from src to dst but omit any chunks in omit
src
&StateSyncMessage
dst
&mut dyn Chunkable
omit
&HashSet<ChunkId>