Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
pr review: rename BaoDecoder to DataStream and add doc comment
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn committed Feb 3, 2023
1 parent 6bc00b3 commit be48294
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ pub struct Stats {
pub mbits: f64,
}

/// A verified stream of data coming from the provider
///
/// We guarantee that the data is correct by incrementally verifying a hash
#[repr(transparent)]
#[derive(Debug)]
pub struct BaoDecoder(AsyncSliceDecoder<ReceiveStream>);
pub struct DataStream(AsyncSliceDecoder<ReceiveStream>);

impl BaoDecoder {
impl DataStream {
fn new(inner: ReceiveStream, hash: bao::Hash) -> Self {
BaoDecoder(AsyncSliceDecoder::new(inner, hash, 0, u64::MAX))
DataStream(AsyncSliceDecoder::new(inner, hash, 0, u64::MAX))
}

async fn read_size(&mut self) -> io::Result<u64> {
Expand All @@ -85,7 +88,7 @@ impl BaoDecoder {
}
}

impl AsyncRead for BaoDecoder {
impl AsyncRead for DataStream {
fn poll_read(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
Expand All @@ -108,8 +111,8 @@ where
FutA: Future<Output = Result<()>>,
B: FnMut(Collection) -> FutB,
FutB: Future<Output = Result<()>>,
C: FnMut(bao::Hash, BaoDecoder, Option<String>) -> FutC,
FutC: Future<Output = Result<BaoDecoder>>,
C: FnMut(bao::Hash, DataStream, Option<String>) -> FutC,
FutC: Future<Output = Result<DataStream>>,
{
let now = Instant::now();
let (_client, mut connection) = setup(opts).await?;
Expand Down Expand Up @@ -241,7 +244,7 @@ async fn handle_blob_response(
hash: bao::Hash,
mut reader: ReceiveStream,
buffer: &mut BytesMut,
) -> Result<BaoDecoder> {
) -> Result<DataStream> {
match read_lp_data(&mut reader, buffer).await? {
Some(response_buffer) => {
let response: Response = postcard::from_bytes(&response_buffer)?;
Expand All @@ -258,7 +261,7 @@ async fn handle_blob_response(
// next blob in collection will be sent over
Res::Found => {
assert!(buffer.is_empty());
let decoder = BaoDecoder::new(reader, hash);
let decoder = DataStream::new(reader, hash);
Ok(decoder)
}
}
Expand Down

0 comments on commit be48294

Please sign in to comment.