src/client/remote_chunk_reader.rs: implement remote chunk reader
This commit is contained in:
parent
4f6aaf542c
commit
7f99bf691a
|
@ -9,6 +9,9 @@ mod merge_known_chunks;
|
|||
mod http_client;
|
||||
pub use http_client::*;
|
||||
|
||||
mod remote_chunk_reader;
|
||||
pub use remote_chunk_reader::*;
|
||||
|
||||
mod pxar_backup_stream;
|
||||
pub use pxar_backup_stream::*;
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
use failure::*;
|
||||
use futures::future::Future;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::BackupReader;
|
||||
use crate::backup::{ReadChunk, DataChunk, CryptConfig};
|
||||
|
||||
/// Read chunks from remote host using ``BackupReader``
|
||||
pub struct RemoteChunkReader {
|
||||
client: Arc<BackupReader>,
|
||||
crypt_config: Option<Arc<CryptConfig>>,
|
||||
}
|
||||
|
||||
impl RemoteChunkReader {
|
||||
|
||||
pub fn new(client: Arc<BackupReader>, crypt_config: Option<Arc<CryptConfig>>) -> Self {
|
||||
Self { client, crypt_config }
|
||||
}
|
||||
}
|
||||
|
||||
impl ReadChunk for RemoteChunkReader {
|
||||
|
||||
fn read_chunk(&mut self, digest:&[u8; 32]) -> Result<Vec<u8>, Error> {
|
||||
|
||||
let digest_str = proxmox::tools::digest_to_hex(digest);
|
||||
|
||||
let writer = Vec::with_capacity(4*1024*1024);
|
||||
|
||||
let chunk_data = self.client.download_chunk(&digest, writer).wait()?;
|
||||
|
||||
let chunk = DataChunk::from_raw(chunk_data, *digest)?;
|
||||
chunk.verify_crc()?;
|
||||
|
||||
let raw_data = match self.crypt_config {
|
||||
Some(ref crypt_config) => chunk.decode(Some(crypt_config))?,
|
||||
None => chunk.decode(None)?,
|
||||
};
|
||||
|
||||
Ok(raw_data)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue