@@ -392,7 +392,7 @@ pub use range_spec::{ChunkRangesSeq, NonEmptyRequestRangeSpecIter, RangeSpec};
392392use snafu:: { GenerateImplicitData , Snafu } ;
393393use tokio:: io:: AsyncReadExt ;
394394
395- use crate :: { api:: blobs:: Bitfield , provider:: CountingReader , BlobFormat , Hash , HashAndFormat } ;
395+ use crate :: { api:: blobs:: Bitfield , provider:: RecvStreamExt , BlobFormat , Hash , HashAndFormat } ;
396396
397397/// Maximum message size is limited to 100MiB for now.
398398pub const MAX_MESSAGE_SIZE : usize = 1024 * 1024 ;
@@ -441,9 +441,7 @@ pub enum RequestType {
441441}
442442
443443impl Request {
444- pub async fn read_async (
445- reader : & mut CountingReader < & mut iroh:: endpoint:: RecvStream > ,
446- ) -> io:: Result < Self > {
444+ pub async fn read_async ( reader : & mut iroh:: endpoint:: RecvStream ) -> io:: Result < ( Self , usize ) > {
447445 let request_type = reader. read_u8 ( ) . await ?;
448446 let request_type: RequestType = postcard:: from_bytes ( std:: slice:: from_ref ( & request_type) )
449447 . map_err ( |_| {
@@ -453,22 +451,31 @@ impl Request {
453451 )
454452 } ) ?;
455453 Ok ( match request_type {
456- RequestType :: Get => reader
457- . read_to_end_as :: < GetRequest > ( MAX_MESSAGE_SIZE )
458- . await ?
459- . into ( ) ,
460- RequestType :: GetMany => reader
461- . read_to_end_as :: < GetManyRequest > ( MAX_MESSAGE_SIZE )
462- . await ?
463- . into ( ) ,
464- RequestType :: Observe => reader
465- . read_to_end_as :: < ObserveRequest > ( MAX_MESSAGE_SIZE )
466- . await ?
467- . into ( ) ,
468- RequestType :: Push => reader
469- . read_length_prefixed :: < PushRequest > ( MAX_MESSAGE_SIZE )
470- . await ?
471- . into ( ) ,
454+ RequestType :: Get => {
455+ let ( r, size) = reader
456+ . read_to_end_as :: < GetRequest > ( MAX_MESSAGE_SIZE )
457+ . await ?;
458+ ( r. into ( ) , size)
459+ }
460+ RequestType :: GetMany => {
461+ let ( r, size) = reader
462+ . read_to_end_as :: < GetManyRequest > ( MAX_MESSAGE_SIZE )
463+ . await ?;
464+ ( r. into ( ) , size)
465+ }
466+ RequestType :: Observe => {
467+ let ( r, size) = reader
468+ . read_to_end_as :: < ObserveRequest > ( MAX_MESSAGE_SIZE )
469+ . await ?;
470+ ( r. into ( ) , size)
471+ }
472+ RequestType :: Push => {
473+ let r = reader
474+ . read_length_prefixed :: < PushRequest > ( MAX_MESSAGE_SIZE )
475+ . await ?;
476+ let size = postcard:: experimental:: serialized_size ( & r) . unwrap ( ) ;
477+ ( r. into ( ) , size)
478+ }
472479 _ => {
473480 return Err ( io:: Error :: new (
474481 io:: ErrorKind :: InvalidData ,
0 commit comments